DeleteTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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\User;
  22. use OC\Core\Command\User\Delete;
  23. use OCP\IUser;
  24. use OCP\IUserManager;
  25. use Symfony\Component\Console\Input\InputInterface;
  26. use Symfony\Component\Console\Output\OutputInterface;
  27. use Test\TestCase;
  28. class DeleteTest extends TestCase {
  29. /** @var \PHPUnit_Framework_MockObject_MockObject */
  30. protected $userManager;
  31. /** @var \PHPUnit_Framework_MockObject_MockObject */
  32. protected $consoleInput;
  33. /** @var \PHPUnit_Framework_MockObject_MockObject */
  34. protected $consoleOutput;
  35. /** @var \Symfony\Component\Console\Command\Command */
  36. protected $command;
  37. protected function setUp() {
  38. parent::setUp();
  39. $userManager = $this->userManager = $this->getMockBuilder(IUserManager::class)
  40. ->disableOriginalConstructor()
  41. ->getMock();
  42. $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
  43. $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
  44. /** @var \OCP\IUserManager $userManager */
  45. $this->command = new Delete($userManager);
  46. }
  47. public function validUserLastSeen() {
  48. return [
  49. [true, 'The specified user was deleted'],
  50. [false, 'The specified user could not be deleted'],
  51. ];
  52. }
  53. /**
  54. * @dataProvider validUserLastSeen
  55. *
  56. * @param bool $deleteSuccess
  57. * @param string $expectedString
  58. */
  59. public function testValidUser($deleteSuccess, $expectedString) {
  60. $user = $this->getMockBuilder(IUser::class)->getMock();
  61. $user->expects($this->once())
  62. ->method('delete')
  63. ->willReturn($deleteSuccess);
  64. $this->userManager->expects($this->once())
  65. ->method('get')
  66. ->with('user')
  67. ->willReturn($user);
  68. $this->consoleInput->expects($this->once())
  69. ->method('getArgument')
  70. ->with('uid')
  71. ->willReturn('user');
  72. $this->consoleOutput->expects($this->once())
  73. ->method('writeln')
  74. ->with($this->stringContains($expectedString));
  75. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  76. }
  77. public function testInvalidUser() {
  78. $this->userManager->expects($this->once())
  79. ->method('get')
  80. ->with('user')
  81. ->willReturn(null);
  82. $this->consoleInput->expects($this->once())
  83. ->method('getArgument')
  84. ->with('uid')
  85. ->willReturn('user');
  86. $this->consoleOutput->expects($this->once())
  87. ->method('writeln')
  88. ->with($this->stringContains('User does not exist'));
  89. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  90. }
  91. }