From bb5554de7ffdb1292045e7817a35b450c02403ca Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 7 May 2013 13:37:20 +0200 Subject: [PATCH] [files] rename tests --- apps/files/tests/ajax_rename.php | 99 ++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 apps/files/tests/ajax_rename.php diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php new file mode 100644 index 00000000000..8332f36e161 --- /dev/null +++ b/apps/files/tests/ajax_rename.php @@ -0,0 +1,99 @@ +. + * + */ + + +require_once realpath( dirname(__FILE__).'/../lib/files.php' ); + +class Test_Ajax_Rename extends \PHPUnit_Framework_TestCase { + + function setUp() { + // mock OC_L10n + $l10nMock = $this->getMock('\OC_L10N', array('t')); + $l10nMock->expects($this->any()) + ->method('t') + ->will($this->returnArgument(0)); + $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath')); + $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\Files($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' => 'Unable to rename file') + ); + + $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); + } +} \ No newline at end of file -- 2.39.5