diff options
Diffstat (limited to 'tests/lib/AppTest.php')
-rw-r--r-- | tests/lib/AppTest.php | 142 |
1 files changed, 47 insertions, 95 deletions
diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 06331700737..c56e31aadf8 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -1,20 +1,26 @@ <?php + /** - * Copyright (c) 2012 Bernhard Posselt <dev@bernhard-posselt.com> - * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test; use OC\App\AppManager; -use OC\App\InfoParser; use OC\AppConfig; +use OC\Config\ConfigManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\IAppConfig; -use OCP\IURLGenerator; +use OCP\ICacheFactory; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\Server; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -30,7 +36,7 @@ class AppTest extends \Test\TestCase { public const TEST_GROUP1 = 'group1'; public const TEST_GROUP2 = 'group2'; - public function appVersionsProvider() { + public static function appVersionsProvider(): array { return [ // exact match [ @@ -307,17 +313,15 @@ class AppTest extends \Test\TestCase { ]; } - /** - * @dataProvider appVersionsProvider - */ - public function testIsAppCompatible($ocVersion, $appInfo, $expectedResult) { + #[\PHPUnit\Framework\Attributes\DataProvider('appVersionsProvider')] + public function testIsAppCompatible($ocVersion, $appInfo, $expectedResult): void { $this->assertEquals($expectedResult, \OC_App::isAppCompatible($ocVersion, $appInfo)); } /** * Tests that the app order is correct */ - public function testGetEnabledAppsIsSorted() { + public function testGetEnabledAppsIsSorted(): void { $apps = \OC_App::getEnabledApps(); // copy array $sortedApps = $apps; @@ -331,7 +335,7 @@ class AppTest extends \Test\TestCase { /** * Providers for the app config values */ - public function appConfigValuesProvider() { + public static function appConfigValuesProvider(): array { return [ // logged in user1 [ @@ -347,6 +351,7 @@ class AppTest extends \Test\TestCase { 'federatedfilesharing', 'lookup_server_connector', 'oauth2', + 'profile', 'provisioning_api', 'settings', 'theming', @@ -370,6 +375,7 @@ class AppTest extends \Test\TestCase { 'federatedfilesharing', 'lookup_server_connector', 'oauth2', + 'profile', 'provisioning_api', 'settings', 'theming', @@ -394,6 +400,7 @@ class AppTest extends \Test\TestCase { 'federatedfilesharing', 'lookup_server_connector', 'oauth2', + 'profile', 'provisioning_api', 'settings', 'theming', @@ -418,6 +425,7 @@ class AppTest extends \Test\TestCase { 'federatedfilesharing', 'lookup_server_connector', 'oauth2', + 'profile', 'provisioning_api', 'settings', 'theming', @@ -442,6 +450,7 @@ class AppTest extends \Test\TestCase { 'federatedfilesharing', 'lookup_server_connector', 'oauth2', + 'profile', 'provisioning_api', 'settings', 'theming', @@ -456,15 +465,14 @@ class AppTest extends \Test\TestCase { /** * Test enabled apps - * - * @dataProvider appConfigValuesProvider */ - public function testEnabledApps($user, $expectedApps, $forceAll) { - $userManager = \OC::$server->getUserManager(); - $groupManager = \OC::$server->getGroupManager(); - $user1 = $userManager->createUser(self::TEST_USER1, self::TEST_USER1); - $user2 = $userManager->createUser(self::TEST_USER2, self::TEST_USER2); - $user3 = $userManager->createUser(self::TEST_USER3, self::TEST_USER3); + #[\PHPUnit\Framework\Attributes\DataProvider('appConfigValuesProvider')] + public function testEnabledApps($user, $expectedApps, $forceAll): void { + $userManager = Server::get(IUserManager::class); + $groupManager = Server::get(IGroupManager::class); + $user1 = $userManager->createUser(self::TEST_USER1, 'NotAnEasyPassword123456+'); + $user2 = $userManager->createUser(self::TEST_USER2, 'NotAnEasyPassword123456_'); + $user3 = $userManager->createUser(self::TEST_USER3, 'NotAnEasyPassword123456?'); $group1 = $groupManager->createGroup(self::TEST_GROUP1); $group1->addUser($user1); @@ -476,7 +484,7 @@ class AppTest extends \Test\TestCase { \OC_User::setUserId($user); $this->setupAppConfigMock()->expects($this->once()) - ->method('getValues') + ->method('searchValues') ->willReturn( [ 'app3' => 'yes', @@ -486,7 +494,6 @@ class AppTest extends \Test\TestCase { 'appforgroup2' => '["group2"]', 'appforgroup12' => '["group2","group1"]', ] - ); $apps = \OC_App::getEnabledApps(false, $forceAll); @@ -508,28 +515,27 @@ class AppTest extends \Test\TestCase { * Test isEnabledApps() with cache, not re-reading the list of * enabled apps more than once when a user is set. */ - public function testEnabledAppsCache() { - $userManager = \OC::$server->getUserManager(); - $user1 = $userManager->createUser(self::TEST_USER1, self::TEST_USER1); + public function testEnabledAppsCache(): void { + $userManager = Server::get(IUserManager::class); + $user1 = $userManager->createUser(self::TEST_USER1, 'NotAnEasyPassword123456+'); \OC_User::setUserId(self::TEST_USER1); $this->setupAppConfigMock()->expects($this->once()) - ->method('getValues') + ->method('searchValues') ->willReturn( [ 'app3' => 'yes', 'app2' => 'no', ] - ); $apps = \OC_App::getEnabledApps(); - $this->assertEquals(['files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'provisioning_api', 'settings', 'theming', 'twofactor_backupcodes', 'viewer', 'workflowengine'], $apps); + $this->assertEquals(['files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'profile', 'provisioning_api', 'settings', 'theming', 'twofactor_backupcodes', 'viewer', 'workflowengine'], $apps); // mock should not be called again here $apps = \OC_App::getEnabledApps(); - $this->assertEquals(['files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'provisioning_api', 'settings', 'theming', 'twofactor_backupcodes', 'viewer', 'workflowengine'], $apps); + $this->assertEquals(['files', 'app3', 'cloud_federation_api', 'dav', 'federatedfilesharing', 'lookup_server_connector', 'oauth2', 'profile', 'provisioning_api', 'settings', 'theming', 'twofactor_backupcodes', 'viewer', 'workflowengine'], $apps); $this->restoreAppConfig(); \OC_User::setUserId(null); @@ -541,8 +547,8 @@ class AppTest extends \Test\TestCase { private function setupAppConfigMock() { /** @var AppConfig|MockObject */ $appConfig = $this->getMockBuilder(AppConfig::class) - ->setMethods(['getValues']) - ->setConstructorArgs([\OC::$server->getDatabaseConnection()]) + ->onlyMethods(['searchValues']) + ->setConstructorArgs([Server::get(IDBConnection::class)]) ->disableOriginalConstructor() ->getMock(); @@ -558,13 +564,14 @@ class AppTest extends \Test\TestCase { private function registerAppConfig(AppConfig $appConfig) { $this->overwriteService(AppConfig::class, $appConfig); $this->overwriteService(AppManager::class, new AppManager( - \OC::$server->getUserSession(), - \OC::$server->getConfig(), - \OC::$server->getGroupManager(), - \OC::$server->getMemCacheFactory(), - \OC::$server->get(IEventDispatcher::class), - \OC::$server->get(LoggerInterface::class), - \OC::$server->get(IURLGenerator::class), + Server::get(IUserSession::class), + Server::get(IConfig::class), + Server::get(IGroupManager::class), + Server::get(ICacheFactory::class), + Server::get(IEventDispatcher::class), + Server::get(LoggerInterface::class), + Server::get(ServerVersion::class), + Server::get(ConfigManager::class), )); } @@ -578,59 +585,4 @@ class AppTest extends \Test\TestCase { // Remove the cache of the mocked apps list with a forceRefresh \OC_App::getEnabledApps(); } - - /** - * Providers for the app data values - */ - public function appDataProvider() { - return [ - [ - ['description' => " \t This is a multiline \n test with \n \t \n \n some new lines "], - ['description' => "This is a multiline \n test with \n \t \n \n some new lines"], - ], - [ - ['description' => " \t This is a multiline \n test with \n \t some new lines "], - ['description' => "This is a multiline \n test with \n \t some new lines"], - ], - [ - ['description' => hex2bin('5065726d657420646520732761757468656e7469666965722064616e732070697769676f20646972656374656d656e74206176656320736573206964656e74696669616e7473206f776e636c6f75642073616e73206c65732072657461706572206574206d657420c3a0206a6f757273206365757820636920656e20636173206465206368616e67656d656e74206465206d6f742064652070617373652e0d0a0d')], - ['description' => "Permet de s'authentifier dans piwigo directement avec ses identifiants owncloud sans les retaper et met à jours ceux ci en cas de changement de mot de passe."], - ], - [ - ['not-a-description' => " \t This is a multiline \n test with \n \t some new lines "], - [ - 'not-a-description' => " \t This is a multiline \n test with \n \t some new lines ", - 'description' => '', - ], - ], - [ - ['description' => [100, 'bla']], - ['description' => ''], - ], - ]; - } - - /** - * Test app info parser - * - * @dataProvider appDataProvider - * @param array $data - * @param array $expected - */ - public function testParseAppInfo(array $data, array $expected) { - $this->assertSame($expected, \OC_App::parseAppInfo($data)); - } - - public function testParseAppInfoL10N() { - $parser = new InfoParser(); - $data = $parser->parse(\OC::$SERVERROOT. "/tests/data/app/description-multi-lang.xml"); - $this->assertEquals('English', \OC_App::parseAppInfo($data, 'en')['description']); - $this->assertEquals('German', \OC_App::parseAppInfo($data, 'de')['description']); - } - - public function testParseAppInfoL10NSingleLanguage() { - $parser = new InfoParser(); - $data = $parser->parse(\OC::$SERVERROOT. "/tests/data/app/description-single-lang.xml"); - $this->assertEquals('English', \OC_App::parseAppInfo($data, 'en')['description']); - } } |