diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-10-29 15:39:10 +0300 |
---|---|---|
committer | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2014-11-03 23:57:55 +0300 |
commit | 4330383b9559c570f2afdf86064aafe02a938138 (patch) | |
tree | 17dbe604b220967a3dca41ab30b263b4e863e19b /tests | |
parent | cd0314169c9786df9032e098a4b9b15629060a27 (diff) |
Add generic test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/controller/documentcontrollertest.php | 77 | ||||
-rw-r--r-- | tests/phpunit.xml | 2 |
2 files changed, 78 insertions, 1 deletions
diff --git a/tests/controller/documentcontrollertest.php b/tests/controller/documentcontrollertest.php new file mode 100644 index 00000000..5da1cbe0 --- /dev/null +++ b/tests/controller/documentcontrollertest.php @@ -0,0 +1,77 @@ +<?php +/** + * ownCloud - Documents App + * + * @author Victor Dubiniuk + * @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com + * + * This file is licensed under the Affero General Public License version 3 or + * later. + */ + +namespace OCA\Documents\Controller; + +class DocumentControllerTest extends \PHPUnit_Framework_TestCase { + private $appName; + private $request; + private $l10n; + private $settings; + private $uid; + private $password; + private $controller; + + public function setUp(){ + $this->appName = 'documents'; + $this->uid = 'jack_the_documents_tester'; + $this->password = 'password'; + $this->request = $this->getMockBuilder('\OCP\IRequest') + ->disableOriginalConstructor() + ->getMock() + ; + $this->settings = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock() + ; + $this->l10n = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor() + ->getMock() + ; + $this->controller = new DocumentController( + $this->appName, + $this->request, + $this->settings, + $this->l10n, + $this->uid + ); + } + + public function tearDown(){ + \OC_User::deleteUser($this->uid); + } + + public function testRename(){ + $this->login(); + $result = array( + 'status' => 'error', + 'message' => (string) $this->l10n->t('You don\'t have permission to rename this document') + ); + $this->request->post = array( + 'fileId' => 500, + 'name' => 'newname.ext' + ); + $response = $this->controller->rename(500); + $this->assertEquals($result, $response); + } + + protected function login(){ + if (!\OCP\User::userExists($this->uid)){ + \OC_User::createUser($this->uid, $this->password); + } + if (!\OC_User::isLoggedIn()){ + $result = \OC_User::getUserSession()->login($this->uid, $this->password); + if ($result){ + \OC_Util::setupFS(\OC_User::getUserSession()->getUser()->getUID()); + } + } + } +} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index b8311273..74549c3c 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -12,7 +12,7 @@ <!-- filters for code coverage --> <filter> <whitelist> - <directory suffix=".php">../../mail</directory> + <directory suffix=".php">../../documents</directory> <exclude> <directory suffix=".php">../../documents/l10n</directory> <directory suffix=".php">../../documents/tests</directory> |