SetConfigTest.php 3.1 KB

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