Fix unit test of file plugin

This commit is contained in:
Thomas Müller 2016-04-12 15:51:09 +02:00
parent bb2e68f72b
commit e21642ca31
2 changed files with 21 additions and 14 deletions

View File

@ -155,7 +155,7 @@ class FilesPlugin extends ServerPlugin {
* @throws NotFound * @throws NotFound
*/ */
function checkMove($source, $destination) { function checkMove($source, $destination) {
$sourceNode = $this->server->tree->getNodeForPath($source); $sourceNode = $this->tree->getNodeForPath($source);
if ($sourceNode instanceof FutureFile) { if ($sourceNode instanceof FutureFile) {
return; return;
} }

View File

@ -23,6 +23,9 @@
namespace OCA\DAV\Tests\Unit\Connector\Sabre; namespace OCA\DAV\Tests\Unit\Connector\Sabre;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
use Test\TestCase;
/** /**
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
@ -30,7 +33,7 @@ use OCP\Files\StorageNotAvailableException;
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
class FilesPlugin extends \Test\TestCase { class FilesPlugin extends TestCase {
const GETETAG_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::GETETAG_PROPERTYNAME; const GETETAG_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::GETETAG_PROPERTYNAME;
const FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::FILEID_PROPERTYNAME; const FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::FILEID_PROPERTYNAME;
const INTERNAL_FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::INTERNAL_FILEID_PROPERTYNAME; const INTERNAL_FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::INTERNAL_FILEID_PROPERTYNAME;
@ -42,12 +45,12 @@ class FilesPlugin extends \Test\TestCase {
const OWNER_DISPLAY_NAME_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME; const OWNER_DISPLAY_NAME_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME;
/** /**
* @var \Sabre\DAV\Server * @var \Sabre\DAV\Server | \PHPUnit_Framework_MockObject_MockObject
*/ */
private $server; private $server;
/** /**
* @var \Sabre\DAV\Tree * @var \Sabre\DAV\Tree | \PHPUnit_Framework_MockObject_MockObject
*/ */
private $tree; private $tree;
@ -57,7 +60,7 @@ class FilesPlugin extends \Test\TestCase {
private $plugin; private $plugin;
/** /**
* @var \OC\Files\View * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject
*/ */
private $view; private $view;
@ -79,6 +82,7 @@ class FilesPlugin extends \Test\TestCase {
/** /**
* @param string $class * @param string $class
* @return \PHPUnit_Framework_MockObject_MockObject
*/ */
private function createTestNode($class) { private function createTestNode($class) {
$node = $this->getMockBuilder($class) $node = $this->getMockBuilder($class)
@ -111,9 +115,10 @@ class FilesPlugin extends \Test\TestCase {
} }
public function testGetPropertiesForFile() { public function testGetPropertiesForFile() {
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File'); $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$propFind = new \Sabre\DAV\PropFind( $propFind = new PropFind(
'/dummyPath', '/dummyPath',
array( array(
self::GETETAG_PROPERTYNAME, self::GETETAG_PROPERTYNAME,
@ -165,11 +170,12 @@ class FilesPlugin extends \Test\TestCase {
} }
public function testGetPropertiesForFileHome() { public function testGetPropertiesForFileHome() {
/** @var \OCA\DAV\Files\FilesHome | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->getMockBuilder('\OCA\DAV\Files\FilesHome') $node = $this->getMockBuilder('\OCA\DAV\Files\FilesHome')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$propFind = new \Sabre\DAV\PropFind( $propFind = new PropFind(
'/dummyPath', '/dummyPath',
array( array(
self::GETETAG_PROPERTYNAME, self::GETETAG_PROPERTYNAME,
@ -214,9 +220,10 @@ class FilesPlugin extends \Test\TestCase {
} }
public function testGetPropertiesStorageNotAvailable() { public function testGetPropertiesStorageNotAvailable() {
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File'); $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$propFind = new \Sabre\DAV\PropFind( $propFind = new PropFind(
'/dummyPath', '/dummyPath',
array( array(
self::DOWNLOADURL_PROPERTYNAME, self::DOWNLOADURL_PROPERTYNAME,
@ -240,7 +247,7 @@ class FilesPlugin extends \Test\TestCase {
$this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true); $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true);
$this->plugin->initialize($this->server); $this->plugin->initialize($this->server);
$propFind = new \Sabre\DAV\PropFind( $propFind = new PropFind(
'/dummyPath', '/dummyPath',
[ [
self::PERMISSIONS_PROPERTYNAME, self::PERMISSIONS_PROPERTYNAME,
@ -248,6 +255,7 @@ class FilesPlugin extends \Test\TestCase {
0 0
); );
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File'); $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$node->expects($this->any()) $node->expects($this->any())
->method('getDavPermissions') ->method('getDavPermissions')
@ -262,9 +270,10 @@ class FilesPlugin extends \Test\TestCase {
} }
public function testGetPropertiesForDirectory() { public function testGetPropertiesForDirectory() {
/** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory'); $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
$propFind = new \Sabre\DAV\PropFind( $propFind = new PropFind(
'/dummyPath', '/dummyPath',
array( array(
self::GETETAG_PROPERTYNAME, self::GETETAG_PROPERTYNAME,
@ -308,7 +317,7 @@ class FilesPlugin extends \Test\TestCase {
->will($this->returnValue(true)); ->will($this->returnValue(true));
// properties to set // properties to set
$propPatch = new \Sabre\DAV\PropPatch(array( $propPatch = new PropPatch(array(
self::GETETAG_PROPERTYNAME => 'newetag', self::GETETAG_PROPERTYNAME => 'newetag',
self::LASTMODIFIED_PROPERTYNAME => $testDate self::LASTMODIFIED_PROPERTYNAME => $testDate
)); ));
@ -328,9 +337,7 @@ class FilesPlugin extends \Test\TestCase {
} }
public function testUpdatePropsForbidden() { public function testUpdatePropsForbidden() {
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File'); $propPatch = new PropPatch(array(
$propPatch = new \Sabre\DAV\PropPatch(array(
self::OWNER_ID_PROPERTYNAME => 'user2', self::OWNER_ID_PROPERTYNAME => 'user2',
self::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two', self::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two',
self::FILEID_PROPERTYNAME => 12345, self::FILEID_PROPERTYNAME => 12345,