DisableTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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() {
  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. }