Fix sabre directory test cases

- rely on a mock subfolder instead of the root
- remove obsolete "Shared" limitation tests which did pass but not for the right
  reasons
- added test for the prevention of root deletion
This commit is contained in:
Vincent Petry 2015-06-05 19:04:59 +02:00
parent 6ae5ae2e31
commit b97be0ea02
1 changed files with 15 additions and 24 deletions

View File

@ -20,14 +20,14 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
$this->info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false); $this->info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
} }
private function getRootDir() { private function getDir($path = '/') {
$this->view->expects($this->once()) $this->view->expects($this->once())
->method('getRelativePath') ->method('getRelativePath')
->will($this->returnValue('')); ->will($this->returnValue($path));
$this->info->expects($this->once()) $this->info->expects($this->once())
->method('getPath') ->method('getPath')
->will($this->returnValue('')); ->will($this->returnValue($path));
return new \OC\Connector\Sabre\Directory($this->view, $this->info); return new \OC\Connector\Sabre\Directory($this->view, $this->info);
} }
@ -35,24 +35,13 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
/** /**
* @expectedException \Sabre\DAV\Exception\Forbidden * @expectedException \Sabre\DAV\Exception\Forbidden
*/ */
public function testCreateSharedFileFails() { public function testDeleteRootFolderFails() {
$dir = $this->getRootDir(); $this->info->expects($this->any())
$dir->createFile('Shared'); ->method('isDeletable')
} ->will($this->returnValue(true));
$this->view->expects($this->never())
/** ->method('rmdir');
* @expectedException \Sabre\DAV\Exception\Forbidden $dir = $this->getDir();
*/
public function testCreateSharedFolderFails() {
$dir = $this->getRootDir();
$dir->createDirectory('Shared');
}
/**
* @expectedException \Sabre\DAV\Exception\Forbidden
*/
public function testDeleteSharedFolderFails() {
$dir = $this->getRootDir();
$dir->delete(); $dir->delete();
} }
@ -68,9 +57,10 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
// but fails // but fails
$this->view->expects($this->once()) $this->view->expects($this->once())
->method('rmdir') ->method('rmdir')
->with('sub')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$dir = $this->getRootDir(); $dir = $this->getDir('sub');
$dir->delete(); $dir->delete();
} }
@ -82,7 +72,7 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
->method('isDeletable') ->method('isDeletable')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$dir = $this->getRootDir(); $dir = $this->getDir('sub');
$dir->delete(); $dir->delete();
} }
@ -98,9 +88,10 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
// but fails // but fails
$this->view->expects($this->once()) $this->view->expects($this->once())
->method('rmdir') ->method('rmdir')
->with('sub')
->will($this->returnValue(false)); ->will($this->returnValue(false));
$dir = $this->getRootDir(); $dir = $this->getDir('sub');
$dir->delete(); $dir->delete();
} }