SetDefaultModuleTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\SetDefaultModule;
  23. use OCP\Encryption\IManager;
  24. use Symfony\Component\Console\Input\InputInterface;
  25. use Symfony\Component\Console\Output\OutputInterface;
  26. use Test\TestCase;
  27. class SetDefaultModuleTest extends TestCase {
  28. /** @var \PHPUnit_Framework_MockObject_MockObject */
  29. protected $manager;
  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. $manager = $this->manager = $this->getMockBuilder(IManager::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
  42. $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
  43. /** @var \OCP\Encryption\IManager $manager */
  44. $this->command = new SetDefaultModule($manager);
  45. }
  46. public function dataSetDefaultModule() {
  47. return [
  48. ['ID0', 'ID0', null, null, 'already'],
  49. ['ID0', 'ID1', 'ID1', true, 'info'],
  50. ['ID0', 'ID1', 'ID1', false, 'error'],
  51. ];
  52. }
  53. /**
  54. * @dataProvider dataSetDefaultModule
  55. *
  56. * @param string $oldModule
  57. * @param string $newModule
  58. * @param string $updateModule
  59. * @param bool $updateSuccess
  60. * @param string $expectedString
  61. */
  62. public function testSetDefaultModule($oldModule, $newModule, $updateModule, $updateSuccess, $expectedString) {
  63. $this->consoleInput->expects($this->once())
  64. ->method('getArgument')
  65. ->with('module')
  66. ->willReturn($newModule);
  67. $this->manager->expects($this->once())
  68. ->method('getDefaultEncryptionModuleId')
  69. ->willReturn($oldModule);
  70. if ($updateModule) {
  71. $this->manager->expects($this->once())
  72. ->method('setDefaultEncryptionModule')
  73. ->with($updateModule)
  74. ->willReturn($updateSuccess);
  75. }
  76. $this->consoleOutput->expects($this->once())
  77. ->method('writeln')
  78. ->with($this->stringContains($expectedString));
  79. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  80. }
  81. }