diff options
Diffstat (limited to 'tests/lib/Settings/ManagerTest.php')
-rw-r--r-- | tests/lib/Settings/ManagerTest.php | 108 |
1 files changed, 55 insertions, 53 deletions
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 96711e75cab..91277cc7f1e 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -1,30 +1,15 @@ <?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; @@ -32,28 +17,31 @@ use OCP\IL10N; 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 LoggerInterface|\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 IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var AuthorizedGroupMapper|MockObject */ + private $mapper; + /** @var IGroupManager|MockObject */ private $groupManager; - /** @var ISubAdmin|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ISubAdmin|MockObject */ private $subAdmin; protected function setUp(): void { @@ -79,27 +67,37 @@ class ManagerTest extends TestCase { ); } - 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') @@ -113,7 +111,7 @@ 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); @@ -131,7 +129,7 @@ class ManagerTest extends TestCase { ], $settings); } - public function testGetAdminSettingsAsSubAdmin() { + public function testGetAdminSettingsAsSubAdmin(): void { $section = $this->createMock(ISettings::class); $section->method('getPriority') ->willReturn(13); @@ -147,7 +145,7 @@ class ManagerTest extends TestCase { $this->assertEquals([], $settings); } - public function testGetSubAdminSettingsAsSubAdmin() { + public function testGetSubAdminSettingsAsSubAdmin(): void { $section = $this->createMock(ISubAdminSettings::class); $section->method('getPriority') ->willReturn(13); @@ -166,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); @@ -181,14 +179,12 @@ class ManagerTest extends TestCase { $this->manager->registerSetting('personal', 'section1'); $this->manager->registerSetting('personal', 'section2'); - $this->container->expects($this->at(0)) - ->method('get') - ->with('section1') - ->willReturn($section); - $this->container->expects($this->at(1)) + $this->container->expects($this->exactly(2)) ->method('get') - ->with('section2') - ->willReturn($section2); + ->willReturnMap([ + ['section1', $section], + ['section2', $section2], + ]); $settings = $this->manager->getPersonalSettings('security'); @@ -198,7 +194,7 @@ class ManagerTest extends TestCase { ], $settings); } - public function testSameSectionAsPersonalAndAdmin() { + public function testSameSectionAsPersonalAndAdmin(): void { $this->l10nFactory ->expects($this->once()) ->method('get') @@ -209,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()); } } |