diff options
Diffstat (limited to 'tests/Core/Command/Encryption/EnableTest.php')
-rw-r--r-- | tests/Core/Command/Encryption/EnableTest.php | 81 |
1 files changed, 30 insertions, 51 deletions
diff --git a/tests/Core/Command/Encryption/EnableTest.php b/tests/Core/Command/Encryption/EnableTest.php index c1656054ecd..32d1a7576f5 100644 --- a/tests/Core/Command/Encryption/EnableTest.php +++ b/tests/Core/Command/Encryption/EnableTest.php @@ -1,22 +1,9 @@ <?php + /** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace Tests\Core\Command\Encryption; @@ -59,7 +46,7 @@ class EnableTest extends TestCase { } - public function dataEnable() { + public static function dataEnable(): array { return [ ['no', null, [], true, 'Encryption enabled', 'No encryption module is loaded'], ['yes', null, [], false, 'Encryption is already enabled', 'No encryption module is loaded'], @@ -69,53 +56,45 @@ class EnableTest extends TestCase { ]; } - /** - * @dataProvider dataEnable - * - * @param string $oldStatus - * @param string $defaultModule - * @param array $availableModules - * @param bool $isUpdating - * @param string $expectedString - * @param string $expectedDefaultModuleString - */ - public function testEnable($oldStatus, $defaultModule, $availableModules, $isUpdating, $expectedString, $expectedDefaultModuleString) { - $invokeCount = 0; - $this->config->expects($this->at($invokeCount)) - ->method('getAppValue') - ->with('core', 'encryption_enabled', $this->anything()) - ->willReturn($oldStatus); - $invokeCount++; - + #[\PHPUnit\Framework\Attributes\DataProvider('dataEnable')] + public function testEnable(string $oldStatus, ?string $defaultModule, array $availableModules, bool $isUpdating, string $expectedString, string $expectedDefaultModuleString): void { if ($isUpdating) { $this->config->expects($this->once()) ->method('setAppValue') ->with('core', 'encryption_enabled', 'yes'); - $invokeCount++; } $this->manager->expects($this->atLeastOnce()) ->method('getEncryptionModules') ->willReturn($availableModules); - if (!empty($availableModules)) { - $this->config->expects($this->at($invokeCount)) + if (empty($availableModules)) { + $this->config->expects($this->once()) ->method('getAppValue') - ->with('core', 'default_encryption_module', $this->anything()) - ->willReturn($defaultModule); + ->willReturnMap([ + ['core', 'encryption_enabled', 'no', $oldStatus], + ]); + } else { + $this->config->expects($this->exactly(2)) + ->method('getAppValue') + ->willReturnMap([ + ['core', 'encryption_enabled', 'no', $oldStatus], + ['core', 'default_encryption_module', null, $defaultModule], + ]); } - $this->consoleOutput->expects($this->at(0)) - ->method('writeln') - ->with($this->stringContains($expectedString)); - - $this->consoleOutput->expects($this->at(1)) - ->method('writeln') - ->with(''); - - $this->consoleOutput->expects($this->at(2)) + $calls = [ + [$expectedString, 0], + ['', 0], + [$expectedDefaultModuleString, 0], + ]; + $this->consoleOutput->expects($this->exactly(3)) ->method('writeln') - ->with($this->stringContains($expectedDefaultModuleString)); + ->willReturnCallback(function (string $message, int $level) use (&$calls): void { + $call = array_shift($calls); + $this->assertStringContainsString($call[0], $message); + $this->assertSame($call[1], $level); + }); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } |