diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2023-04-20 16:52:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-20 16:52:38 +0200 |
commit | b294edad804f40618a96116845615831302d0357 (patch) | |
tree | 71023e0f6d2185d44a4a62200e5613efa8aee089 /tests | |
parent | 8d5165e8dc40289b5d523523c4140f780b2fe293 (diff) | |
parent | 590c202797e6f5018635e45cdb2ed79ecd1c9865 (diff) | |
download | nextcloud-server-b294edad804f40618a96116845615831302d0357.tar.gz nextcloud-server-b294edad804f40618a96116845615831302d0357.zip |
Merge branch 'master' into enh/type-iconfig-getter-calls
Signed-off-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php | 1 | ||||
-rw-r--r-- | tests/Core/Command/Preview/RepairTest.php | 1 | ||||
-rw-r--r-- | tests/Core/Controller/LostControllerTest.php | 36 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/FilesAppContext.php | 2 | ||||
-rw-r--r-- | tests/acceptance/features/header.feature | 20 | ||||
-rw-r--r-- | tests/lib/AppFramework/Middleware/MiddlewareTest.php | 16 | ||||
-rw-r--r-- | tests/lib/Encryption/DecryptAllTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Files/Node/FileTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 131 | ||||
-rw-r--r-- | tests/lib/Files/Node/NodeTest.php | 14 | ||||
-rw-r--r-- | tests/lib/Files/Node/RootTest.php | 43 | ||||
-rw-r--r-- | tests/lib/Preview/GeneratorTest.php | 19 | ||||
-rw-r--r-- | tests/lib/Updater/ChangesCheckTest.php | 12 |
13 files changed, 141 insertions, 162 deletions
diff --git a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php index 1d5e2ac420d..ecb3faaa25d 100644 --- a/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php +++ b/tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php @@ -75,6 +75,7 @@ class ChangeKeyStorageRootTest extends TestCase { /* We need format method to return a string */ $outputFormatter = $this->createMock(OutputFormatterInterface::class); + $outputFormatter->method('isDecorated')->willReturn(false); $outputFormatter->method('format')->willReturnArgument(0); $this->outputInterface->expects($this->any())->method('getFormatter') diff --git a/tests/Core/Command/Preview/RepairTest.php b/tests/Core/Command/Preview/RepairTest.php index d235c0d0aea..090e9cc0bd0 100644 --- a/tests/Core/Command/Preview/RepairTest.php +++ b/tests/Core/Command/Preview/RepairTest.php @@ -71,6 +71,7 @@ class RepairTest extends TestCase { /* We need format method to return a string */ $outputFormatter = $this->createMock(OutputFormatterInterface::class); + $outputFormatter->method('isDecorated')->willReturn(false); $outputFormatter->method('format')->willReturnArgument(0); $this->output->expects($this->any()) diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index e95c3fa1c51..1481a1e46d4 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -1,8 +1,10 @@ <?php /** * @author Lukas Reschke <lukas@owncloud.com> + * @author Joshua Trees <me@jtrees.io> * * @copyright Copyright (c) 2015, ownCloud, Inc. + * @copyright Copyright (c) 2023, Joshua Trees <me@jtrees.io> * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -721,4 +723,38 @@ class LostControllerTest extends TestCase { $result = self::invokePrivate($this->lostController, 'findUserByIdOrMail', ['test@example.com']); $this->assertInstanceOf(IUser::class, $result); } + + public function testTrimEmailInput() { + $this->userManager + ->expects($this->once()) + ->method('getByEmail') + ->with('test@example.com') + ->willReturn([$this->existingUser]); + + $this->mailer + ->expects($this->once()) + ->method('send'); + + $response = $this->lostController->email(' test@example.com '); + $expectedResponse = new JSONResponse(['status' => 'success']); + $expectedResponse->throttle(); + $this->assertEquals($expectedResponse, $response); + } + + public function testUsernameInput() { + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('ExistingUser') + ->willReturn($this->existingUser); + + $this->mailer + ->expects($this->once()) + ->method('send'); + + $response = $this->lostController->email(' ExistingUser '); + $expectedResponse = new JSONResponse(['status' => 'success']); + $expectedResponse->throttle(); + $this->assertEquals($expectedResponse, $response); + } } diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php index b4b6e72e5b5..ec1f89e1462 100644 --- a/tests/acceptance/features/bootstrap/FilesAppContext.php +++ b/tests/acceptance/features/bootstrap/FilesAppContext.php @@ -73,7 +73,7 @@ class FilesAppContext implements Context, ActorAwareInterface { * @return Locator */ public static function currentSectionMainView() { - return Locator::forThe()->xpath("//*[starts-with(@id, 'app-content-') and not(contains(concat(' ', normalize-space(@class), ' '), ' hidden '))]")-> + return Locator::forThe()->xpath("//*[starts-with(@id, 'app-content-') and not(@id = 'app-content-vue') and not(contains(concat(' ', normalize-space(@class), ' '), ' hidden '))]")-> describedAs("Current section main view in Files app"); } diff --git a/tests/acceptance/features/header.feature b/tests/acceptance/features/header.feature index ac5da75425c..d453f5dff6b 100644 --- a/tests/acceptance/features/header.feature +++ b/tests/acceptance/features/header.feature @@ -33,16 +33,16 @@ Feature: header And I see that the contact "user0" in the Contacts menu is shown And I see that the contact "admin" in the Contacts menu is not shown - Scenario: users from other groups are not seen in the contacts menu when autocompletion is restricted within the same group - Given I am logged in as the admin - And I visit the admin settings page - And I open the "Sharing" section of the "Administration" group - And I enable restricting username autocompletion to groups - And I see that username autocompletion is restricted to groups - When I open the Contacts menu - Then I see that the Contacts menu is shown - And I see that the contact "user0" in the Contacts menu is not shown - And I see that the contact "admin" in the Contacts menu is not shown +# Scenario: users from other groups are not seen in the contacts menu when autocompletion is restricted within the same group +# Given I am logged in as the admin +# And I visit the admin settings page +# And I open the "Sharing" section of the "Administration" group +# And I enable restricting username autocompletion to groups +# And I see that username autocompletion is restricted to groups +# When I open the Contacts menu +# Then I see that the Contacts menu is shown +# And I see that the contact "user0" in the Contacts menu is not shown +# And I see that the contact "admin" in the Contacts menu is not shown Scenario: just added users are seen in the contacts menu Given I am logged in as the admin diff --git a/tests/lib/AppFramework/Middleware/MiddlewareTest.php b/tests/lib/AppFramework/Middleware/MiddlewareTest.php index f9d8926db7e..f9e775269d4 100644 --- a/tests/lib/AppFramework/Middleware/MiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/MiddlewareTest.php @@ -70,27 +70,27 @@ class MiddlewareTest extends \Test\TestCase { } - public function testBeforeController() { - $this->middleware->beforeController($this->controller, null); + public function testBeforeController(): void { + $this->middleware->beforeController($this->controller, ''); $this->assertNull(null); } - public function testAfterExceptionRaiseAgainWhenUnhandled() { + public function testAfterExceptionRaiseAgainWhenUnhandled(): void { $this->expectException(\Exception::class); - $this->middleware->afterException($this->controller, null, $this->exception); + $this->middleware->afterException($this->controller, '', $this->exception); } - public function testAfterControllerReturnResponseWhenUnhandled() { - $response = $this->middleware->afterController($this->controller, null, $this->response); + public function testAfterControllerReturnResponseWhenUnhandled(): void { + $response = $this->middleware->afterController($this->controller, '', $this->response); $this->assertEquals($this->response, $response); } - public function testBeforeOutputReturnOutputhenUnhandled() { - $output = $this->middleware->beforeOutput($this->controller, null, 'test'); + public function testBeforeOutputReturnOutputhenUnhandled(): void { + $output = $this->middleware->beforeOutput($this->controller, '', 'test'); $this->assertEquals('test', $output); } diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php index f33f88eb214..69f78f435cf 100644 --- a/tests/lib/Encryption/DecryptAllTest.php +++ b/tests/lib/Encryption/DecryptAllTest.php @@ -77,12 +77,15 @@ class DecryptAllTest extends TestCase { ->disableOriginalConstructor()->getMock(); $this->outputInterface = $this->getMockBuilder(OutputInterface::class) ->disableOriginalConstructor()->getMock(); + $this->outputInterface->expects($this->any())->method('isDecorated') + ->willReturn(false); $this->userInterface = $this->getMockBuilder(UserInterface::class) ->disableOriginalConstructor()->getMock(); /* We need format method to return a string */ $outputFormatter = $this->createMock(OutputFormatterInterface::class); $outputFormatter->method('format')->willReturn('foo'); + $outputFormatter->method('isDecorated')->willReturn(false); $this->outputInterface->expects($this->any())->method('getFormatter') ->willReturn($outputFormatter); @@ -304,6 +307,7 @@ class DecryptAllTest extends TestCase { /* We need format method to return a string */ $outputFormatter = $this->createMock(OutputFormatterInterface::class); + $outputFormatter->method('isDecorated')->willReturn(false); $outputFormatter->method('format')->willReturn('foo'); $output = $this->createMock(OutputInterface::class); diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index 3305f9ac170..218e2531727 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -185,7 +185,7 @@ class FileTest extends NodeTest { $root = new \OC\Files\Node\Root( $this->manager, - new $this->view, + $this->view, $this->user, $this->userMountCache, $this->logger, @@ -277,7 +277,7 @@ class FileTest extends NodeTest { $root = new \OC\Files\Node\Root( $this->manager, - new $this->view, + $this->view, $this->user, $this->userMountCache, $this->logger, diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 8a604af3846..d745a05ba17 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -23,7 +23,6 @@ use OC\Files\Search\SearchOrder; 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; @@ -40,6 +39,9 @@ use OCP\Files\Storage; */ 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 { @@ -64,25 +66,26 @@ class FolderTest extends NodeTest { /** * @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)); + $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]); @@ -95,10 +98,7 @@ class FolderTest extends NodeTest { 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(); @@ -117,10 +117,7 @@ class FolderTest extends NodeTest { 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(); @@ -140,10 +137,7 @@ class FolderTest extends NodeTest { 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(); @@ -161,10 +155,7 @@ class FolderTest extends NodeTest { 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(); @@ -188,10 +179,7 @@ class FolderTest extends NodeTest { 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(); @@ -218,10 +206,7 @@ class FolderTest extends NodeTest { $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(); @@ -238,10 +223,7 @@ class FolderTest extends NodeTest { 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(); @@ -268,10 +250,7 @@ class FolderTest extends NodeTest { $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(); @@ -288,10 +267,7 @@ class FolderTest extends NodeTest { 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(); @@ -308,10 +284,7 @@ class FolderTest extends NodeTest { 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(); @@ -351,10 +324,7 @@ class FolderTest extends NodeTest { 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]) @@ -395,10 +365,7 @@ class FolderTest extends NodeTest { 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(); @@ -438,10 +405,7 @@ class FolderTest extends NodeTest { 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(); @@ -498,21 +462,18 @@ class FolderTest extends NodeTest { } 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]) @@ -559,10 +520,7 @@ class FolderTest extends NodeTest { 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]) @@ -605,10 +563,7 @@ class FolderTest extends NodeTest { 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]) @@ -650,10 +605,7 @@ class FolderTest extends NodeTest { 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]) @@ -715,10 +667,7 @@ class FolderTest extends NodeTest { 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]) @@ -742,10 +691,7 @@ class FolderTest extends NodeTest { 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']) @@ -810,10 +756,7 @@ class FolderTest extends NodeTest { 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']) @@ -877,10 +820,7 @@ class FolderTest extends NodeTest { 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']) @@ -966,10 +906,7 @@ class FolderTest extends NodeTest { } $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(); diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index 8c0d4cdb293..b63d287a191 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -54,6 +54,9 @@ abstract class NodeTest extends \Test\TestCase { $this->view = $this->getMockBuilder(View::class) ->disableOriginalConstructor() ->getMock(); + $this->view->expects($this->any()) + ->method('getRoot') + ->willReturn(''); $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); @@ -66,6 +69,17 @@ abstract class NodeTest extends \Test\TestCase { } /** + * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view + */ + protected function getRootViewMock() { + $view = $this->createMock(View::class); + $view->expects($this->any()) + ->method('getRoot') + ->willReturn(''); + return $view; + } + + /** * @param IRootFolder $root * @param View $view * @param string $path diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index 5d8e2a4ac62..aab658c3c36 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -52,6 +52,17 @@ class RootTest extends \Test\TestCase { $this->eventDispatcher = $this->createMock(IEventDispatcher::class); } + /** + * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view + */ + protected function getRootViewMock() { + $view = $this->createMock(View::class); + $view->expects($this->any()) + ->method('getRoot') + ->willReturn(''); + return $view; + } + protected function getFileInfo($data) { return new FileInfo('', null, '', $data, null); } @@ -63,12 +74,7 @@ class RootTest extends \Test\TestCase { $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor() ->getMock(); - /** - * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view - */ - $view = $this->getMockBuilder(View::class) - ->disableOriginalConstructor() - ->getMock(); + $view = $this->getRootViewMock(); $root = new \OC\Files\Node\Root( $this->manager, $view, @@ -100,12 +106,7 @@ class RootTest extends \Test\TestCase { $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor() ->getMock(); - /** - * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view - */ - $view = $this->getMockBuilder(View::class) - ->disableOriginalConstructor() - ->getMock(); + $view = $this->getRootViewMock(); $root = new \OC\Files\Node\Root( $this->manager, $view, @@ -129,12 +130,7 @@ class RootTest extends \Test\TestCase { public function testGetInvalidPath() { $this->expectException(\OCP\Files\NotPermittedException::class); - /** - * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view - */ - $view = $this->getMockBuilder(View::class) - ->disableOriginalConstructor() - ->getMock(); + $view = $this->getRootViewMock(); $root = new \OC\Files\Node\Root( $this->manager, $view, @@ -152,12 +148,7 @@ class RootTest extends \Test\TestCase { public function testGetNoStorages() { $this->expectException(\OCP\Files\NotFoundException::class); - /** - * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view - */ - $view = $this->getMockBuilder(View::class) - ->disableOriginalConstructor() - ->getMock(); + $view = $this->getRootViewMock(); $root = new \OC\Files\Node\Root( $this->manager, $view, @@ -174,7 +165,7 @@ class RootTest extends \Test\TestCase { public function testGetUserFolder() { $root = new \OC\Files\Node\Root( $this->manager, - $this->createMock(View::class), + $this->getRootViewMock(), $this->user, $this->userMountCache, $this->logger, @@ -215,7 +206,7 @@ class RootTest extends \Test\TestCase { $root = new \OC\Files\Node\Root( $this->createMock(Manager::class), - $this->createMock(View::class), + $this->getRootViewMock(), null, $this->userMountCache, $this->logger, diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 1f6f43dce1e..37fc3935139 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -105,15 +105,12 @@ class GeneratorTest extends \Test\TestCase { $maxPreview->method('getMimeType') ->willReturn('image/png'); - $previewFolder->method('getDirectoryListing') - ->willReturn([$maxPreview]); - $previewFile = $this->createMock(ISimpleFile::class); $previewFile->method('getSize')->willReturn(1000); + $previewFile->method('getName')->willReturn('256-256.png'); - $previewFolder->method('getFile') - ->with($this->equalTo('256-256.png')) - ->willReturn($previewFile); + $previewFolder->method('getDirectoryListing') + ->willReturn([$maxPreview, $previewFile]); $this->legacyEventDispatcher->expects($this->once()) ->method('dispatch') @@ -344,14 +341,12 @@ class GeneratorTest extends \Test\TestCase { $maxPreview->method('getMimeType') ->willReturn('image/png'); - $previewFolder->method('getDirectoryListing') - ->willReturn([$maxPreview]); - $preview = $this->createMock(ISimpleFile::class); $preview->method('getSize')->willReturn(1000); - $previewFolder->method('getFile') - ->with($this->equalTo('1024-512-crop.png')) - ->willReturn($preview); + $preview->method('getName')->willReturn('1024-512-crop.png'); + + $previewFolder->method('getDirectoryListing') + ->willReturn([$maxPreview, $preview]); $this->previewManager->expects($this->never()) ->method('isMimeSupported'); diff --git a/tests/lib/Updater/ChangesCheckTest.php b/tests/lib/Updater/ChangesCheckTest.php index 02da6d08401..e96406622f4 100644 --- a/tests/lib/Updater/ChangesCheckTest.php +++ b/tests/lib/Updater/ChangesCheckTest.php @@ -28,7 +28,7 @@ namespace Test\Updater; use OC\Updater\ChangesCheck; use OC\Updater\ChangesMapper; -use OC\Updater\ChangesResult; +use OC\Updater\Changes; use OCP\AppFramework\Db\DoesNotExistException; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; @@ -88,7 +88,7 @@ class ChangesCheckTest extends TestCase { public function testCacheResultInsert() { $version = '13.0.4'; - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->exactly(2)) ->method('__call') ->withConsecutive(['getVersion'], ['setVersion', [$version]]) @@ -104,7 +104,7 @@ class ChangesCheckTest extends TestCase { public function testCacheResultUpdate() { $version = '13.0.4'; - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->once()) ->method('__call') ->willReturn($version); @@ -306,7 +306,7 @@ class ChangesCheckTest extends TestCase { */ public function testQueryChangesServer(string $etag) { $uri = 'https://changes.nextcloud.server/?13.0.5'; - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->any()) ->method('__call') ->willReturn($etag); @@ -370,7 +370,7 @@ class ChangesCheckTest extends TestCase { $this->expectException(DoesNotExistException::class); $mocker->willThrowException(new DoesNotExistException('Changes info is not present')); } else { - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->once()) ->method('__call') ->with('getData') @@ -386,7 +386,7 @@ class ChangesCheckTest extends TestCase { } public function testGetChangesForVersionEmptyData() { - $entry = $this->createMock(ChangesResult::class); + $entry = $this->createMock(Changes::class); $entry->expects($this->once()) ->method('__call') ->with('getData') |