Skip to content

Commit

Permalink
fix(SettingsControllerTest)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Feb 2, 2024
1 parent 9170eee commit e05ca41
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/SettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OCA\Bookmarks\Tests;

use OCA\Bookmarks\Controller\SettingsController;
use OCA\Bookmarks\Service\UserSettingsService;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserManager;
Expand Down Expand Up @@ -57,23 +58,24 @@ protected function setUp(): void {
/** @var IFactory $l10nFactory */
$l10nFactory = \OC::$server->get(IFactory::class);
$l = $l10nFactory->get('bookmarks');
$userSettings = \OC::$server->get(UserSettingsService::class);
if (!$this->userManager->userExists($this->userId)) {
$this->userManager->createUser($this->userId, 'password');
}
$this->config = \OC::$server->get(IConfig::class);
$this->controller = new SettingsController('bookmarks', $this->request, $this->userId, $this->config, $l);
$this->controller = new SettingsController('bookmarks', $this->request, $userSettings);
}

/**
* @throws \OCP\PreConditionNotMetException
*/
public function testGetSorting(): void {
$this->config->setUserValue($this->userId, $this->appName, 'sorting', 'clickcount'); //case: user has a normal sorting option
$output = $this->controller->getSorting();
$output = $this->controller->getSetting('sorting');
$data = $output->getData();
$this->assertEquals('clickcount', $data['sorting']);
$this->config->deleteUserValue($this->userId, $this->appName, 'sorting'); //case: user has no sorting option
$output = $this->controller->getSorting();
$output = $this->controller->getSetting('sorting');
$data = $output->getData();
$this->assertEquals('lastmodified', $data['sorting']); //returns default
}
Expand All @@ -82,11 +84,11 @@ public function testGetSorting(): void {
*
*/
public function testSetSorting(): void {
$output = $this->controller->setSorting('added'); //case: set a normal sorting option
$output = $this->controller->setSetting('sorting', 'added'); //case: set a normal sorting option
$data = $output->getData();
$this->assertEquals('success', $data['status']);
$this->assertEquals('added', $this->config->getUserValue($this->userId, $this->appName, 'sorting', ''));
$output = $this->controller->setSorting('foo'); //case: set an invalid sorting option
$output = $this->controller->setSetting('sorting', 'foo'); //case: set an invalid sorting option
$data = $output->getData();
$this->assertEquals('error', $data['status']);
}
Expand Down

0 comments on commit e05ca41

Please sign in to comment.