1
0

TwoFactorSettingsControllerTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Settings\Tests\Controller;
  7. use OC\Authentication\TwoFactorAuth\EnforcementState;
  8. use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
  9. use OCA\Settings\Controller\TwoFactorSettingsController;
  10. use OCP\AppFramework\Http\JSONResponse;
  11. use OCP\IRequest;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. class TwoFactorSettingsControllerTest extends TestCase {
  15. /** @var IRequest|MockObject */
  16. private $request;
  17. /** @var MandatoryTwoFactor|MockObject */
  18. private $mandatoryTwoFactor;
  19. /** @var TwoFactorSettingsController */
  20. private $controller;
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $this->request = $this->createMock(IRequest::class);
  24. $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
  25. $this->controller = new TwoFactorSettingsController(
  26. 'settings',
  27. $this->request,
  28. $this->mandatoryTwoFactor
  29. );
  30. }
  31. public function testIndex(): void {
  32. $state = new EnforcementState(true);
  33. $this->mandatoryTwoFactor->expects($this->once())
  34. ->method('getState')
  35. ->willReturn($state);
  36. $expected = new JSONResponse($state);
  37. $resp = $this->controller->index();
  38. $this->assertEquals($expected, $resp);
  39. }
  40. public function testUpdate(): void {
  41. $state = new EnforcementState(true);
  42. $this->mandatoryTwoFactor->expects($this->once())
  43. ->method('setState')
  44. ->with($this->equalTo(new EnforcementState(true)));
  45. $this->mandatoryTwoFactor->expects($this->once())
  46. ->method('getState')
  47. ->willReturn($state);
  48. $expected = new JSONResponse($state);
  49. $resp = $this->controller->update(true);
  50. $this->assertEquals($expected, $resp);
  51. }
  52. }