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()); } } } }