EnableTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Tests\Core\Command\User;
  7. use OC\Core\Command\User\Enable;
  8. use OCP\IUser;
  9. use OCP\IUserManager;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. use Test\TestCase;
  13. class EnableTest extends TestCase {
  14. /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
  15. protected $userManager;
  16. /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */
  17. protected $consoleInput;
  18. /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */
  19. protected $consoleOutput;
  20. /** @var Disable */
  21. protected $command;
  22. protected function setUp(): void {
  23. parent::setUp();
  24. $this->userManager = $this->createMock(IUserManager::class);
  25. $this->consoleInput = $this->createMock(InputInterface::class);
  26. $this->consoleOutput = $this->createMock(OutputInterface::class);
  27. $this->command = new Enable($this->userManager);
  28. }
  29. public function testValidUser() {
  30. $user = $this->createMock(IUser::class);
  31. $user->expects($this->once())
  32. ->method('setEnabled')
  33. ->with(true);
  34. $this->userManager
  35. ->method('get')
  36. ->with('user')
  37. ->willReturn($user);
  38. $this->consoleInput
  39. ->method('getArgument')
  40. ->with('uid')
  41. ->willReturn('user');
  42. $this->consoleOutput->expects($this->once())
  43. ->method('writeln')
  44. ->with($this->stringContains('The specified user is enabled'));
  45. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  46. }
  47. public function testInvalidUser() {
  48. $this->userManager->expects($this->once())
  49. ->method('get')
  50. ->with('user')
  51. ->willReturn(null);
  52. $this->consoleInput
  53. ->method('getArgument')
  54. ->with('uid')
  55. ->willReturn('user');
  56. $this->consoleOutput->expects($this->once())
  57. ->method('writeln')
  58. ->with($this->stringContains('User does not exist'));
  59. self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
  60. }
  61. }