Fix more unit tests to pass a mock storage instead of null to FileInfo

This commit is contained in:
Vincent Petry 2015-12-08 16:33:39 +01:00
parent 6e4006d139
commit 28e9bc1156
4 changed files with 53 additions and 21 deletions

View File

@ -48,6 +48,14 @@ class File extends \Test\TestCase {
parent::tearDown();
}
private function getMockStorage() {
$storage = $this->getMock('\OCP\Files\Storage');
$storage->expects($this->any())
->method('getId')
->will($this->returnValue('home::someuser'));
return $storage;
}
/**
* @param string $string
*/
@ -149,7 +157,7 @@ class File extends \Test\TestCase {
->method('getRelativePath')
->will($this->returnArgument(0));
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -209,7 +217,7 @@ class File extends \Test\TestCase {
$_SERVER['HTTP_OC_CHUNKED'] = true;
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-0', null, null, [
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@ -219,7 +227,7 @@ class File extends \Test\TestCase {
$this->assertNull($file->put('test data one'));
$file->releaseLock(ILockingProvider::LOCK_SHARED);
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', null, null, [
$info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@ -261,7 +269,7 @@ class File extends \Test\TestCase {
$info = new \OC\Files\FileInfo(
$viewRoot . '/' . ltrim($path, '/'),
null,
$this->getMockStorage(),
null,
['permissions' => \OCP\Constants::PERMISSION_ALL],
null
@ -450,7 +458,7 @@ class File extends \Test\TestCase {
$_SERVER['CONTENT_LENGTH'] = 123456;
$_SERVER['REQUEST_METHOD'] = 'PUT';
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -483,7 +491,7 @@ class File extends \Test\TestCase {
// simulate situation where the target file is locked
$view->lockFile('/test.txt', ILockingProvider::LOCK_EXCLUSIVE);
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -518,7 +526,7 @@ class File extends \Test\TestCase {
$_SERVER['HTTP_OC_CHUNKED'] = true;
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-0', null, null, [
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@ -526,7 +534,7 @@ class File extends \Test\TestCase {
$this->assertNull($file->put('test data one'));
$file->releaseLock(ILockingProvider::LOCK_SHARED);
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', null, null, [
$info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [
'permissions' => \OCP\Constants::PERMISSION_ALL
], null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@ -555,7 +563,7 @@ class File extends \Test\TestCase {
->method('getRelativePath')
->will($this->returnArgument(0));
$info = new \OC\Files\FileInfo('/*', null, null, array(
$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@ -591,7 +599,7 @@ class File extends \Test\TestCase {
->method('getRelativePath')
->will($this->returnArgument(0));
$info = new \OC\Files\FileInfo('/*', null, null, array(
$info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
@ -618,7 +626,7 @@ class File extends \Test\TestCase {
$_SERVER['CONTENT_LENGTH'] = 12345;
$_SERVER['REQUEST_METHOD'] = 'PUT';
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -654,7 +662,7 @@ class File extends \Test\TestCase {
->method('unlink')
->will($this->returnValue(true));
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -672,7 +680,7 @@ class File extends \Test\TestCase {
$view = $this->getMock('\OC\Files\View',
array());
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => 0
), null);
@ -695,7 +703,7 @@ class File extends \Test\TestCase {
->method('unlink')
->will($this->returnValue(false));
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -718,7 +726,7 @@ class File extends \Test\TestCase {
->method('unlink')
->willThrowException(new ForbiddenException('', true));
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -753,7 +761,7 @@ class File extends \Test\TestCase {
$path = 'test-locking.txt';
$info = new \OC\Files\FileInfo(
'/' . $this->user . '/files/' . $path,
null,
$this->getMockStorage(),
null,
['permissions' => \OCP\Constants::PERMISSION_ALL],
null
@ -865,7 +873,7 @@ class File extends \Test\TestCase {
->method('fopen')
->will($this->returnValue(false));
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
@ -883,7 +891,7 @@ class File extends \Test\TestCase {
->method('fopen')
->willThrowException(new ForbiddenException('', true));
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
$info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);

View File

@ -21,8 +21,16 @@ class File extends \Test\TestCase {
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy);
}
protected function getMockStorage() {
$storage = $this->getMock('\OCP\Files\Storage');
$storage->expects($this->any())
->method('getId')
->will($this->returnValue('home::someuser'));
return $storage;
}
protected function getFileInfo($data) {
return new FileInfo('', null, '', $data, null);
return new FileInfo('', $this->getMockStorage(), '', $data, null);
}
public function testDelete() {

View File

@ -31,8 +31,16 @@ class Folder extends \Test\TestCase {
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy);
}
protected function getMockStorage() {
$storage = $this->getMock('\OCP\Files\Storage');
$storage->expects($this->any())
->method('getId')
->will($this->returnValue('home::someuser'));
return $storage;
}
protected function getFileInfo($data) {
return new FileInfo('', null, '', $data, null);
return new FileInfo('', $this->getMockStorage(), '', $data, null);
}
public function testDelete() {

View File

@ -18,8 +18,16 @@ class Node extends \Test\TestCase {
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy);
}
protected function getMockStorage() {
$storage = $this->getMock('\OCP\Files\Storage');
$storage->expects($this->any())
->method('getId')
->will($this->returnValue('home::someuser'));
return $storage;
}
protected function getFileInfo($data) {
return new FileInfo('', null, '', $data, null);
return new FileInfo('', $this->getMockStorage(), '', $data, null);
}
public function testStat() {