setconfigtest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\Config\App;
  22. use OC\Core\Command\Config\App\SetConfig;
  23. use Test\TestCase;
  24. class SetConfigTest 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 SetConfig($config);
  42. }
  43. public function setData() {
  44. return [
  45. [
  46. 'name',
  47. 'newvalue',
  48. true,
  49. true,
  50. true,
  51. 'info',
  52. ],
  53. [
  54. 'name',
  55. 'newvalue',
  56. false,
  57. true,
  58. false,
  59. 'comment',
  60. ],
  61. ];
  62. }
  63. /**
  64. * @dataProvider setData
  65. *
  66. * @param string $configName
  67. * @param mixed $newValue
  68. * @param bool $configExists
  69. * @param bool $updateOnly
  70. * @param bool $updated
  71. * @param string $expectedMessage
  72. */
  73. public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage) {
  74. $this->config->expects($this->once())
  75. ->method('getAppKeys')
  76. ->with('app-name')
  77. ->willReturn($configExists ? [$configName] : []);
  78. if ($updated) {
  79. $this->config->expects($this->once())
  80. ->method('setAppValue')
  81. ->with('app-name', $configName, $newValue);
  82. }
  83. $this->consoleInput->expects($this->exactly(2))
  84. ->method('getArgument')
  85. ->willReturnMap([
  86. ['app', 'app-name'],
  87. ['name', $configName],
  88. ]);
  89. $this->consoleInput->expects($this->any())
  90. ->method('getOption')
  91. ->with('value')
  92. ->willReturn($newValue);
  93. $this->consoleInput->expects($this->any())
  94. ->method('hasParameterOption')
  95. ->with('--update-only')
  96. ->willReturn($updateOnly);
  97. $this->consoleOutput->expects($this->any())
  98. ->method('writeln')
  99. ->with($this->stringContains($expectedMessage));
  100. $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  101. }
  102. }