]> source.dussan.org Git - nextcloud-server.git/commitdiff
add test for search() in shared cache
authorJörn Friedrich Dreyer <jfd@butonic.de>
Thu, 31 Jul 2014 10:06:13 +0000 (12:06 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Fri, 8 Aug 2014 09:47:56 +0000 (11:47 +0200)
apps/files_sharing/tests/cache.php

index 8472c7f1ab036f95b78d3e3d2721444444140e55..1b0fe6fdc6d3c45ae8eee344ee11aa90761c51f2 100644 (file)
@@ -95,6 +95,80 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
                parent::tearDown();
        }
 
+       function searchDataProvider() {
+               return array(
+                       array('%another%',
+                               array(
+                                       array('name' => 'another too.txt', 'path' => 'subdir/another too.txt'),
+                                       array('name' => 'another.txt', 'path' => 'subdir/another.txt'),
+                               )
+                       ),
+                       array('%Another%',
+                               array(
+                                       array('name' => 'another too.txt', 'path' => 'subdir/another too.txt'),
+                                       array('name' => 'another.txt', 'path' => 'subdir/another.txt'),
+                               )
+                       ),
+                       array('%dir%',
+                               array(
+                                       array('name' => 'emptydir', 'path' => 'emptydir'),
+                                       array('name' => 'subdir', 'path' => 'subdir'),
+                                       array('name' => 'shareddir', 'path' => ''),
+                               )
+                       ),
+                       array('%Dir%',
+                               array(
+                                       array('name' => 'emptydir', 'path' => 'emptydir'),
+                                       array('name' => 'subdir', 'path' => 'subdir'),
+                                       array('name' => 'shareddir', 'path' => ''),
+                               )
+                       ),
+                       array('%txt%',
+                               array(
+                                       array('name' => 'bar.txt', 'path' => 'bar.txt'),
+                                       array('name' => 'another too.txt', 'path' => 'subdir/another too.txt'),
+                                       array('name' => 'another.txt', 'path' => 'subdir/another.txt'),
+                               )
+                       ),
+                       array('%Txt%',
+                               array(
+                                       array('name' => 'bar.txt', 'path' => 'bar.txt'),
+                                       array('name' => 'another too.txt', 'path' => 'subdir/another too.txt'),
+                                       array('name' => 'another.txt', 'path' => 'subdir/another.txt'),
+                               )
+                       ),
+                       array('%',
+                               array(
+                                       array('name' => 'bar.txt', 'path' => 'bar.txt'),
+                                       array('name' => 'emptydir', 'path' => 'emptydir'),
+                                       array('name' => 'subdir', 'path' => 'subdir'),
+                                       array('name' => 'another too.txt', 'path' => 'subdir/another too.txt'),
+                                       array('name' => 'another.txt', 'path' => 'subdir/another.txt'),
+                                       array('name' => 'not a text file.xml', 'path' => 'subdir/not a text file.xml'),
+                                       array('name' => 'shareddir', 'path' => ''),
+                               )
+                       ),
+                       array('%nonexistant%',
+                               array(
+                               )
+                       ),
+               );
+       }
+
+       /**
+        * we cannot use a dataProvider because that would cause the stray hook detection to remove the hooks
+        * that were added in setUpBeforeClass.
+        */
+       function testSearch() {
+               foreach ($this->searchDataProvider() as $data) {
+                       list($pattern, $expectedFiles) = $data;
+
+                       $results = $this->sharedStorage->getCache()->search($pattern);
+
+                       $this->verifyFiles($expectedFiles, $results);
+               }
+
+       }
        /**
         * Test searching by mime type
         */
@@ -115,8 +189,6 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
                                ),
                        );
                $this->verifyFiles($check, $results);
-
-               $this->verifyFiles($check, $results);
        }
 
        function testGetFolderContentsInRoot() {
@@ -245,7 +317,7 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
                                }
                        }
                }
-               $this->assertTrue(empty($results));
+               $this->assertEquals(array(), $results);
        }
 
        /**