Welcome to mirror list, hosted at ThFree Co, Russian Federation.

documentcontrollertest.php « controller « tests - github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca6f4f543ff6d16273ee1a3f58276eee73255e50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
 * ownCloud - Richdocuments 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\Richdocuments\Controller;

class DocumentControllerTest extends \PHPUnit_Framework_TestCase {
	private $appName = 'richdocuments';
	private $request;
	private $l10n;
	private $settings;
	private $uid = 'jack_the_documents_tester';
	private $password = 'password';
	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
		);
		
		$userManager = \OC::$server->getUserManager();
		$userSession = \OC::$server->getUserSession();
		if (!$userManager->userExists($this->uid)){
			$userManager->createUser($this->uid, $this->password);
			\OC::$server->getUserFolder($this->uid);
		}
		$userSession->login($this->uid, $this->password);
		\OC_Util::setupFS();
	}
	
	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);
	}
	
	public function testCreate(){
		$currentDir = getcwd();
		chdir('../../../');
		$response = $this->controller->create();
		chdir($currentDir);
		$this->assertEquals('success', $response['status']);
	}
}