disabletest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Test\TestCase;
  24. class DisableTest extends TestCase {
  25. /** @var \PHPUnit_Framework_MockObject_MockObject */
  26. protected $config;
  27. /** @var \PHPUnit_Framework_MockObject_MockObject */
  28. protected $consoleInput;
  29. /** @var \PHPUnit_Framework_MockObject_MockObject */
  30. protected $consoleOutput;
  31. /** @var \Symfony\Component\Console\Command\Command */
  32. protected $command;
  33. protected function setUp() {
  34. parent::setUp();
  35. $config = $this->config = $this->getMockBuilder('OCP\IConfig')
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface');
  39. $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
  40. /** @var \OCP\IConfig $config */
  41. $this->command = new Disable($config);
  42. }
  43. public function dataDisable() {
  44. return [
  45. ['yes', true, 'Encryption disabled'],
  46. ['no', false, 'Encryption is already disabled'],
  47. ];
  48. }
  49. /**
  50. * @dataProvider dataDisable
  51. *
  52. * @param string $oldStatus
  53. * @param bool $isUpdating
  54. * @param string $expectedString
  55. */
  56. public function testDisable($oldStatus, $isUpdating, $expectedString) {
  57. $this->config->expects($this->once())
  58. ->method('getAppValue')
  59. ->with('core', 'encryption_enabled', $this->anything())
  60. ->willReturn($oldStatus);
  61. $this->consoleOutput->expects($this->once())
  62. ->method('writeln')
  63. ->with($this->stringContains($expectedString));
  64. if ($isUpdating) {
  65. $this->config->expects($this->once())
  66. ->method('setAppValue')
  67. ->with('core', 'encryption_enabled', 'no');
  68. }
  69. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  70. }
  71. }