diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2017-12-11 15:27:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-11 15:27:44 +0100 |
commit | c1fcd6fc98c43c7a0298d68e1c2533132b12176d (patch) | |
tree | bb38a5509b4ac3f505ae7c6f1c98440e12a4bc5b /tests/Core | |
parent | 7c39711798354cd99dd9d8740e8c97f0d0f0fecc (diff) | |
parent | 96bc03a03a7d7b1d5868eed5c1cc86b1b9b8ca2c (diff) | |
download | nextcloud-server-c1fcd6fc98c43c7a0298d68e1c2533132b12176d.tar.gz nextcloud-server-c1fcd6fc98c43c7a0298d68e1c2533132b12176d.zip |
Merge pull request #7324 from nextcloud/no-sorters-no-instances
don't create sorter instances when none was requested
Diffstat (limited to 'tests/Core')
-rw-r--r-- | tests/Core/Controller/AutoCompleteControllerTest.php | 140 |
1 files changed, 99 insertions, 41 deletions
diff --git a/tests/Core/Controller/AutoCompleteControllerTest.php b/tests/Core/Controller/AutoCompleteControllerTest.php index bcd0d6e1cd3..6279ba3283e 100644 --- a/tests/Core/Controller/AutoCompleteControllerTest.php +++ b/tests/Core/Controller/AutoCompleteControllerTest.php @@ -59,57 +59,115 @@ class AutoCompleteControllerTest extends TestCase { ); } - public function testGet() { - $searchResults = [ - 'exact' => [ - 'users' => [], - 'robots' => [], - ], - 'users' => [ - ['label' => 'Alice A.', 'value' => ['shareWith' => 'alice']], - ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']], + public function searchDataProvider() { + return [ + [ #0 – regular search + // searchResults + [ + 'exact' => [ + 'users' => [], + 'robots' => [], + ], + 'users' => [ + ['label' => 'Alice A.', 'value' => ['shareWith' => 'alice']], + ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']], + ], + ], + // expected + [ + [ 'id' => 'alice', 'label' => 'Alice A.', 'source' => 'users'], + [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'], + ], + '', + 'files', + '42', + null ], - ]; - - $expected = [ - [ 'id' => 'alice', 'label' => 'Alice A.', 'source' => 'users'], - [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'], - ]; - - $this->collaboratorSearch->expects($this->once()) - ->method('search') - ->willReturn([$searchResults, false]); - - $response = $this->controller->get('', 'files', '42', null); - - $list = $response->getData(); - $this->assertEquals($expected, $list); // has better error output… - $this->assertSame($expected, $list); - } - - public function testGetWithExactMatch() { - $searchResults = [ - 'exact' => [ - 'users' => [ - ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']], + [ #1 – missing itemtype and id + [ + 'exact' => [ + 'users' => [], + 'robots' => [], + ], + 'users' => [ + ['label' => 'Alice A.', 'value' => ['shareWith' => 'alice']], + ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']], + ], ], - 'robots' => [], + // expected + [ + [ 'id' => 'alice', 'label' => 'Alice A.', 'source' => 'users'], + [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'], + ], + '', + null, + null, + null ], - 'users' => [ - ['label' => 'Robert R.', 'value' => ['shareWith' => 'bobby']], + [ #2 – with sorter + [ + 'exact' => [ + 'users' => [], + 'robots' => [], + ], + 'users' => [ + ['label' => 'Alice A.', 'value' => ['shareWith' => 'alice']], + ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']], + ], + ], + // expected + [ + [ 'id' => 'alice', 'label' => 'Alice A.', 'source' => 'users'], + [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'], + ], + '', + 'files', + '42', + 'karma|bus-factor' ], + [ #3 – exact Match + [ + 'exact' => [ + 'users' => [ + ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']], + ], + 'robots' => [], + ], + 'users' => [ + ['label' => 'Robert R.', 'value' => ['shareWith' => 'bobby']], + ], + ], + [ + [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'], + [ 'id' => 'bobby', 'label' => 'Robert R.', 'source' => 'users'], + ], + 'bob', + 'files', + '42', + null + ] ]; + } - $expected = [ - [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'], - [ 'id' => 'bobby', 'label' => 'Robert R.', 'source' => 'users'], - ]; - + /** + * @param $searchResults + * @param $expected + * @param $searchTerm + * @param $itemType + * @param $itemId + * @param $sorter + * @dataProvider searchDataProvider + */ + public function testGet($searchResults, $expected, $searchTerm, $itemType, $itemId, $sorter) { $this->collaboratorSearch->expects($this->once()) ->method('search') ->willReturn([$searchResults, false]); - $response = $this->controller->get('bob', 'files', '42', null); + $runSorterFrequency = $sorter === null ? $this->never() : $this->once(); + $this->autoCompleteManager->expects($runSorterFrequency) + ->method('runSorters'); + + $response = $this->controller->get($searchTerm, $itemType, $itemId, $sorter); $list = $response->getData(); $this->assertEquals($expected, $list); // has better error output… |