SetDefaultModuleTest.php 2.8 KB

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