2013-10-22 09:22:06 +00:00
|
|
|
<?php
|
2014-03-03 13:27:24 +00:00
|
|
|
|
2013-10-22 09:22:06 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase {
|
|
|
|
|
2014-09-22 10:19:34 +00:00
|
|
|
private $view;
|
|
|
|
private $info;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
$this->view = $this->getMock('OC\Files\View', array(), array(), '', false);
|
|
|
|
$this->info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false);
|
|
|
|
}
|
|
|
|
|
2014-03-03 13:27:24 +00:00
|
|
|
private function getRootDir() {
|
2014-09-22 10:19:34 +00:00
|
|
|
$this->view->expects($this->once())
|
2014-03-03 13:27:24 +00:00
|
|
|
->method('getRelativePath')
|
|
|
|
->will($this->returnValue(''));
|
|
|
|
|
2014-09-22 10:19:34 +00:00
|
|
|
$this->info->expects($this->once())
|
2014-03-03 13:27:24 +00:00
|
|
|
->method('getPath')
|
|
|
|
->will($this->returnValue(''));
|
|
|
|
|
2014-09-22 10:19:34 +00:00
|
|
|
return new OC_Connector_Sabre_Directory($this->view, $this->info);
|
2014-03-03 13:27:24 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 09:22:06 +00:00
|
|
|
/**
|
2014-01-09 13:25:48 +00:00
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
2013-10-22 09:22:06 +00:00
|
|
|
*/
|
|
|
|
public function testCreateSharedFileFails() {
|
2014-03-03 13:27:24 +00:00
|
|
|
$dir = $this->getRootDir();
|
2013-10-22 09:22:06 +00:00
|
|
|
$dir->createFile('Shared');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-09 13:25:48 +00:00
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
2013-10-22 09:22:06 +00:00
|
|
|
*/
|
|
|
|
public function testCreateSharedFolderFails() {
|
2014-03-03 13:27:24 +00:00
|
|
|
$dir = $this->getRootDir();
|
2013-10-22 09:22:06 +00:00
|
|
|
$dir->createDirectory('Shared');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-09 13:25:48 +00:00
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
2013-10-22 09:22:06 +00:00
|
|
|
*/
|
|
|
|
public function testDeleteSharedFolderFails() {
|
2014-03-03 13:27:24 +00:00
|
|
|
$dir = $this->getRootDir();
|
2013-10-22 09:22:06 +00:00
|
|
|
$dir->delete();
|
|
|
|
}
|
2014-09-22 10:19:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function testDeleteFolderWhenAllowed() {
|
|
|
|
// deletion allowed
|
|
|
|
$this->info->expects($this->once())
|
|
|
|
->method('isDeletable')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
// but fails
|
|
|
|
$this->view->expects($this->once())
|
|
|
|
->method('rmdir')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$dir = $this->getRootDir();
|
|
|
|
$dir->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
|
|
|
public function testDeleteFolderFailsWhenNotAllowed() {
|
|
|
|
$this->info->expects($this->once())
|
|
|
|
->method('isDeletable')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$dir = $this->getRootDir();
|
|
|
|
$dir->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
|
|
|
public function testDeleteFolderThrowsWhenDeletionFailed() {
|
|
|
|
// deletion allowed
|
|
|
|
$this->info->expects($this->once())
|
|
|
|
->method('isDeletable')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
// but fails
|
|
|
|
$this->view->expects($this->once())
|
|
|
|
->method('rmdir')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$dir = $this->getRootDir();
|
|
|
|
$dir->delete();
|
|
|
|
}
|
2013-10-22 09:22:06 +00:00
|
|
|
}
|