DisableTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Tests\Core\Command\Encryption;
  8. use OC\Core\Command\Encryption\Disable;
  9. use OCP\IConfig;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. use Test\TestCase;
  13. class DisableTest extends TestCase {
  14. /** @var \PHPUnit\Framework\MockObject\MockObject */
  15. protected $config;
  16. /** @var \PHPUnit\Framework\MockObject\MockObject */
  17. protected $consoleInput;
  18. /** @var \PHPUnit\Framework\MockObject\MockObject */
  19. protected $consoleOutput;
  20. /** @var \Symfony\Component\Console\Command\Command */
  21. protected $command;
  22. protected function setUp(): void {
  23. parent::setUp();
  24. $config = $this->config = $this->getMockBuilder(IConfig::class)
  25. ->disableOriginalConstructor()
  26. ->getMock();
  27. $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
  28. $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
  29. /** @var \OCP\IConfig $config */
  30. $this->command = new Disable($config);
  31. }
  32. public function dataDisable() {
  33. return [
  34. ['yes', true, 'Encryption disabled'],
  35. ['no', false, 'Encryption is already disabled'],
  36. ];
  37. }
  38. /**
  39. * @dataProvider dataDisable
  40. *
  41. * @param string $oldStatus
  42. * @param bool $isUpdating
  43. * @param string $expectedString
  44. */
  45. public function testDisable($oldStatus, $isUpdating, $expectedString): void {
  46. $this->config->expects($this->once())
  47. ->method('getAppValue')
  48. ->with('core', 'encryption_enabled', $this->anything())
  49. ->willReturn($oldStatus);
  50. $this->consoleOutput->expects($this->once())
  51. ->method('writeln')
  52. ->with($this->stringContains($expectedString));
  53. if ($isUpdating) {
  54. $this->config->expects($this->once())
  55. ->method('setAppValue')
  56. ->with('core', 'encryption_enabled', 'no');
  57. }
  58. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  59. }
  60. }