diff options
Diffstat (limited to 'apps/files/tests/controller')
-rw-r--r-- | apps/files/tests/controller/ViewControllerTest.php | 22 | ||||
-rw-r--r-- | apps/files/tests/controller/apicontrollertest.php | 55 |
2 files changed, 72 insertions, 5 deletions
diff --git a/apps/files/tests/controller/ViewControllerTest.php b/apps/files/tests/controller/ViewControllerTest.php index 657ab6cb338..0446cc8982c 100644 --- a/apps/files/tests/controller/ViewControllerTest.php +++ b/apps/files/tests/controller/ViewControllerTest.php @@ -1,5 +1,6 @@ <?php /** + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <nickvergessen@owncloud.com> * @author Lukas Reschke <lukas@owncloud.com> * @author Vincent Petry <pvince81@owncloud.com> @@ -33,6 +34,7 @@ use OCP\AppFramework\Http\RedirectResponse; use OCP\INavigationManager; use OCP\IL10N; use OCP\IConfig; +use OCP\IUserSession; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -55,6 +57,10 @@ class ViewControllerTest extends TestCase { private $eventDispatcher; /** @var ViewController */ private $viewController; + /** @var IUser */ + private $user; + /** @var IUserSession */ + private $userSession; public function setUp() { parent::setUp(); @@ -64,6 +70,11 @@ class ViewControllerTest extends TestCase { $this->l10n = $this->getMock('\OCP\IL10N'); $this->config = $this->getMock('\OCP\IConfig'); $this->eventDispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $this->userSession = $this->getMock('\OCP\IUserSession'); + $this->user = $this->getMock('\OCP\IUser'); + $this->userSession->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($this->user)); $this->viewController = $this->getMockBuilder('\OCA\Files\Controller\ViewController') ->setConstructorArgs([ 'files', @@ -72,7 +83,8 @@ class ViewControllerTest extends TestCase { $this->navigationManager, $this->l10n, $this->config, - $this->eventDispatcher + $this->eventDispatcher, + $this->userSession ]) ->setMethods([ 'getStorageInfo', @@ -143,6 +155,12 @@ class ViewControllerTest extends TestCase { 'owner' => 'MyName', 'ownerDisplayName' => 'MyDisplayName', ])); + $this->config->expects($this->exactly(2)) + ->method('getUserValue') + ->will($this->returnValueMap([ + [$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'], + [$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'] + ])); $this->config ->expects($this->any()) @@ -224,6 +242,8 @@ class ViewControllerTest extends TestCase { 'owner' => 'MyName', 'ownerDisplayName' => 'MyDisplayName', 'isPublic' => false, + 'defaultFileSorting' => 'name', + 'defaultFileSortingDirection' => 'asc', 'mailNotificationEnabled' => 'no', 'mailPublicNotificationEnabled' => 'no', 'allowShareWithLink' => 'yes', diff --git a/apps/files/tests/controller/apicontrollertest.php b/apps/files/tests/controller/apicontrollertest.php index a9b248a36fe..59f53e8ee81 100644 --- a/apps/files/tests/controller/apicontrollertest.php +++ b/apps/files/tests/controller/apicontrollertest.php @@ -1,5 +1,6 @@ <?php /** + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Lukas Reschke <lukas@owncloud.com> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <rullzer@owncloud.com> @@ -43,6 +44,8 @@ use OCP\Image; class ApiControllerTest extends TestCase { /** @var string */ private $appName = 'files'; + /** @var \OCP\IUser */ + private $user; /** @var IRequest */ private $request; /** @var TagService */ @@ -53,19 +56,21 @@ class ApiControllerTest extends TestCase { private $apiController; /** @var \OCP\Share\IManager */ private $shareManager; + /** @var \OCP\IConfig */ + private $config; public function setUp() { $this->request = $this->getMockBuilder('\OCP\IRequest') ->disableOriginalConstructor() ->getMock(); - $user = $this->getMock('\OCP\IUser'); - $user->expects($this->any()) + $this->user = $this->getMock('\OCP\IUser'); + $this->user->expects($this->any()) ->method('getUID') ->will($this->returnValue('user1')); $userSession = $this->getMock('\OCP\IUserSession'); $userSession->expects($this->any()) ->method('getUser') - ->will($this->returnValue($user)); + ->will($this->returnValue($this->user)); $this->tagService = $this->getMockBuilder('\OCA\Files\Service\TagService') ->disableOriginalConstructor() ->getMock(); @@ -75,6 +80,7 @@ class ApiControllerTest extends TestCase { $this->preview = $this->getMockBuilder('\OCP\IPreview') ->disableOriginalConstructor() ->getMock(); + $this->config = $this->getMock('\OCP\IConfig'); $this->apiController = new ApiController( $this->appName, @@ -82,7 +88,8 @@ class ApiControllerTest extends TestCase { $userSession, $this->tagService, $this->preview, - $this->shareManager + $this->shareManager, + $this->config ); } @@ -335,4 +342,44 @@ class ApiControllerTest extends TestCase { $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); } + + public function testUpdateFileSorting() { + $mode = 'mtime'; + $direction = 'desc'; + + $this->config->expects($this->at(0)) + ->method('setUserValue') + ->with($this->user->getUID(), 'files', 'file_sorting', $mode); + $this->config->expects($this->at(1)) + ->method('setUserValue') + ->with($this->user->getUID(), 'files', 'file_sorting_direction', $direction); + + $expected = new HTTP\Response(); + $actual = $this->apiController->updateFileSorting($mode, $direction); + $this->assertEquals($expected, $actual); + } + + public function invalidSortingModeData() { + return [ + ['color', 'asc'], + ['name', 'size'], + ['foo', 'bar'] + ]; + } + + /** + * @dataProvider invalidSortingModeData + */ + public function testUpdateInvalidFileSorting($mode, $direction) { + $this->config->expects($this->never()) + ->method('setUserValue'); + + $expected = new Http\Response(null); + $expected->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); + + $result = $this->apiController->updateFileSorting($mode, $direction); + + $this->assertEquals($expected, $result); + } + } |