@@ -1,11 +1,11 @@ | |||
<?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. | |||
*/ | |||
class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Framework_TestCase { | |||
/** | |||
@@ -18,17 +18,18 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame | |||
*/ | |||
private $plugin; | |||
public function setUp() { | |||
private function init($view) { | |||
$this->server = new Sabre_DAV_Server(); | |||
$this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin(); | |||
$this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin($view); | |||
$this->plugin->initialize($this->server); | |||
} | |||
/** | |||
* @dataProvider lengthProvider | |||
*/ | |||
public function testLength($expected, $headers) | |||
{ | |||
public function testLength($expected, $headers) { | |||
$this->init(null); | |||
$this->server->httpRequest = new Sabre_HTTP_Request($headers); | |||
$length = $this->plugin->getLength(); | |||
$this->assertEquals($expected, $length); | |||
@@ -37,9 +38,8 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame | |||
/** | |||
* @dataProvider verifyContentLengthProvider | |||
*/ | |||
public function testVerifyContentLength($method, $fileSize, $headers) | |||
{ | |||
$this->plugin->fileView = $this->buildFileViewMock($fileSize); | |||
public function testVerifyContentLength($method, $fileSize, $headers) { | |||
$this->init($this->buildFileViewMock($fileSize)); | |||
$headers['REQUEST_METHOD'] = $method; | |||
$this->server->httpRequest = new Sabre_HTTP_Request($headers); | |||
@@ -51,12 +51,11 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame | |||
* @dataProvider verifyContentLengthFailedProvider | |||
* @expectedException Sabre_DAV_Exception_BadRequest | |||
*/ | |||
public function testVerifyContentLengthFailed($method, $fileSize, $headers) | |||
{ | |||
$this->plugin->fileView = $this->buildFileViewMock($fileSize); | |||
public function testVerifyContentLengthFailed($method, $fileSize, $headers) { | |||
$view = $this->buildFileViewMock($fileSize); | |||
$this->init($view); | |||
// we expect unlink to be called | |||
$this->plugin->fileView->expects($this->once())->method('unlink'); | |||
$view->expects($this->once())->method('unlink'); | |||
$headers['REQUEST_METHOD'] = $method; | |||
$this->server->httpRequest = new Sabre_HTTP_Request($headers); | |||
@@ -92,7 +91,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame | |||
private function buildFileViewMock($fileSize) { | |||
// mock filesystem | |||
$view = $this->getMock('\OC\Files\View', array('filesize', 'unlink'), array(), '', FALSE); | |||
$view = $this->getMock('\OC\Files\View', array('filesize', 'unlink'), array(), '', false); | |||
$view->expects($this->any())->method('filesize')->withAnyParameters()->will($this->returnValue($fileSize)); | |||
return $view; |
@@ -1,18 +1,32 @@ | |||
<?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. | |||
*/ | |||
class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase { | |||
private function getRootDir() { | |||
$view = $this->getMock('OC\Files\View', array(), array(), '', false); | |||
$view->expects($this->once()) | |||
->method('getRelativePath') | |||
->will($this->returnValue('')); | |||
$info = $this->getMock('OC\Files\FileInfo', array(), array(), '', false); | |||
$info->expects($this->once()) | |||
->method('getPath') | |||
->will($this->returnValue('')); | |||
return new OC_Connector_Sabre_Directory($view, $info); | |||
} | |||
/** | |||
* @expectedException Sabre_DAV_Exception_Forbidden | |||
*/ | |||
public function testCreateSharedFileFails() { | |||
$dir = new OC_Connector_Sabre_Directory(''); | |||
$dir = $this->getRootDir(); | |||
$dir->createFile('Shared'); | |||
} | |||
@@ -20,7 +34,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase { | |||
* @expectedException Sabre_DAV_Exception_Forbidden | |||
*/ | |||
public function testCreateSharedFolderFails() { | |||
$dir = new OC_Connector_Sabre_Directory(''); | |||
$dir = $this->getRootDir(); | |||
$dir->createDirectory('Shared'); | |||
} | |||
@@ -28,7 +42,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase { | |||
* @expectedException Sabre_DAV_Exception_Forbidden | |||
*/ | |||
public function testDeleteSharedFolderFails() { | |||
$dir = new OC_Connector_Sabre_Directory('Shared'); | |||
$dir = $this->getRootDir(); | |||
$dir->delete(); | |||
} | |||
} |
@@ -13,9 +13,20 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { | |||
*/ | |||
public function testSimplePutFails() { | |||
// setup | |||
$file = new OC_Connector_Sabre_File('/test.txt'); | |||
$file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents'), array(), '', FALSE); | |||
$file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(false)); | |||
$view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'), array(), '', false); | |||
$view->expects($this->any()) | |||
->method('file_put_contents') | |||
->will($this->returnValue(false)); | |||
$view->expects($this->any()) | |||
->method('getRelativePath') | |||
->will($this->returnValue('/test.txt')); | |||
$info = new \OC\Files\FileInfo('/test.txt', null, null, array( | |||
'permissions'=>\OCP\PERMISSION_ALL | |||
)); | |||
$file = new OC_Connector_Sabre_File($view, $info); | |||
// action | |||
$etag = $file->put('test data'); | |||
@@ -26,10 +37,25 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { | |||
*/ | |||
public function testSimplePutFailsOnRename() { | |||
// setup | |||
$file = new OC_Connector_Sabre_File('/test.txt'); | |||
$file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents', 'rename'), array(), '', FALSE); | |||
$file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(true)); | |||
$file->fileView->expects($this->any())->method('rename')->withAnyParameters()->will($this->returnValue(false)); | |||
$view = $this->getMock('\OC\Files\View', array('file_put_contents', 'rename', 'getRelativePath'), array(), '', false); | |||
$view->expects($this->any()) | |||
->method('file_put_contents') | |||
->withAnyParameters() | |||
->will($this->returnValue(true)); | |||
$view->expects($this->any()) | |||
->method('rename') | |||
->withAnyParameters() | |||
->will($this->returnValue(false)); | |||
$view->expects($this->any()) | |||
->method('getRelativePath') | |||
->will($this->returnValue('/test.txt')); | |||
$info = new \OC\Files\FileInfo('/test.txt', null, null, array( | |||
'permissions' => \OCP\PERMISSION_ALL | |||
)); | |||
$file = new OC_Connector_Sabre_File($view, $info); | |||
// action | |||
$etag = $file->put('test data'); | |||
@@ -40,9 +66,19 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { | |||
*/ | |||
public function testSimplePutInvalidChars() { | |||
// setup | |||
$file = new OC_Connector_Sabre_File('/super*star.txt'); | |||
$file->fileView = $this->getMock('\OC\Files\View', array('file_put_contents'), array(), '', FALSE); | |||
$file->fileView->expects($this->any())->method('file_put_contents')->withAnyParameters()->will($this->returnValue(false)); | |||
$view = $this->getMock('\OC\Files\View', array('file_put_contents', 'getRelativePath'), array(), '', false); | |||
$view->expects($this->any()) | |||
->method('file_put_contents') | |||
->will($this->returnValue(false)); | |||
$view->expects($this->any()) | |||
->method('getRelativePath') | |||
->will($this->returnValue('/super*star.txt')); | |||
$info = new \OC\Files\FileInfo('/super*star.txt', null, null, array( | |||
'permissions' => \OCP\PERMISSION_ALL | |||
)); | |||
$file = new OC_Connector_Sabre_File($view, $info); | |||
// action | |||
$etag = $file->put('test data'); | |||
@@ -54,9 +90,16 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { | |||
*/ | |||
public function testSetNameInvalidChars() { | |||
// setup | |||
$file = new OC_Connector_Sabre_File('/test.txt'); | |||
$file->fileView = $this->getMock('\OC\Files\View', array('isUpdatable'), array(), '', FALSE); | |||
$file->fileView->expects($this->any())->method('isUpdatable')->withAnyParameters()->will($this->returnValue(true)); | |||
$view = $this->getMock('\OC\Files\View', array('getRelativePath'), array(), '', false); | |||
$view->expects($this->any()) | |||
->method('getRelativePath') | |||
->will($this->returnValue('/super*star.txt')); | |||
$info = new \OC\Files\FileInfo('/super*star.txt', null, null, array( | |||
'permissions' => \OCP\PERMISSION_ALL | |||
)); | |||
$file = new OC_Connector_Sabre_File($view, $info); | |||
$file->setName('/super*star.txt'); | |||
} | |||
@@ -64,7 +107,17 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { | |||
* @expectedException Sabre_DAV_Exception_Forbidden | |||
*/ | |||
public function testDeleteSharedFails() { | |||
$file = new OC_Connector_Sabre_File('Shared'); | |||
$view = $this->getMock('\OC\Files\View', array('getRelativePath'), array(), '', false); | |||
$view->expects($this->any()) | |||
->method('getRelativePath') | |||
->will($this->returnValue('Shared')); | |||
$info = new \OC\Files\FileInfo('/Shared', null, null, array( | |||
'permissions' => \OCP\PERMISSION_ALL | |||
)); | |||
$file = new OC_Connector_Sabre_File($view, $info); | |||
$file->delete(); | |||
} | |||
} |
@@ -9,6 +9,7 @@ | |||
namespace Test\OC\Connector\Sabre; | |||
use OC\Files\FileInfo; | |||
use OC_Connector_Sabre_Directory; | |||
use PHPUnit_Framework_TestCase; | |||
use Sabre_DAV_Exception_Forbidden; | |||
@@ -32,6 +33,10 @@ class TestDoubleFileView extends \OC\Files\View{ | |||
public function rename($path1, $path2) { | |||
return $this->canRename; | |||
} | |||
public function getRelativePath($path){ | |||
return $path; | |||
} | |||
} | |||
class ObjectTree extends PHPUnit_Framework_TestCase { | |||
@@ -91,10 +96,14 @@ class ObjectTree extends PHPUnit_Framework_TestCase { | |||
* @param $updatables | |||
*/ | |||
private function moveTest($source, $dest, $updatables, $deletables) { | |||
$rootDir = new OC_Connector_Sabre_Directory(''); | |||
$view = new TestDoubleFileView($updatables, $deletables); | |||
$info = new FileInfo('', null, null, array()); | |||
$rootDir = new OC_Connector_Sabre_Directory($view, $info); | |||
$objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree', | |||
array('nodeExists', 'getNodeForPath'), | |||
array($rootDir)); | |||
array($rootDir, $view)); | |||
$objectTree->expects($this->once()) | |||
->method('getNodeForPath') | |||
@@ -102,7 +111,6 @@ class ObjectTree extends PHPUnit_Framework_TestCase { | |||
->will($this->returnValue(false)); | |||
/** @var $objectTree \OC\Connector\Sabre\ObjectTree */ | |||
$objectTree->fileView = new TestDoubleFileView($updatables, $deletables); | |||
$objectTree->move($source, $dest); | |||
} | |||
@@ -1,11 +1,11 @@ | |||
<?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. | |||
*/ | |||
class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { | |||
/** | |||
@@ -18,17 +18,18 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { | |||
*/ | |||
private $plugin; | |||
public function setUp() { | |||
private function init($quota) { | |||
$view = $this->buildFileViewMock($quota); | |||
$this->server = new Sabre_DAV_Server(); | |||
$this->plugin = new OC_Connector_Sabre_QuotaPlugin(); | |||
$this->plugin = new OC_Connector_Sabre_QuotaPlugin($view); | |||
$this->plugin->initialize($this->server); | |||
} | |||
/** | |||
* @dataProvider lengthProvider | |||
*/ | |||
public function testLength($expected, $headers) | |||
{ | |||
public function testLength($expected, $headers) { | |||
$this->init(0); | |||
$this->server->httpRequest = new Sabre_HTTP_Request($headers); | |||
$length = $this->plugin->getLength(); | |||
$this->assertEquals($expected, $length); | |||
@@ -37,9 +38,8 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { | |||
/** | |||
* @dataProvider quotaOkayProvider | |||
*/ | |||
public function testCheckQuota($quota, $headers) | |||
{ | |||
$this->plugin->fileView = $this->buildFileViewMock($quota); | |||
public function testCheckQuota($quota, $headers) { | |||
$this->init($quota); | |||
$this->server->httpRequest = new Sabre_HTTP_Request($headers); | |||
$result = $this->plugin->checkQuota(''); | |||
@@ -50,9 +50,8 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { | |||
* @expectedException Sabre_DAV_Exception_InsufficientStorage | |||
* @dataProvider quotaExceededProvider | |||
*/ | |||
public function testCheckExceededQuota($quota, $headers) | |||
{ | |||
$this->plugin->fileView = $this->buildFileViewMock($quota); | |||
public function testCheckExceededQuota($quota, $headers) { | |||
$this->init($quota); | |||
$this->server->httpRequest = new Sabre_HTTP_Request($headers); | |||
$this->plugin->checkQuota(''); | |||
@@ -92,7 +91,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { | |||
private function buildFileViewMock($quota) { | |||
// mock filesysten | |||
$view = $this->getMock('\OC\Files\View', array('free_space'), array(), '', FALSE); | |||
$view = $this->getMock('\OC\Files\View', array('free_space'), array(), '', false); | |||
$view->expects($this->any())->method('free_space')->withAnyParameters()->will($this->returnValue($quota)); | |||
return $view; |