Addressbook - empty path/query filter may cause issues
authorMichael Spahn <m.spahn@metaways.de>
Thu, 30 Mar 2017 13:19:38 +0000 (15:19 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Sun, 2 Apr 2017 18:18:59 +0000 (20:18 +0200)
added more path filter test
fixed issue

Change-Id: I0dc2d6cdeef56b6a0620b1a710339d1c4f7f6299
Reviewed-on: http://gerrit.tine20.com/customers/4467
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Addressbook/JsonTest.php
tine20/Tinebase/Model/Filter/Path.php

index 49d47d2..5f85b0a 100644 (file)
@@ -1433,6 +1433,50 @@ class Addressbook_JsonTest extends TestCase
     }
 
     /**
+     * Tests if path info in query breaks backend
+     */
+    public function testSearchContactsWithPathFilterIfPathDisabled()
+    {
+        if (Tinebase_Config::getInstance()->featureEnabled(Tinebase_Config::FEATURE_SEARCH_PATH)) {
+            $this->markTestSkipped('Test does not apply if path feature is enabled');
+        }
+
+        $filter = [
+            [
+                'condition' => 'OR',
+                'filters' => [
+                    [
+                        'condition' => 'AND',
+                        'filters' => [
+                            [
+                                'field' => 'query',
+                                'operator' => 'contains',
+                                'value' => '',
+                            ],
+                        ],
+                    ],
+                    [
+                        'field' => 'path',
+                        'operator' => 'contains',
+                        'value' => '',
+                    ],
+                ],
+            ]
+        ];
+
+        $paging = [
+            'sort' => 'n_fn',
+            'dir' => 'ASC',
+            'start' => 0,
+            'limit' => 10
+        ];
+
+        $result = $this->_uit->searchContacts($filter, $paging);
+
+        $this->assertEquals(6, $result['totalcount']);
+    }
+
+    /**
      * testOrganizerForeignIdFilterWithOrCondition
      */
     public function testOrganizerForeignIdFilterWithOrCondition()
index 7e56c1f..fae9748 100644 (file)
@@ -53,8 +53,9 @@ class Tinebase_Model_Filter_Path extends Tinebase_Model_Filter_Text
      */
     public function appendFilterSql($_select, $_backend)
     {
-        if (true !== Tinebase_Config::getInstance()->featureEnabled(Tinebase_Config::FEATURE_SEARCH_PATH)) {
-            $_select->where('1=0');
+        if (true !== Tinebase_Config::getInstance()->featureEnabled(Tinebase_Config::FEATURE_SEARCH_PATH) ||
+            empty($this->_value)) {
+            $_select->where('1=1');
             return;
         }