Skip to content

Commit 2a21921

Browse files
committed
Add testing
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
1 parent 3528a67 commit 2a21921

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

apps/files/tests/Controller/ApiControllerTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
namespace OCA\Files\Controller;
2929

30+
use OCA\Files\Capabilities;
3031
use OCA\Files\Service\TagService;
3132
use OCP\AppFramework\Http;
3233
use OCP\AppFramework\Http\DataResponse;
@@ -211,6 +212,42 @@ public function testUpdateFileSorting() {
211212
$this->assertEquals($expected, $actual);
212213
}
213214

215+
public function testUpdateFileSortingWithBadParams() {
216+
$mode = 'abcdef';
217+
$direction = '123456';
218+
219+
$this->config->expects($this->never())
220+
->method('setUserValue')
221+
->with($this->user->getUID(), 'files', 'file_sorting', $mode);
222+
$this->config->expects($this->never())
223+
->method('setUserValue')
224+
->with($this->user->getUID(), 'files', 'file_sorting_direction', $direction);
225+
226+
$actual = $this->apiController->updateFileSorting($mode, $direction);
227+
$this->assertEquals($actual->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY);
228+
}
229+
230+
public function testGetFileSorting() {
231+
$file_sorting = Capabilities::SORTING_MODES[0];
232+
$file_sorting_direction = Capabilities::SORTING_DIRECTIONS[0];
233+
234+
$this->config->expects($this->at(0))
235+
->method('getUserValue')
236+
->with($this->user->getUID(), 'files', 'file_sorting', $file_sorting)
237+
->willReturn($file_sorting);
238+
$this->config->expects($this->at(1))
239+
->method('getUserValue')
240+
->with($this->user->getUID(), 'files', 'file_sorting_direction', $file_sorting_direction)
241+
->willReturn($file_sorting_direction);
242+
243+
$expected = new HTTP\JSONResponse([
244+
'file_sorting' => 'name',
245+
'file_sorting_direction' => 'asc'
246+
]);
247+
$actual = $this->apiController->getFileSorting();
248+
$this->assertEquals($expected, $actual);
249+
}
250+
214251
public function invalidSortingModeData() {
215252
return [
216253
['color', 'asc'],

0 commit comments

Comments
 (0)