DisableTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Core\Command\TwoFactorAuth;
  24. use OC\Authentication\TwoFactorAuth\Manager;
  25. use OC\Core\Command\TwoFactorAuth\Disable;
  26. use OCP\IUser;
  27. use OCP\IUserManager;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. use Test\TestCase;
  31. class DisableTest extends TestCase {
  32. /** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
  33. private $manager;
  34. /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  35. private $userManager;
  36. /** @var Disable */
  37. private $command;
  38. public function setUp() {
  39. parent::setUp();
  40. $this->manager = $this->createMock(Manager::class);
  41. $this->userManager = $this->createMock(IUserManager::class);
  42. $this->command = new Disable($this->manager, $this->userManager);
  43. }
  44. public function testDisableSuccess() {
  45. $user = $this->createMock(IUser::class);
  46. $input = $this->createMock(InputInterface::class);
  47. $output = $this->createMock(OutputInterface::class);
  48. $input->method('getArgument')
  49. ->with($this->equalTo('uid'))
  50. ->willReturn('user');
  51. $this->userManager->method('get')
  52. ->with('user')
  53. ->willReturn($user);
  54. $this->manager->expects($this->once())
  55. ->method('disableTwoFactorAuthentication')
  56. ->with($this->equalTo($user));
  57. $output->expects($this->once())
  58. ->method('writeln')
  59. ->with('Two-factor authentication disabled for user user');
  60. $this->invokePrivate($this->command, 'execute', [$input, $output]);
  61. }
  62. public function testEnableFail() {
  63. $input = $this->createMock(InputInterface::class);
  64. $output = $this->createMock(OutputInterface::class);
  65. $input->method('getArgument')
  66. ->with($this->equalTo('uid'))
  67. ->willReturn('user');
  68. $this->userManager->method('get')
  69. ->with('user')
  70. ->willReturn(null);
  71. $this->manager->expects($this->never())
  72. ->method($this->anything());
  73. $output->expects($this->once())
  74. ->method('writeln')
  75. ->with('<error>Invalid UID</error>');
  76. $this->invokePrivate($this->command, 'execute', [$input, $output]);
  77. }
  78. }