Fixed unit tests for ajax rename

This commit is contained in:
Vincent Petry 2013-11-27 23:19:57 +01:00
parent 68f610a90e
commit bc64931cd0
1 changed files with 46 additions and 21 deletions

View File

@ -38,13 +38,14 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$l10nMock->expects($this->any()) $l10nMock->expects($this->any())
->method('t') ->method('t')
->will($this->returnArgument(0)); ->will($this->returnArgument(0));
$viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath'), array(), '', false); $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath', 'getFileInfo'), array(), '', false);
$viewMock->expects($this->any()) $viewMock->expects($this->any())
->method('normalizePath') ->method('normalizePath')
->will($this->returnArgument(0)); ->will($this->returnArgument(0));
$viewMock->expects($this->any()) $viewMock->expects($this->any())
->method('rename') ->method('rename')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$this->viewMock = $viewMock;
$this->files = new \OCA\Files\App($viewMock, $l10nMock); $this->files = new \OCA\Files\App($viewMock, $l10nMock);
} }
@ -79,17 +80,28 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$oldname = 'Shared'; $oldname = 'Shared';
$newname = 'new_name'; $newname = 'new_name';
$result = $this->files->rename($dir, $oldname, $newname); $this->viewMock->expects($this->any())
$expected = array( ->method('getFileInfo')
'success' => true, ->will($this->returnValue(array(
'data' => array( 'fileid' => 123,
'dir' => $dir, 'type' => 'dir',
'file' => $oldname, 'mimetype' => 'httpd/unix-directory',
'newname' => $newname 'size' => 18,
) 'etag' => 'abcdef',
); 'directory' => '/',
'name' => 'new_name',
)));
$this->assertEquals($expected, $result); $result = $this->files->rename($dir, $oldname, $newname);
$this->assertTrue($result['success']);
$this->assertEquals(123, $result['data']['id']);
$this->assertEquals('new_name', $result['data']['name']);
$this->assertEquals('/test', $result['data']['directory']);
$this->assertEquals(18, $result['data']['size']);
$this->assertEquals('httpd/unix-directory', $result['data']['mime']);
$this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']);
$this->assertFalse($result['data']['isPreviewAvailable']);
} }
/** /**
@ -117,16 +129,29 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase {
$oldname = 'oldname'; $oldname = 'oldname';
$newname = 'newname'; $newname = 'newname';
$result = $this->files->rename($dir, $oldname, $newname); $this->viewMock->expects($this->any())
$expected = array( ->method('getFileInfo')
'success' => true, ->will($this->returnValue(array(
'data' => array( 'fileid' => 123,
'dir' => $dir, 'type' => 'dir',
'file' => $oldname, 'mimetype' => 'httpd/unix-directory',
'newname' => $newname 'size' => 18,
) 'etag' => 'abcdef',
); 'directory' => '/',
'name' => 'new_name',
)));
$this->assertEquals($expected, $result);
$result = $this->files->rename($dir, $oldname, $newname);
$this->assertTrue($result['success']);
$this->assertEquals(123, $result['data']['id']);
$this->assertEquals('newname', $result['data']['name']);
$this->assertEquals('/', $result['data']['directory']);
$this->assertEquals(18, $result['data']['size']);
$this->assertEquals('httpd/unix-directory', $result['data']['mime']);
$this->assertEquals('abcdef', $result['data']['etag']);
$this->assertEquals(\OC_Helper::mimetypeIcon('dir'), $result['data']['icon']);
$this->assertFalse($result['data']['isPreviewAvailable']);
} }
} }