|
|
|
|
@ -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… |
|
|
|
|
|