DeleteConfigTest.php 3.2 KB

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