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