diff options
Diffstat (limited to 'tests/lib/Settings')
-rw-r--r-- | tests/lib/Settings/DeclarativeManagerTest.php | 42 | ||||
-rw-r--r-- | tests/lib/Settings/ManagerTest.php | 27 | ||||
-rw-r--r-- | tests/lib/Settings/SectionTest.php | 1 |
3 files changed, 52 insertions, 18 deletions
diff --git a/tests/lib/Settings/DeclarativeManagerTest.php b/tests/lib/Settings/DeclarativeManagerTest.php index 522264acd8c..59411e1f825 100644 --- a/tests/lib/Settings/DeclarativeManagerTest.php +++ b/tests/lib/Settings/DeclarativeManagerTest.php @@ -18,6 +18,7 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\IGroupManager; use OCP\IUser; +use OCP\Security\ICrypto; use OCP\Settings\DeclarativeSettingsTypes; use OCP\Settings\Events\DeclarativeSettingsSetValueEvent; use OCP\Settings\IDeclarativeManager; @@ -50,6 +51,9 @@ class DeclarativeManagerTest extends TestCase { /** @var LoggerInterface|MockObject */ private $logger; + /** @var ICrypto|MockObject */ + private $crypto; + /** @var IUser|MockObject */ private $user; @@ -215,6 +219,36 @@ class DeclarativeManagerTest extends TestCase { ], ], ], + [ + 'id' => 'test_sensitive_field', + 'title' => 'Sensitive text field', + 'description' => 'Set some secure value setting that is stored encrypted', + 'type' => DeclarativeSettingsTypes::TEXT, + 'label' => 'Sensitive field', + 'placeholder' => 'Set secure value', + 'default' => '', + 'sensitive' => true, // only for TEXT, PASSWORD types + ], + [ + 'id' => 'test_sensitive_field_2', + 'title' => 'Sensitive password field', + 'description' => 'Set some password setting that is stored encrypted', + 'type' => DeclarativeSettingsTypes::PASSWORD, + 'label' => 'Sensitive field', + 'placeholder' => 'Set secure value', + 'default' => '', + 'sensitive' => true, // only for TEXT, PASSWORD types + ], + [ + 'id' => 'test_non_sensitive_field', + 'title' => 'Password field', + 'description' => 'Set some password setting', + 'type' => DeclarativeSettingsTypes::PASSWORD, + 'label' => 'Password field', + 'placeholder' => 'Set secure value', + 'default' => '', + 'sensitive' => false, + ], ], ]; @@ -229,6 +263,7 @@ class DeclarativeManagerTest extends TestCase { $this->config = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); $this->logger = $this->createMock(LoggerInterface::class); + $this->crypto = $this->createMock(ICrypto::class); $this->declarativeManager = new DeclarativeManager( $this->eventDispatcher, @@ -236,7 +271,8 @@ class DeclarativeManagerTest extends TestCase { $this->coordinator, $this->config, $this->appConfig, - $this->logger + $this->logger, + $this->crypto, ); $this->user = $this->createMock(IUser::class); @@ -309,9 +345,7 @@ class DeclarativeManagerTest extends TestCase { $this->assertFalse(isset($formIds[$app]) && in_array($schemaDuplicateFields['id'], $formIds[$app])); } - /** - * @dataProvider dataValidateSchema - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateSchema')] public function testValidateSchema(bool $expected, bool $expectException, string $app, array $schema): void { if ($expectException) { $this->expectException(\Exception::class); diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 90c195e6bd0..91277cc7f1e 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -8,6 +9,7 @@ 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; @@ -15,6 +17,7 @@ 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; @@ -65,11 +68,11 @@ class ManagerTest extends TestCase { } public function testGetAdminSections(): void { - $this->manager->registerSection('admin', \OCA\WorkflowEngine\Settings\Section::class); + $this->manager->registerSection('admin', Section::class); - $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $section = Server::get(Section::class); $this->container->method('get') - ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->with(Section::class) ->willReturn($section); $this->assertEquals([ @@ -78,11 +81,11 @@ class ManagerTest extends TestCase { } public function testGetPersonalSections(): void { - $this->manager->registerSection('personal', \OCA\WorkflowEngine\Settings\Section::class); + $this->manager->registerSection('personal', Section::class); - $section = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $section = Server::get(Section::class); $this->container->method('get') - ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->with(Section::class) ->willReturn($section); $this->assertEquals([ @@ -178,10 +181,6 @@ class ManagerTest extends TestCase { $this->container->expects($this->exactly(2)) ->method('get') - ->withConsecutive( - ['section1'], - ['section2'] - ) ->willReturnMap([ ['section1', $section], ['section2', $section2], @@ -206,13 +205,13 @@ 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 = \OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class); + $section = Server::get(Section::class); $this->container->method('get') - ->with(\OCA\WorkflowEngine\Settings\Section::class) + ->with(Section::class) ->willReturn($section); $this->assertEquals([ diff --git a/tests/lib/Settings/SectionTest.php b/tests/lib/Settings/SectionTest.php index dd69f8ae110..ecd654ba748 100644 --- a/tests/lib/Settings/SectionTest.php +++ b/tests/lib/Settings/SectionTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later |