summaryrefslogtreecommitdiffstats
path: root/apps/files/tests/ajax_rename.php
blob: 2b90a11743d164053d17770a463fddde561a2f88 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

/**
 * ownCloud - Core
 *
 * @author Morris Jobke
 * @copyright 2013 Morris Jobke morris.jobke@gmail.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {

	function setUp() {
		// mock OC_L10n
		$l10nMock = $this->getMock('\OC_L10N', array('t'), array(), '', false);
		$l10nMock->expects($this->any())
			->method('t')
			->will($this->returnArgument(0));
		$viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath'), array(), '', false);
		$viewMock->expects($this->any())
			->method('normalizePath')
			->will($this->returnArgument(0));
		$viewMock->expects($this->any())
			->method('rename')
			->will($this->returnValue(true));
		$this->files = new \OCA\Files\App($viewMock, $l10nMock);
	}

	/**
	 * @brief test rename of file/folder named "Shared"
	 */
	function testRenameSharedFolder() {
		$dir = '/';
		$oldname = 'Shared';
		$newname = 'new_name';

		$result = $this->files->rename($dir, $oldname, $newname);
		$expected = array(
			'success'	=> false,
			'data'		=> array('message' => '%s could not be renamed')
		);

		$this->assertEquals($expected, $result);
	}

	/**
	 * @brief test rename of file/folder named "Shared"
	 */
	function testRenameSharedFolderInSubdirectory() {
		$dir = '/test';
		$oldname = 'Shared';
		$newname = 'new_name';

		$result = $this->files->rename($dir, $oldname, $newname);
		$expected = array(
			'success'	=> true,
			'data'		=> array(
				'dir'		=> $dir,
				'file'		=> $oldname,
				'newname'	=> $newname
			)
		);

		$this->assertEquals($expected, $result);
	}

	/**
	 * @brief test rename of file/folder to "Shared"
	 */
	function testRenameFolderToShared() {
		$dir = '/';
		$oldname = 'oldname';
		$newname = 'Shared';

		$result = $this->files->rename($dir, $oldname, $newname);
		$expected = array(
			'success'	=> false,
			'data'		=> array('message' => "Invalid folder name. Usage of 'Shared' is reserved by ownCloud")
		);

		$this->assertEquals($expected, $result);
	}

	/**
	 * @brief test rename of file/folder
	 */
	function testRenameFolder() {
		$dir = '/';
		$oldname = 'oldname';
		$newname = 'newname';

		$result = $this->files->rename($dir, $oldname, $newname);
		$expected = array(
			'success'	=> true,
			'data'		=> array(
				'dir'		=> $dir,
				'file'		=> $oldname,
				'newname'	=> $newname
			)
		);

		$this->assertEquals($expected, $result);
	}
}