aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Node/FileTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Node/FileTest.php')
-rw-r--r--tests/lib/Files/Node/FileTest.php73
1 files changed, 38 insertions, 35 deletions
diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php
index 74a23520344..f3d893d5af2 100644
--- a/tests/lib/Files/Node/FileTest.php
+++ b/tests/lib/Files/Node/FileTest.php
@@ -7,7 +7,10 @@
namespace Test\Files\Node;
+use OC\Files\Node\File;
use OC\Files\Node\Root;
+use OCP\Constants;
+use OCP\Files\NotPermittedException;
/**
* Class FileTest
@@ -19,9 +22,9 @@ use OC\Files\Node\Root;
class FileTest extends NodeTestCase {
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
if ($data || $internalPath || $storage) {
- return new \OC\Files\Node\File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
+ return new File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
} else {
- return new \OC\Files\Node\File($root, $view, $path);
+ return new File($root, $view, $path);
}
}
@@ -43,7 +46,7 @@ class FileTest extends NodeTestCase {
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -58,15 +61,15 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$this->assertEquals('bar', $node->getContent());
}
public function testGetContentNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
@@ -82,7 +85,7 @@ class FileTest extends NodeTestCase {
->with('/bar/foo')
->willReturn($this->getFileInfo(['permissions' => 0]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->getContent();
}
@@ -99,20 +102,20 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$this->view->expects($this->once())
->method('file_put_contents')
->with('/bar/foo', 'bar')
->willReturn(true);
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->putContent('bar');
}
public function testPutContentNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
@@ -122,9 +125,9 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->putContent('bar');
}
@@ -139,7 +142,7 @@ class FileTest extends NodeTestCase {
->with('/bar/foo')
->willReturn($this->getFileInfo(['mimetype' => 'text/plain']));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$this->assertEquals('text/plain', $node->getMimeType());
}
@@ -148,7 +151,7 @@ class FileTest extends NodeTestCase {
fwrite($stream, 'bar');
rewind($stream);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -159,7 +162,7 @@ class FileTest extends NodeTestCase {
$this->cacheFactory,
);
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -174,9 +177,9 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$fh = $node->fopen('r');
$this->assertEquals($stream, $fh);
$this->assertEquals('bar', fread($fh, 3));
@@ -185,7 +188,7 @@ class FileTest extends NodeTestCase {
public function testFOpenWrite(): void {
$stream = fopen('php://memory', 'w+');
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -196,7 +199,7 @@ class FileTest extends NodeTestCase {
$this->cacheFactory,
);
$hooksCalled = 0;
- $hook = function ($file) use (&$hooksCalled) {
+ $hook = function ($file) use (&$hooksCalled): void {
$hooksCalled++;
};
@@ -211,9 +214,9 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$fh = $node->fopen('w');
$this->assertEquals($stream, $fh);
fwrite($fh, 'bar');
@@ -224,9 +227,9 @@ class FileTest extends NodeTestCase {
public function testFOpenReadNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -236,7 +239,7 @@ class FileTest extends NodeTestCase {
$this->eventDispatcher,
$this->cacheFactory,
);
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -245,15 +248,15 @@ class FileTest extends NodeTestCase {
->with('/bar/foo')
->willReturn($this->getFileInfo(['permissions' => 0]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('r');
}
public function testFOpenReadWriteNoReadPermissions(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -263,24 +266,24 @@ class FileTest extends NodeTestCase {
$this->eventDispatcher,
$this->cacheFactory,
);
- $hook = function () {
+ $hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');
};
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_UPDATE]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_UPDATE]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('w');
}
public function testFOpenReadWriteNoWritePermissions(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -290,16 +293,16 @@ class FileTest extends NodeTestCase {
$this->eventDispatcher,
$this->cacheFactory,
);
- $hook = function () {
+ $hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');
};
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('w');
}
}