1
0

setconfigtest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\System;
  22. use OC\Core\Command\Config\System\SetConfig;
  23. use Test\TestCase;
  24. class SetConfigTest extends TestCase {
  25. /** @var \PHPUnit_Framework_MockObject_MockObject */
  26. protected $systemConfig;
  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. $systemConfig = $this->systemConfig = $this->getMockBuilder('OC\SystemConfig')
  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 \OC\SystemConfig $systemConfig */
  41. $this->command = new SetConfig($systemConfig);
  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->systemConfig->expects($this->once())
  75. ->method('getKeys')
  76. ->willReturn($configExists ? [$configName] : []);
  77. if ($updated) {
  78. $this->systemConfig->expects($this->once())
  79. ->method('setValue')
  80. ->with($configName, $newValue);
  81. }
  82. $this->consoleInput->expects($this->once())
  83. ->method('getArgument')
  84. ->with('name')
  85. ->willReturn($configName);
  86. $this->consoleInput->expects($this->any())
  87. ->method('getOption')
  88. ->with('value')
  89. ->willReturn($newValue);
  90. $this->consoleInput->expects($this->any())
  91. ->method('hasParameterOption')
  92. ->with('--update-only')
  93. ->willReturn($updateOnly);
  94. $this->consoleOutput->expects($this->any())
  95. ->method('writeln')
  96. ->with($this->stringContains($expectedMessage));
  97. $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  98. }
  99. }