]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/LinkFilterTest.php
Improved search: combine AND, exact terms and exclude search.
[github/shaarli/Shaarli.git] / tests / LinkFilterTest.php
index 164af0d4fa83f683a2a1b8c789a0c2f8c1406de9..4d754d2522987d21d05d53e10179e1a4e9008804 100644 (file)
@@ -27,7 +27,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
     public function testFilter()
     {
         $this->assertEquals(
-            6,
+            7,
             count(self::$linkFilter->filter('', ''))
         );
 
@@ -222,7 +222,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
         );
         
         $this->assertEquals(
-            2,
+            3,
             count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"free software"'))
         );        
     }
@@ -250,11 +250,43 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
     public function testFilterFullTextMixed()
     {
         $this->assertEquals(
-            2,
+            3,
             count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'free software'))
         );
     }
 
+    /**
+     * Full-text search - test exclusion with '-'.
+     */
+    public function testExcludeSearch()
+    {
+        $this->assertEquals(
+            1,
+            count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'free -software'))
+        );
+
+        $this->assertEquals(
+            7,
+            count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-software'))
+        );
+    }
+
+    /**
+     * Full-text search - test AND, exact terms and exclusion combined.
+     */
+    public function testMultiSearch()
+    {
+        $this->assertEquals(
+            2,
+            count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"Free Software " stallman "read this"'))
+        );
+
+        $this->assertEquals(
+            1,
+            count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"free software " stallman "read this" -beard'))
+        );
+    }
+
     /**
      * Tag search with exclusion.
      */
@@ -266,7 +298,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
         );
 
         $this->assertEquals(
-            5,
+            6,
             count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free'))
         );
     }