diff options
Diffstat (limited to 'tests/lib/Settings/ManagerTest.php')
-rw-r--r-- | tests/lib/Settings/ManagerTest.php | 131 |
1 files changed, 73 insertions, 58 deletions
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 3d967b2ed21..91277cc7f1e 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -1,92 +1,103 @@ <?php + /** - * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> - * - * @author Lukas Reschke <lukas@statuscode.ch> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Settings\Tests\AppInfo; +namespace OC\Settings\Tests\AppInfo; +use OC\Settings\AuthorizedGroupMapper; use OC\Settings\Manager; +use OCA\WorkflowEngine\Settings\Section; +use OCP\Group\ISubAdmin; use OCP\IDBConnection; +use OCP\IGroupManager; use OCP\IL10N; -use OCP\ILogger; use OCP\IServerContainer; use OCP\IURLGenerator; use OCP\L10N\IFactory; +use OCP\Server; use OCP\Settings\ISettings; use OCP\Settings\ISubAdminSettings; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class ManagerTest extends TestCase { - - /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Manager|MockObject */ private $manager; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; - /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IDBConnection|MockObject */ private $l10n; - /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IFactory|MockObject */ private $l10nFactory; - /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IURLGenerator|MockObject */ private $url; - /** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IServerContainer|MockObject */ private $container; + /** @var AuthorizedGroupMapper|MockObject */ + private $mapper; + /** @var IGroupManager|MockObject */ + private $groupManager; + /** @var ISubAdmin|MockObject */ + private $subAdmin; protected function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->l10n = $this->createMock(IL10N::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->url = $this->createMock(IURLGenerator::class); $this->container = $this->createMock(IServerContainer::class); + $this->mapper = $this->createMock(AuthorizedGroupMapper::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->subAdmin = $this->createMock(ISubAdmin::class); $this->manager = new Manager( $this->logger, $this->l10nFactory, $this->url, - $this->container + $this->container, + $this->mapper, + $this->groupManager, + $this->subAdmin, ); } - public function testGetAdminSections() { - $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); + public function testGetAdminSections(): void { + $this->manager->registerSection('admin', Section::class); + + $section = Server::get(Section::class); + $this->container->method('get') + ->with(Section::class) + ->willReturn($section); $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getAdminSections()); } - public function testGetPersonalSections() { - $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); + public function testGetPersonalSections(): void { + $this->manager->registerSection('personal', Section::class); + + $section = Server::get(Section::class); + $this->container->method('get') + ->with(Section::class) + ->willReturn($section); $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getPersonalSections()); } - public function testGetAdminSectionsEmptySection() { + public function testGetAdminSectionsEmptySection(): void { $this->assertEquals([], $this->manager->getAdminSections()); } - public function testGetPersonalSectionsEmptySection() { + public function testGetPersonalSectionsEmptySection(): void { $this->l10nFactory ->expects($this->once()) ->method('get') @@ -100,13 +111,13 @@ class ManagerTest extends TestCase { $this->assertEquals([], $this->manager->getPersonalSections()); } - public function testGetAdminSettings() { + public function testGetAdminSettings(): void { $section = $this->createMock(ISettings::class); $section->method('getPriority') ->willReturn(13); $section->method('getSection') ->willReturn('sharing'); - $this->container->method('query') + $this->container->method('get') ->with('myAdminClass') ->willReturn($section); @@ -118,13 +129,13 @@ class ManagerTest extends TestCase { ], $settings); } - public function testGetAdminSettingsAsSubAdmin() { + public function testGetAdminSettingsAsSubAdmin(): void { $section = $this->createMock(ISettings::class); $section->method('getPriority') ->willReturn(13); $section->method('getSection') ->willReturn('sharing'); - $this->container->method('query') + $this->container->method('get') ->with('myAdminClass') ->willReturn($section); @@ -134,14 +145,14 @@ class ManagerTest extends TestCase { $this->assertEquals([], $settings); } - public function testGetSubAdminSettingsAsSubAdmin() { + public function testGetSubAdminSettingsAsSubAdmin(): void { $section = $this->createMock(ISubAdminSettings::class); $section->method('getPriority') ->willReturn(13); $section->method('getSection') ->willReturn('sharing'); $this->container->expects($this->once()) - ->method('query') + ->method('get') ->with('mySubAdminClass') ->willReturn($section); @@ -153,7 +164,7 @@ class ManagerTest extends TestCase { ], $settings); } - public function testGetPersonalSettings() { + public function testGetPersonalSettings(): void { $section = $this->createMock(ISettings::class); $section->method('getPriority') ->willReturn(16); @@ -168,14 +179,12 @@ class ManagerTest extends TestCase { $this->manager->registerSetting('personal', 'section1'); $this->manager->registerSetting('personal', 'section2'); - $this->container->expects($this->at(0)) - ->method('query') - ->with('section1') - ->willReturn($section); - $this->container->expects($this->at(1)) - ->method('query') - ->with('section2') - ->willReturn($section2); + $this->container->expects($this->exactly(2)) + ->method('get') + ->willReturnMap([ + ['section1', $section], + ['section2', $section2], + ]); $settings = $this->manager->getPersonalSettings('security'); @@ -185,7 +194,7 @@ class ManagerTest extends TestCase { ], $settings); } - public function testSameSectionAsPersonalAndAdmin() { + public function testSameSectionAsPersonalAndAdmin(): void { $this->l10nFactory ->expects($this->once()) ->method('get') @@ -196,15 +205,21 @@ class ManagerTest extends TestCase { ->method('t') ->willReturnArgument(0); - $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); - $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); + $this->manager->registerSection('personal', Section::class); + $this->manager->registerSection('admin', Section::class); + + + $section = Server::get(Section::class); + $this->container->method('get') + ->with(Section::class) + ->willReturn($section); $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getPersonalSections()); $this->assertEquals([ - 55 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], + 55 => [$section], ], $this->manager->getAdminSections()); } } |