diff --git a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php index 129ba37098063..e1fce2ad831dc 100644 --- a/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php +++ b/apps/updatenotification/tests/ResetTokenBackgroundJobTest.php @@ -65,13 +65,11 @@ public function testRunWithNotExpiredToken() { public function testRunWithExpiredToken() { $this->timeFactory - ->expects($this->at(0)) ->method('getTime') - ->willReturn(1455131633); - $this->timeFactory - ->expects($this->at(1)) - ->method('getTime') - ->willReturn(1455045234); + ->willReturnOnConsecutiveCalls( + 1455131633, + 1455045234 + ); $this->config ->expects($this->once()) ->method('getAppValue') diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php index 852504fb45aa4..bbaa56fa18dcf 100644 --- a/apps/updatenotification/tests/Settings/AdminTest.php +++ b/apps/updatenotification/tests/Settings/AdminTest.php @@ -29,6 +29,7 @@ */ namespace OCA\UpdateNotification\Tests\Settings; +use OC\User\Backend; use OCA\UpdateNotification\Settings\Admin; use OCA\UpdateNotification\UpdateChecker; use OCP\AppFramework\Http\TemplateResponse; @@ -36,13 +37,18 @@ use OCP\IDateTimeFormatter; use OCP\IGroup; use OCP\IGroupManager; +use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\L10N\ILanguageIterator; use OCP\Support\Subscription\IRegistry; +use OCP\User\Backend\ICountUsersBackend; +use OCP\UserInterface; use OCP\Util; -use Test\TestCase; -use OCP\IUserManager; use Psr\Log\LoggerInterface; +use Test\TestCase; + +interface UserInterfaceAwareICountUsersBackend extends UserInterface, ICountUsersBackend { +} class AdminTest extends TestCase { /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */ @@ -77,11 +83,11 @@ protected function setUp(): void { $this->logger = $this->createMock(LoggerInterface::class); $this->admin = new Admin( - $this->config, - $this->updateChecker, - $this->groupManager, - $this->dateTimeFormatter, - $this->l10nFactory, + $this->config, + $this->updateChecker, + $this->groupManager, + $this->dateTimeFormatter, + $this->l10nFactory, $this->subscriptionRegistry, $this->userManager, $this->logger @@ -89,9 +95,9 @@ protected function setUp(): void { } public function testGetFormWithUpdate() { - $backend1 = $this->createMock(UserInterface::class); - $backend2 = $this->createMock(UserInterface::class); - $backend3 = $this->createMock(UserInterface::class); + $backend1 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); + $backend2 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); + $backend3 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); $backend1 ->expects($this->once()) ->method('implementsActions') @@ -213,9 +219,9 @@ public function testGetFormWithUpdate() { } public function testGetFormWithUpdateAndChangedUpdateServer() { - $backend1 = $this->createMock(UserInterface::class); - $backend2 = $this->createMock(UserInterface::class); - $backend3 = $this->createMock(UserInterface::class); + $backend1 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); + $backend2 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); + $backend3 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); $backend1 ->expects($this->once()) ->method('implementsActions') @@ -337,9 +343,9 @@ public function testGetFormWithUpdateAndChangedUpdateServer() { } public function testGetFormWithUpdateAndCustomersUpdateServer() { - $backend1 = $this->createMock(UserInterface::class); - $backend2 = $this->createMock(UserInterface::class); - $backend3 = $this->createMock(UserInterface::class); + $backend1 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); + $backend2 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); + $backend3 = $this->createMock(UserInterfaceAwareICountUsersBackend::class); $backend1 ->expects($this->once()) ->method('implementsActions') diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index 174af2e8b8995..541a4ed24f532 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -37,6 +37,7 @@ use OCP\Encryption\IEncryptionModule; use OCP\IConfig; use OCP\IUser; +use OCP\App\IAppManager; class Util { public const HEADER_START = 'HBEGIN'; @@ -299,7 +300,8 @@ public function getUserWithAccessToMountPoint($users, $groups) { * @return boolean */ public function isSystemWideMountPoint($path, $uid) { - if (\OCP\App::isEnabled("files_external")) { + $appManager = \OC::$server->get(IAppManager::class); + if ($appManager->isEnabledForUser('files_external', null)) { /** @var GlobalStoragesService $storageService */ $storageService = \OC::$server->get(GlobalStoragesService::class); $storages = $storageService->getAllStorages(); diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php index 02155be11ddab..ab6101b7027a9 100644 --- a/tests/lib/Encryption/UtilTest.php +++ b/tests/lib/Encryption/UtilTest.php @@ -4,8 +4,7 @@ use OC\Encryption\Util; use OC\Files\View; -use OCA\Files_External\Lib\StorageConfig; -use OCA\Files_External\Service\GlobalStoragesService; +use OCP\App\IAppManager; use OCP\Encryption\IEncryptionModule; use OCP\IConfig; use Test\TestCase; @@ -40,11 +39,11 @@ protected function setUp(): void { ->disableOriginalConstructor() ->getMock(); - $this->userManager = $this->getMockBuilder('OC\User\Manager') + $this->userManager = $this->getMockBuilder(\OC\User\Manager::class) ->disableOriginalConstructor() ->getMock(); - $this->groupManager = $this->getMockBuilder('OC\Group\Manager') + $this->groupManager = $this->getMockBuilder(\OC\Group\Manager::class) ->disableOriginalConstructor() ->getMock(); @@ -207,6 +206,15 @@ public function dataTestIsSystemWideMountPoint() { * @dataProvider dataTestIsSystemWideMountPoint */ public function testIsSystemWideMountPoint($expectedResult, $expectationText, $applicableUsers, $applicableGroups, $mountPointName = '/mp') { + $appManager = $this->createMock(IAppManager::class); + $appManager + ->expects($this->once()) + ->method('isEnabledForUser') + ->with('files_external') + ->willReturn(true); + + $this->overwriteService(IAppManager::class, $appManager); + $this->groupManager->method('isInGroup') ->will($this->returnValueMap([ ['user1', 'group1', true], // user is only in group1 @@ -215,17 +223,28 @@ public function testIsSystemWideMountPoint($expectedResult, $expectationText, $a $storages = []; - $storageConfig = $this->createMock(StorageConfig::class); + // StorageConfig + $storageConfig = $this->getMockBuilder('OCA\\Files_External\\Lib\\StorageConfig') + ->setMethods([ + 'getMountPoint', + 'getApplicableUsers', + 'getApplicableGroups', + ]) + ->getMock(); $storageConfig->method('getMountPoint')->willReturn($mountPointName); $storageConfig->method('getApplicableUsers')->willReturn($applicableUsers); $storageConfig->method('getApplicableGroups')->willReturn($applicableGroups); $storages[] = $storageConfig; - $storagesServiceMock = $this->createMock(GlobalStoragesService::class); + $storagesServiceMock = $this->getMockBuilder('OCA\\Files_External\\Service\\GlobalStoragesService') + ->setMethods([ + 'getAllStorages', + ]) + ->getMock(); $storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages') ->willReturn($storages); - $this->overwriteService(GlobalStoragesService::class, $storagesServiceMock); + $this->overwriteService('OCA\\Files_External\\Service\\GlobalStoragesService', $storagesServiceMock); $this->assertEquals($expectedResult, $this->util->isSystemWideMountPoint('/files/mp', 'user1'), 'Test case: ' . $expectationText); } diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 4cda92b6e838b..1419b4eb0370c 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -105,11 +105,14 @@ public function testGet() { ->method('getUser') ->willReturn($this->user); + $expected = $this->createMock(Node::class); $root->method('get') - ->with('/bar/foo/asd'); + ->with('/bar/foo/asd') + ->willReturn($expected); $node = new Folder($root, $view, '/bar/foo'); - $node->get('asd'); + $return = $node->get('asd'); + self::assertEquals($expected, $return); } public function testNodeExists() { diff --git a/tests/phpunit-autotest.xml b/tests/phpunit-autotest.xml index d2d45b50db7d7..95664ddae3bc1 100644 --- a/tests/phpunit-autotest.xml +++ b/tests/phpunit-autotest.xml @@ -2,6 +2,8 @@