DisableTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Tests\Core\Command\Encryption;
  22. use OC\Core\Command\Encryption\Disable;
  23. use OCP\IConfig;
  24. use Symfony\Component\Console\Input\InputInterface;
  25. use Symfony\Component\Console\Output\OutputInterface;
  26. use Test\TestCase;
  27. class DisableTest extends TestCase {
  28. /** @var \PHPUnit\Framework\MockObject\MockObject */
  29. protected $config;
  30. /** @var \PHPUnit\Framework\MockObject\MockObject */
  31. protected $consoleInput;
  32. /** @var \PHPUnit\Framework\MockObject\MockObject */
  33. protected $consoleOutput;
  34. /** @var \Symfony\Component\Console\Command\Command */
  35. protected $command;
  36. protected function setUp(): void {
  37. parent::setUp();
  38. $config = $this->config = $this->getMockBuilder(IConfig::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
  42. $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
  43. /** @var \OCP\IConfig $config */
  44. $this->command = new Disable($config);
  45. }
  46. public function dataDisable() {
  47. return [
  48. ['yes', true, 'Encryption disabled'],
  49. ['no', false, 'Encryption is already disabled'],
  50. ];
  51. }
  52. /**
  53. * @dataProvider dataDisable
  54. *
  55. * @param string $oldStatus
  56. * @param bool $isUpdating
  57. * @param string $expectedString
  58. */
  59. public function testDisable($oldStatus, $isUpdating, $expectedString) {
  60. $this->config->expects($this->once())
  61. ->method('getAppValue')
  62. ->with('core', 'encryption_enabled', $this->anything())
  63. ->willReturn($oldStatus);
  64. $this->consoleOutput->expects($this->once())
  65. ->method('writeln')
  66. ->with($this->stringContains($expectedString));
  67. if ($isUpdating) {
  68. $this->config->expects($this->once())
  69. ->method('setAppValue')
  70. ->with('core', 'encryption_enabled', 'no');
  71. }
  72. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  73. }
  74. }