You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.5 KiB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Denis Mosolov <denismosolov@gmail.com>
  5. *
  6. * @author Denis Mosolov <denismosolov@gmail.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Afferoq General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Talk\Tests\php\Command\Signaling;
  25. use OCA\Talk\Command\Signaling\Delete;
  26. use OCP\IConfig;
  27. use PHPUnit\Framework\MockObject\MockObject;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. use Test\TestCase;
  31. class DeleteTest extends TestCase {
  32. protected IConfig&MockObject $config;
  33. protected InputInterface&MockObject $input;
  34. protected OutputInterface&MockObject $output;
  35. protected Delete $command;
  36. public function setUp(): void {
  37. parent::setUp();
  38. $this->config = $this->createMock(IConfig::class);
  39. $this->command = new Delete($this->config);
  40. $this->input = $this->createMock(InputInterface::class);
  41. $this->output = $this->createMock(OutputInterface::class);
  42. }
  43. public function testDeleteIfEmpty(): void {
  44. $this->input->method('getArgument')
  45. ->with('server')
  46. ->willReturn('wss://signaling.example.com');
  47. $this->config->expects($this->once())
  48. ->method('getAppValue')
  49. ->with('spreed', 'signaling_servers')
  50. ->willReturn('');
  51. $this->config->expects($this->once())
  52. ->method('setAppValue')
  53. ->with(
  54. $this->equalTo('spreed'),
  55. $this->equalTo('signaling_servers'),
  56. $this->equalTo(json_encode([
  57. 'servers' => [],
  58. 'secret' => ''
  59. ]))
  60. );
  61. $this->output->expects($this->once())
  62. ->method('writeln')
  63. ->with($this->equalTo('<info>There is nothing to delete.</info>'));
  64. self::invokePrivate($this->command, 'execute', [$this->input, $this->output]);
  65. }
  66. public function testDelete(): void {
  67. $this->input->method('getArgument')
  68. ->with('server')
  69. ->willReturn('wss://signaling2.test.com');
  70. $this->config->expects($this->once())
  71. ->method('getAppValue')
  72. ->with('spreed', 'signaling_servers')
  73. ->willReturn(json_encode([
  74. 'servers' => [
  75. [
  76. 'server' => 'wss://signaling1.test.com',
  77. 'verify' => false,
  78. ],
  79. [
  80. 'server' => 'wss://signaling2.test.com',
  81. 'verify' => false,
  82. ],
  83. [
  84. 'server' => 'wss://signaling3.test.com',
  85. 'verify' => false,
  86. ]
  87. ],
  88. 'secret' => 'my-test-secret',
  89. ]));
  90. $this->config->expects($this->once())
  91. ->method('setAppValue')
  92. ->with(
  93. $this->equalTo('spreed'),
  94. $this->equalTo('signaling_servers'),
  95. $this->equalTo(json_encode([
  96. 'servers' => [
  97. [
  98. 'server' => 'wss://signaling1.test.com',
  99. 'verify' => false,
  100. ],
  101. [
  102. 'server' => 'wss://signaling3.test.com',
  103. 'verify' => false,
  104. ]
  105. ],
  106. 'secret' => 'my-test-secret',
  107. ]))
  108. );
  109. $this->output->expects($this->once())
  110. ->method('writeln')
  111. ->with($this->equalTo('<info>Deleted wss://signaling2.test.com.</info>'));
  112. self::invokePrivate($this->command, 'execute', [$this->input, $this->output]);
  113. }
  114. public function testNothingToDelete(): void {
  115. $this->input->method('getArgument')
  116. ->with('server')
  117. ->willReturn('wss://signaling4.test.com');
  118. $this->config->expects($this->once())
  119. ->method('getAppValue')
  120. ->with('spreed', 'signaling_servers')
  121. ->willReturn(json_encode([
  122. 'servers' => [
  123. [
  124. 'server' => 'wss://signaling1.test.com',
  125. 'verify' => false,
  126. ]
  127. ],
  128. 'secret' => 'my-test-secret',
  129. ]));
  130. $this->config->expects($this->once())
  131. ->method('setAppValue')
  132. ->with(
  133. $this->equalTo('spreed'),
  134. $this->equalTo('signaling_servers'),
  135. $this->equalTo(json_encode([
  136. 'servers' => [
  137. [
  138. 'server' => 'wss://signaling1.test.com',
  139. 'verify' => false,
  140. ]
  141. ],
  142. 'secret' => 'my-test-secret',
  143. ]))
  144. );
  145. $this->output->expects($this->once())
  146. ->method('writeln')
  147. ->with($this->equalTo('<info>There is nothing to delete.</info>'));
  148. self::invokePrivate($this->command, 'execute', [$this->input, $this->output]);
  149. }
  150. }