2013-09-26 12:50:15 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\OC\Connector\Sabre;
|
|
|
|
|
|
|
|
|
2014-03-03 17:27:24 +04:00
|
|
|
use OC\Files\FileInfo;
|
2013-09-26 12:50:15 +04:00
|
|
|
use OC_Connector_Sabre_Directory;
|
|
|
|
use PHPUnit_Framework_TestCase;
|
|
|
|
|
|
|
|
class TestDoubleFileView extends \OC\Files\View{
|
|
|
|
|
2013-10-08 13:43:44 +04:00
|
|
|
public function __construct($updatables, $deletables, $canRename = true) {
|
2013-09-26 12:50:15 +04:00
|
|
|
$this->updatables = $updatables;
|
2013-10-08 13:43:44 +04:00
|
|
|
$this->deletables = $deletables;
|
2013-09-26 12:50:15 +04:00
|
|
|
$this->canRename = $canRename;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isUpdatable($path) {
|
|
|
|
return $this->updatables[$path];
|
|
|
|
}
|
|
|
|
|
2014-06-20 17:40:38 +04:00
|
|
|
public function isCreatable($path) {
|
|
|
|
return $this->updatables[$path];
|
|
|
|
}
|
|
|
|
|
2013-10-08 13:43:44 +04:00
|
|
|
public function isDeletable($path) {
|
|
|
|
return $this->deletables[$path];
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:50:15 +04:00
|
|
|
public function rename($path1, $path2) {
|
|
|
|
return $this->canRename;
|
|
|
|
}
|
2014-03-03 17:27:24 +04:00
|
|
|
|
|
|
|
public function getRelativePath($path){
|
|
|
|
return $path;
|
|
|
|
}
|
2013-09-26 12:50:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectTree extends PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider moveFailedProvider
|
2014-01-09 17:25:48 +04:00
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
2013-09-26 12:50:15 +04:00
|
|
|
*/
|
2013-10-08 13:43:44 +04:00
|
|
|
public function testMoveFailed($source, $dest, $updatables, $deletables) {
|
|
|
|
$this->moveTest($source, $dest, $updatables, $deletables);
|
2013-09-26 12:50:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider moveSuccessProvider
|
|
|
|
*/
|
2013-10-08 13:43:44 +04:00
|
|
|
public function testMoveSuccess($source, $dest, $updatables, $deletables) {
|
|
|
|
$this->moveTest($source, $dest, $updatables, $deletables);
|
2013-09-26 12:50:15 +04:00
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
|
|
|
|
2014-01-13 16:14:05 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider moveFailedInvalidCharsProvider
|
2014-01-09 17:25:48 +04:00
|
|
|
* @expectedException \Sabre\DAV\Exception\BadRequest
|
2014-01-13 16:14:05 +04:00
|
|
|
*/
|
|
|
|
public function testMoveFailedInvalidChars($source, $dest, $updatables, $deletables) {
|
|
|
|
$this->moveTest($source, $dest, $updatables, $deletables);
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveFailedInvalidCharsProvider() {
|
|
|
|
return array(
|
|
|
|
array('a/b', 'a/c*', array('a' => false, 'a/b' => true, 'a/c*' => false), array()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:50:15 +04:00
|
|
|
function moveFailedProvider() {
|
|
|
|
return array(
|
2013-10-08 13:43:44 +04:00
|
|
|
array('a/b', 'a/c', array('a' => false, 'a/b' => false, 'a/c' => false), array()),
|
|
|
|
array('a/b', 'b/b', array('a' => false, 'a/b' => false, 'b' => false, 'b/b' => false), array()),
|
|
|
|
array('a/b', 'b/b', array('a' => false, 'a/b' => true, 'b' => false, 'b/b' => false), array()),
|
|
|
|
array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => false, 'b/b' => false), array()),
|
|
|
|
array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false), array('a/b' => false)),
|
2013-09-26 12:50:15 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveSuccessProvider() {
|
|
|
|
return array(
|
2013-10-08 13:43:44 +04:00
|
|
|
array('a/b', 'a/c', array('a' => false, 'a/b' => true, 'a/c' => false), array()),
|
|
|
|
array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false), array('a/b' => true)),
|
2014-01-13 16:14:05 +04:00
|
|
|
// older files with special chars can still be renamed to valid names
|
|
|
|
array('a/b*', 'b/b', array('a' => true, 'a/b*' => true, 'b' => true, 'b/b' => false), array('a/b*' => true)),
|
2013-09-26 12:50:15 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-27 15:41:23 +04:00
|
|
|
/**
|
|
|
|
* @param $source
|
|
|
|
* @param $dest
|
|
|
|
* @param $updatables
|
|
|
|
*/
|
2013-10-08 13:43:44 +04:00
|
|
|
private function moveTest($source, $dest, $updatables, $deletables) {
|
2014-03-03 17:27:24 +04:00
|
|
|
$view = new TestDoubleFileView($updatables, $deletables);
|
|
|
|
|
|
|
|
$info = new FileInfo('', null, null, array());
|
|
|
|
|
|
|
|
$rootDir = new OC_Connector_Sabre_Directory($view, $info);
|
2013-09-27 15:41:23 +04:00
|
|
|
$objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
|
|
|
|
array('nodeExists', 'getNodeForPath'),
|
2014-03-03 17:27:24 +04:00
|
|
|
array($rootDir, $view));
|
2013-09-27 15:41:23 +04:00
|
|
|
|
|
|
|
$objectTree->expects($this->once())
|
|
|
|
->method('getNodeForPath')
|
|
|
|
->with($this->identicalTo($source))
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
/** @var $objectTree \OC\Connector\Sabre\ObjectTree */
|
2014-06-17 16:10:11 +04:00
|
|
|
$mountManager = \OC\Files\Filesystem::getMountManager();
|
|
|
|
$objectTree->init($rootDir, $view, $mountManager);
|
2013-09-27 15:41:23 +04:00
|
|
|
$objectTree->move($source, $dest);
|
|
|
|
}
|
2013-09-26 12:50:15 +04:00
|
|
|
|
|
|
|
}
|