Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests: Adapt node related unit tests mocks to required root view
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and backportbot-nextcloud[bot] committed May 8, 2023
commit 6520fa1ac9e123f5ae6d18e932039e8a5c0e5f4e
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ public function testGetChildren(): void {

$this->view->expects($this->any())
->method('getRelativePath')
->willReturnCallback(function($path) {
->willReturnCallback(function ($path) {
return str_replace('/admin/files/', '', $path);
});

$this->view->expects($this->any())
->method('getAbsolutePath')
->willReturnCallback(function($path) {
->willReturnCallback(function ($path) {
return Filesystem::normalizePath('/admin/files' . $path);
});

Expand Down
8 changes: 5 additions & 3 deletions apps/dav/tests/unit/Files/FileSearchBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ protected function setUp(): void {
->disableOriginalConstructor()
->getMock();

$this->view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->getMock();
$this->view = $this->createMock(View::class);

$this->view->expects($this->any())
->method('getRoot')
->willReturn('');

$this->view->expects($this->any())
->method('getRelativePath')
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/Node/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function testFOpenWrite() {

$root = new \OC\Files\Node\Root(
$this->manager,
new $this->view,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
Expand Down Expand Up @@ -277,7 +277,7 @@ public function testFOpenReadWriteNoWritePermissions() {

$root = new \OC\Files\Node\Root(
$this->manager,
new $this->view,
$this->view,
$this->user,
$this->userMountCache,
$this->logger,
Expand Down
131 changes: 33 additions & 98 deletions tests/lib/Files/Node/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\View;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
Expand All @@ -40,6 +39,9 @@
*/
class FolderTest extends NodeTest {
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
$view->expects($this->any())
->method('getRoot')
->willReturn('');
if ($data || $internalPath || $storage) {
return new Folder($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
} else {
Expand All @@ -64,27 +66,26 @@ public function testGetDirectoryContent() {
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->setConstructorArgs([$manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
$root->expects($this->any())
->method('getUser')
->willReturn($this->user);

$view->expects($this->any())
$this->view->expects($this->any())
->method('getDirectoryContent')
->with('/bar/foo')
->willReturn([
new FileInfo('/bar/foo/asd', null, 'foo/asd', ['fileid' => 2, 'path' => '/bar/foo/asd', 'name' => 'asd', 'size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain'], null),
new FileInfo('/bar/foo/qwerty', null, 'foo/qwerty', ['fileid' => 3, 'path' => '/bar/foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'httpd/unix-directory'], null),
]);
$view->method('getFileInfo')
$this->view->method('getFileInfo')
->willReturn($this->createMock(FileInfo::class));
$view->method('getRelativePath')
$this->view->method('getRelativePath')
->willReturn('/bar/foo');

$node = new Folder($root, $view, '/bar/foo');
$node = new Folder($root, $this->view, '/bar/foo');
$children = $node->getDirectoryListing();
$this->assertEquals(2, count($children));
$this->assertInstanceOf('\OC\Files\Node\File', $children[0]);
Expand All @@ -97,10 +98,7 @@ public function testGetDirectoryContent() {

public function testGet() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -119,10 +117,7 @@ public function testGet() {

public function testNodeExists() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -142,10 +137,7 @@ public function testNodeExists() {

public function testNodeExistsNotExists() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -163,10 +155,7 @@ public function testNodeExistsNotExists() {

public function testNewFolder() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -190,10 +179,7 @@ public function testNewFolder() {

public function testNewFolderDeepParent() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -220,10 +206,7 @@ public function testNewFolderNotPermitted() {
$this->expectException(\OCP\Files\NotPermittedException::class);

$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -240,10 +223,7 @@ public function testNewFolderNotPermitted() {

public function testNewFile() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -270,10 +250,7 @@ public function testNewFileNotPermitted() {
$this->expectException(\OCP\Files\NotPermittedException::class);

$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -290,10 +267,7 @@ public function testNewFileNotPermitted() {

public function testGetFreeSpace() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand All @@ -310,10 +284,7 @@ public function testGetFreeSpace() {

public function testSearch() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand Down Expand Up @@ -353,10 +324,7 @@ public function testSearch() {

public function testSearchInRoot() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
Expand Down Expand Up @@ -397,10 +365,7 @@ public function testSearchInRoot() {

public function testSearchInStorageRoot() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand Down Expand Up @@ -440,10 +405,7 @@ public function testSearchInStorageRoot() {

public function testSearchSubStorages() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand Down Expand Up @@ -500,21 +462,18 @@ public function testSearchSubStorages() {
}

public function testIsSubNode() {
$file = new Node(null, null, '/foo/bar');
$folder = new Folder(null, null, '/foo');
$file = new Node(null, $this->view, '/foo/bar');
$folder = new Folder(null, $this->view, '/foo');
$this->assertTrue($folder->isSubNode($file));
$this->assertFalse($folder->isSubNode($folder));

$file = new Node(null, null, '/foobar');
$file = new Node(null, $this->view, '/foobar');
$this->assertFalse($folder->isSubNode($file));
}

public function testGetById() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
Expand Down Expand Up @@ -561,10 +520,7 @@ public function testGetById() {

public function testGetByIdMountRoot() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
Expand Down Expand Up @@ -607,10 +563,7 @@ public function testGetByIdMountRoot() {

public function testGetByIdOutsideFolder() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
Expand Down Expand Up @@ -652,10 +605,7 @@ public function testGetByIdOutsideFolder() {

public function testGetByIdMultipleStorages() {
$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
Expand Down Expand Up @@ -717,10 +667,7 @@ public function uniqueNameProvider() {
public function testGetUniqueName($name, $existingFiles, $expected) {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
Expand All @@ -744,10 +691,7 @@ public function testGetUniqueName($name, $existingFiles, $expected) {
public function testRecent(): void {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
->setMethods(['getUser', 'getMountsIn', 'getMount'])
Expand Down Expand Up @@ -812,10 +756,7 @@ public function testRecent(): void {
public function testRecentFolder() {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
->setMethods(['getUser', 'getMountsIn', 'getMount'])
Expand Down Expand Up @@ -879,10 +820,7 @@ public function testRecentFolder() {
public function testRecentJail() {
$manager = $this->createMock(Manager::class);
$folderPath = '/bar/foo';
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
->setMethods(['getUser', 'getMountsIn', 'getMount'])
Expand Down Expand Up @@ -968,10 +906,7 @@ public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array
}

$manager = $this->createMock(Manager::class);
/**
* @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view
*/
$view = $this->createMock(View::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher])
->getMock();
Expand Down
Loading