@@ -59,57 +59,115 @@ protected function setUp() {
5959 );
6060 }
6161
62- public function testGet () {
63- $ searchResults = [
64- 'exact ' => [
65- 'users ' => [],
66- 'robots ' => [],
67- ],
68- 'users ' => [
69- ['label ' => 'Alice A. ' , 'value ' => ['shareWith ' => 'alice ' ]],
70- ['label ' => 'Bob Y. ' , 'value ' => ['shareWith ' => 'bob ' ]],
62+ public function searchDataProvider () {
63+ return [
64+ [ #0 – regular search
65+ // searchResults
66+ [
67+ 'exact ' => [
68+ 'users ' => [],
69+ 'robots ' => [],
70+ ],
71+ 'users ' => [
72+ ['label ' => 'Alice A. ' , 'value ' => ['shareWith ' => 'alice ' ]],
73+ ['label ' => 'Bob Y. ' , 'value ' => ['shareWith ' => 'bob ' ]],
74+ ],
75+ ],
76+ // expected
77+ [
78+ [ 'id ' => 'alice ' , 'label ' => 'Alice A. ' , 'source ' => 'users ' ],
79+ [ 'id ' => 'bob ' , 'label ' => 'Bob Y. ' , 'source ' => 'users ' ],
80+ ],
81+ '' ,
82+ 'files ' ,
83+ '42 ' ,
84+ null
7185 ],
72- ];
73-
74- $ expected = [
75- [ 'id ' => 'alice ' , 'label ' => 'Alice A. ' , 'source ' => 'users ' ],
76- [ 'id ' => 'bob ' , 'label ' => 'Bob Y. ' , 'source ' => 'users ' ],
77- ];
78-
79- $ this ->collaboratorSearch ->expects ($ this ->once ())
80- ->method ('search ' )
81- ->willReturn ([$ searchResults , false ]);
82-
83- $ response = $ this ->controller ->get ('' , 'files ' , '42 ' , null );
84-
85- $ list = $ response ->getData ();
86- $ this ->assertEquals ($ expected , $ list ); // has better error output…
87- $ this ->assertSame ($ expected , $ list );
88- }
89-
90- public function testGetWithExactMatch () {
91- $ searchResults = [
92- 'exact ' => [
93- 'users ' => [
94- ['label ' => 'Bob Y. ' , 'value ' => ['shareWith ' => 'bob ' ]],
86+ [ #1 – missing itemtype and id
87+ [
88+ 'exact ' => [
89+ 'users ' => [],
90+ 'robots ' => [],
91+ ],
92+ 'users ' => [
93+ ['label ' => 'Alice A. ' , 'value ' => ['shareWith ' => 'alice ' ]],
94+ ['label ' => 'Bob Y. ' , 'value ' => ['shareWith ' => 'bob ' ]],
95+ ],
9596 ],
96- 'robots ' => [],
97+ // expected
98+ [
99+ [ 'id ' => 'alice ' , 'label ' => 'Alice A. ' , 'source ' => 'users ' ],
100+ [ 'id ' => 'bob ' , 'label ' => 'Bob Y. ' , 'source ' => 'users ' ],
101+ ],
102+ '' ,
103+ null ,
104+ null ,
105+ null
97106 ],
98- 'users ' => [
99- ['label ' => 'Robert R. ' , 'value ' => ['shareWith ' => 'bobby ' ]],
107+ [ #2 – with sorter
108+ [
109+ 'exact ' => [
110+ 'users ' => [],
111+ 'robots ' => [],
112+ ],
113+ 'users ' => [
114+ ['label ' => 'Alice A. ' , 'value ' => ['shareWith ' => 'alice ' ]],
115+ ['label ' => 'Bob Y. ' , 'value ' => ['shareWith ' => 'bob ' ]],
116+ ],
117+ ],
118+ // expected
119+ [
120+ [ 'id ' => 'alice ' , 'label ' => 'Alice A. ' , 'source ' => 'users ' ],
121+ [ 'id ' => 'bob ' , 'label ' => 'Bob Y. ' , 'source ' => 'users ' ],
122+ ],
123+ '' ,
124+ 'files ' ,
125+ '42 ' ,
126+ 'karma|bus-factor '
100127 ],
128+ [ #3 – exact Match
129+ [
130+ 'exact ' => [
131+ 'users ' => [
132+ ['label ' => 'Bob Y. ' , 'value ' => ['shareWith ' => 'bob ' ]],
133+ ],
134+ 'robots ' => [],
135+ ],
136+ 'users ' => [
137+ ['label ' => 'Robert R. ' , 'value ' => ['shareWith ' => 'bobby ' ]],
138+ ],
139+ ],
140+ [
141+ [ 'id ' => 'bob ' , 'label ' => 'Bob Y. ' , 'source ' => 'users ' ],
142+ [ 'id ' => 'bobby ' , 'label ' => 'Robert R. ' , 'source ' => 'users ' ],
143+ ],
144+ 'bob ' ,
145+ 'files ' ,
146+ '42 ' ,
147+ null
148+ ]
101149 ];
150+ }
102151
103- $ expected = [
104- [ 'id ' => 'bob ' , 'label ' => 'Bob Y. ' , 'source ' => 'users ' ],
105- [ 'id ' => 'bobby ' , 'label ' => 'Robert R. ' , 'source ' => 'users ' ],
106- ];
107-
152+ /**
153+ * @param $searchResults
154+ * @param $expected
155+ * @param $searchTerm
156+ * @param $itemType
157+ * @param $itemId
158+ * @param $sorter
159+ * @dataProvider searchDataProvider
160+ */
161+ public function testGet ($ searchResults , $ expected , $ searchTerm , $ itemType , $ itemId , $ sorter ) {
108162 $ this ->collaboratorSearch ->expects ($ this ->once ())
109163 ->method ('search ' )
110164 ->willReturn ([$ searchResults , false ]);
111165
112- $ response = $ this ->controller ->get ('bob ' , 'files ' , '42 ' , null );
166+ $ runSorterFrequency = $ sorter === null ? $ this ->never () : $ this ->once ();
167+ $ this ->autoCompleteManager ->expects ($ runSorterFrequency )
168+ ->method ('runSorters ' );
169+
170+ $ response = $ this ->controller ->get ($ searchTerm , $ itemType , $ itemId , $ sorter );
113171
114172 $ list = $ response ->getData ();
115173 $ this ->assertEquals ($ expected , $ list ); // has better error output…
0 commit comments