PasswordTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Tests\Settings\Personal\Security;
  8. use OCA\Settings\Settings\Personal\Security\Password;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\IUser;
  11. use OCP\IUserManager;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. class PasswordTest extends TestCase {
  15. /** @var IUserManager|MockObject */
  16. private $userManager;
  17. /** @var string */
  18. private $uid;
  19. /** @var Password */
  20. private $section;
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $this->userManager = $this->createMock(IUserManager::class);
  24. $this->uid = 'test123';
  25. $this->section = new Password(
  26. $this->userManager,
  27. $this->uid
  28. );
  29. }
  30. public function testGetForm() {
  31. $user = $this->createMock(IUser::class);
  32. $this->userManager->expects($this->once())
  33. ->method('get')
  34. ->with($this->uid)
  35. ->willReturn($user);
  36. $user->expects($this->once())
  37. ->method('canChangePassword')
  38. ->willReturn(true);
  39. $form = $this->section->getForm();
  40. $expected = new TemplateResponse('settings', 'settings/personal/security/password', [
  41. 'passwordChangeSupported' => true,
  42. ]);
  43. $this->assertEquals($expected, $form);
  44. }
  45. }