deleteconfigtest.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\System;
  22. use OC\Core\Command\Config\System\DeleteConfig;
  23. use Test\TestCase;
  24. class DeleteConfigTest 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 DeleteConfig($systemConfig);
  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->systemConfig->expects(($checkIfExists) ? $this->once() : $this->never())
  86. ->method('getKeys')
  87. ->willReturn($configExists ? [$configName] : []);
  88. $this->systemConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never())
  89. ->method('deleteValue')
  90. ->with($configName);
  91. $this->consoleInput->expects($this->once())
  92. ->method('getArgument')
  93. ->with('name')
  94. ->willReturn($configName);
  95. $this->consoleInput->expects($this->any())
  96. ->method('hasParameterOption')
  97. ->with('--error-if-not-exists')
  98. ->willReturn($checkIfExists);
  99. $this->consoleOutput->expects($this->any())
  100. ->method('writeln')
  101. ->with($this->stringContains($expectedMessage));
  102. $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
  103. }
  104. }