Skip to content

Commit

Permalink
Add testing
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jun 5, 2021
1 parent 3528a67 commit 2a21921
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions apps/files/tests/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
namespace OCA\Files\Controller;

use OCA\Files\Capabilities;
use OCA\Files\Service\TagService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand Down Expand Up @@ -211,6 +212,42 @@ public function testUpdateFileSorting() {
$this->assertEquals($expected, $actual);
}

public function testUpdateFileSortingWithBadParams() {
$mode = 'abcdef';
$direction = '123456';

$this->config->expects($this->never())
->method('setUserValue')
->with($this->user->getUID(), 'files', 'file_sorting', $mode);
$this->config->expects($this->never())
->method('setUserValue')
->with($this->user->getUID(), 'files', 'file_sorting_direction', $direction);

$actual = $this->apiController->updateFileSorting($mode, $direction);
$this->assertEquals($actual->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY);
}

public function testGetFileSorting() {
$file_sorting = Capabilities::SORTING_MODES[0];
$file_sorting_direction = Capabilities::SORTING_DIRECTIONS[0];

$this->config->expects($this->at(0))
->method('getUserValue')
->with($this->user->getUID(), 'files', 'file_sorting', $file_sorting)
->willReturn($file_sorting);
$this->config->expects($this->at(1))
->method('getUserValue')
->with($this->user->getUID(), 'files', 'file_sorting_direction', $file_sorting_direction)
->willReturn($file_sorting_direction);

$expected = new HTTP\JSONResponse([
'file_sorting' => 'name',
'file_sorting_direction' => 'asc'
]);
$actual = $this->apiController->getFileSorting();
$this->assertEquals($expected, $actual);
}

public function invalidSortingModeData() {
return [
['color', 'asc'],
Expand Down

0 comments on commit 2a21921

Please sign in to comment.