DeleteTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Tests\Core\Command\User;
  8. use OC\Core\Command\User\Delete;
  9. use OCP\IUser;
  10. use OCP\IUserManager;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. use Test\TestCase;
  14. class DeleteTest extends TestCase {
  15. /** @var \PHPUnit\Framework\MockObject\MockObject */
  16. protected $userManager;
  17. /** @var \PHPUnit\Framework\MockObject\MockObject */
  18. protected $consoleInput;
  19. /** @var \PHPUnit\Framework\MockObject\MockObject */
  20. protected $consoleOutput;
  21. /** @var \Symfony\Component\Console\Command\Command */
  22. protected $command;
  23. protected function setUp(): void {
  24. parent::setUp();
  25. $userManager = $this->userManager = $this->getMockBuilder(IUserManager::class)
  26. ->disableOriginalConstructor()
  27. ->getMock();
  28. $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
  29. $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
  30. /** @var \OCP\IUserManager $userManager */
  31. $this->command = new Delete($userManager);
  32. }
  33. public function validUserLastSeen() {
  34. return [
  35. [true, 'The specified user was deleted'],
  36. [false, 'The specified user could not be deleted'],
  37. ];
  38. }
  39. /**
  40. * @dataProvider validUserLastSeen
  41. *
  42. * @param bool $deleteSuccess
  43. * @param string $expectedString
  44. */
  45. public function testValidUser($deleteSuccess, $expectedString) {
  46. $user = $this->getMockBuilder(IUser::class)->getMock();
  47. $user->expects($this->once())
  48. ->method('delete')
  49. ->willReturn($deleteSuccess);
  50. $this->userManager->expects($this->once())
  51. ->method('get')
  52. ->with('user')
  53. ->willReturn($user);
  54. $this->consoleInput->expects($this->once())
  55. ->method('getArgument')
  56. ->with('uid')
  57. ->willReturn('user');
  58. $this->consoleOutput->expects($this->once())
  59. ->method('writeln')
  60. ->with($this->stringContains($expectedString));
  61. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  62. }
  63. public function testInvalidUser() {
  64. $this->userManager->expects($this->once())
  65. ->method('get')
  66. ->with('user')
  67. ->willReturn(null);
  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('User does not exist'));
  75. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  76. }
  77. }