From bc8e1ebf75b641f4be1d404cbcdbf5f77bbff5dc Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 11 Aug 2014 12:02:33 +0200 Subject: new unit test added --- apps/files/tests/ajax_rename.php | 46 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'apps') diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index fed366aa8eb..5ed8b1931f4 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -73,10 +73,14 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $oldname = 'oldname'; $newname = 'newname'; - $this->viewMock->expects($this->at(0)) + $this->viewMock->expects($this->any()) ->method('file_exists') - ->with('/') - ->will($this->returnValue(true)); + ->with($this->anything()) + ->will($this->returnValueMap(array( + array('/', true), + array('/oldname', true) + ))); + $this->viewMock->expects($this->any()) ->method('getFileInfo') @@ -119,7 +123,7 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $this->viewMock->expects($this->at(0)) ->method('file_exists') - ->with('/unexist') + ->with('/unexist/oldname') ->will($this->returnValue(false)); $this->viewMock->expects($this->any()) @@ -136,6 +140,40 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $result = $this->files->rename($dir, $oldname, $newname); + $this->assertFalse($result['success']); + $this->assertEquals('sourcenotfound', $result['data']['code']); + } + + /** + * Test move to a folder that doesn't exist any more + */ + function testRenameToNonExistingFolder() { + $dir = '/'; + $oldname = 'oldname'; + $newname = '/unexist/newname'; + + $this->viewMock->expects($this->any()) + ->method('file_exists') + ->with($this->anything()) + ->will($this->returnValueMap(array( + array('/oldname', true), + array('/unexist', false) + ))); + + $this->viewMock->expects($this->any()) + ->method('getFileInfo') + ->will($this->returnValue(array( + 'fileid' => 123, + 'type' => 'dir', + 'mimetype' => 'httpd/unix-directory', + 'size' => 18, + 'etag' => 'abcdef', + 'directory' => '/unexist', + 'name' => 'new_name', + ))); + + $result = $this->files->rename($dir, $oldname, $newname); + $this->assertFalse($result['success']); $this->assertEquals('targetnotfound', $result['data']['code']); } -- cgit v1.2.3