deleteconfigtest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\DeleteConfig;
  23. use Test\TestCase;
  24. class DeleteConfigTest 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 DeleteConfig($config);
  42. }
  43. public function deleteData() {
  44. return [
  45. [
  46. 'name',
  47. true,
  48. true,
  49. 0,
  50. 'info',
  51. ],
  52. [
  53. 'name',
  54. true,
  55. false,
  56. 0,
  57. 'info',
  58. ],
  59. [
  60. 'name',
  61. false,
  62. false,
  63. 0,
  64. 'info',
  65. ],
  66. [
  67. 'name',
  68. false,
  69. true,
  70. 1,
  71. 'error',
  72. ],
  73. ];
  74. }
  75. /**
  76. * @dataProvider deleteData
  77. *
  78. * @param string $configName
  79. * @param bool $configExists
  80. * @param bool $checkIfExists
  81. * @param int $expectedReturn
  82. * @param string $expectedMessage
  83. */
  84. public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage) {
  85. $this->config->expects(($checkIfExists) ? $this->once() : $this->never())
  86. ->method('getAppKeys')
  87. ->with('app-name')
  88. ->willReturn($configExists ? [$configName] : []);
  89. $this->config->expects(($expectedReturn === 0) ? $this->once() : $this->never())
  90. ->method('deleteAppValue')
  91. ->with('app-name', $configName);
  92. $this->consoleInput->expects($this->exactly(2))
  93. ->method('getArgument')
  94. ->willReturnMap([
  95. ['app', 'app-name'],
  96. ['name', $configName],
  97. ]);
  98. $this->consoleInput->expects($this->any())
  99. ->method('hasParameterOption')
  100. ->with('--error-if-not-exists')
  101. ->willReturn($checkIfExists);
  102. $this->consoleOutput->expects($this->any())
  103. ->method('writeln')
  104. ->with($this->stringContains($expectedMessage));
  105. $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
  106. }
  107. }