| 
									
										
										
										
											2014-10-29 15:39:10 +03:00
										 |  |  | <?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 { | 
					
						
							| 
									
										
										
										
											2014-11-05 01:39:23 +03:00
										 |  |  | 	private $appName = 'documents'; | 
					
						
							| 
									
										
										
										
											2014-10-29 15:39:10 +03:00
										 |  |  | 	private $request; | 
					
						
							|  |  |  | 	private $l10n; | 
					
						
							|  |  |  | 	private $settings; | 
					
						
							| 
									
										
										
										
											2014-11-05 01:39:23 +03:00
										 |  |  | 	private $uid = 'jack_the_documents_tester'; | 
					
						
							|  |  |  | 	private $password = 'password'; | 
					
						
							| 
									
										
										
										
											2014-10-29 15:39:10 +03:00
										 |  |  | 	private $controller; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public function setUp(){ | 
					
						
							|  |  |  | 		$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 | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2014-11-05 01:39:23 +03:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2015-05-25 18:50:32 +03:00
										 |  |  | 		$userManager = \OC::$server->getUserManager(); | 
					
						
							|  |  |  | 		$userSession = \OC::$server->getUserSession(); | 
					
						
							|  |  |  | 		if (!$userManager->userExists($this->uid)){ | 
					
						
							|  |  |  | 			$userManager->createUser($this->uid, $this->password); | 
					
						
							|  |  |  | 			\OC::$server->getUserFolder($this->uid); | 
					
						
							| 
									
										
										
										
											2014-11-05 01:39:23 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-25 18:50:32 +03:00
										 |  |  | 		$userSession->login($this->uid, $this->password); | 
					
						
							| 
									
										
										
										
											2014-11-05 01:39:23 +03:00
										 |  |  | 		\OC_Util::setupFS(); | 
					
						
							| 
									
										
										
										
											2014-10-29 15:39:10 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public function testRename(){ | 
					
						
							|  |  |  | 		$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); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-11-05 01:39:23 +03:00
										 |  |  | 	public function testCreate(){ | 
					
						
							|  |  |  | 		$currentDir = getcwd(); | 
					
						
							|  |  |  | 		chdir('../../../'); | 
					
						
							|  |  |  | 		$response = $this->controller->create(); | 
					
						
							|  |  |  | 		chdir($currentDir); | 
					
						
							|  |  |  | 		$this->assertEquals('success', $response['status']); | 
					
						
							| 
									
										
										
										
											2014-10-29 15:39:10 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |