ProfilePageControllerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Core\Controller;
  8. use OC\Core\Controller\ProfilePageController;
  9. use OC\Profile\ProfileManager;
  10. use OC\UserStatus\Manager;
  11. use OCP\AppFramework\Services\IInitialState;
  12. use OCP\EventDispatcher\IEventDispatcher;
  13. use OCP\INavigationManager;
  14. use OCP\IRequest;
  15. use OCP\IUser;
  16. use OCP\IUserManager;
  17. use OCP\IUserSession;
  18. use OCP\Share\IManager;
  19. use Test\TestCase;
  20. class ProfilePageControllerTest extends TestCase {
  21. private IUserManager $userManager;
  22. private ProfilePageController $controller;
  23. protected function setUp(): void {
  24. parent::setUp();
  25. $request = $this->createMock(IRequest::class);
  26. $initialStateService = $this->createMock(IInitialState::class);
  27. $profileManager = $this->createMock(ProfileManager::class);
  28. $shareManager = $this->createMock(IManager::class);
  29. $this->userManager = $this->createMock(IUserManager::class);
  30. $userSession = $this->createMock(IUserSession::class);
  31. $userStatusManager = $this->createMock(Manager::class);
  32. $navigationManager = $this->createMock(INavigationManager::class);
  33. $eventDispatcher = $this->createMock(IEventDispatcher::class);
  34. $this->controller = new ProfilePageController(
  35. 'core',
  36. $request,
  37. $initialStateService,
  38. $profileManager,
  39. $shareManager,
  40. $this->userManager,
  41. $userSession,
  42. $userStatusManager,
  43. $navigationManager,
  44. $eventDispatcher,
  45. );
  46. }
  47. public function testUserNotFound(): void {
  48. $this->userManager->method('get')
  49. ->willReturn(null);
  50. $response = $this->controller->index('bob');
  51. $this->assertTrue($response->isThrottled());
  52. }
  53. public function testUserDisabled(): void {
  54. $user = $this->createMock(IUser::class);
  55. $user->method('isEnabled')
  56. ->willReturn(false);
  57. $this->userManager->method('get')
  58. ->willReturn($user);
  59. $response = $this->controller->index('bob');
  60. $this->assertFalse($response->isThrottled());
  61. }
  62. }