From 1af436cb59dcb28892edc2c2edc33f178cbeb66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= <jfd@butonic.de> Date: Thu, 31 Jul 2014 12:06:13 +0200 Subject: [PATCH] add test for search() in shared cache --- apps/files_sharing/tests/cache.php | 78 ++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/tests/cache.php b/apps/files_sharing/tests/cache.php index 8472c7f1ab..1b0fe6fdc6 100644 --- a/apps/files_sharing/tests/cache.php +++ b/apps/files_sharing/tests/cache.php @@ -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); } /** -- GitLab