diff options
author | Daniel <mail@danielkesselberg.de> | 2024-06-12 14:49:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-12 14:49:03 +0200 |
commit | e5a6698ec0125d0183b3e71d27e4d22dae0431bc (patch) | |
tree | 35ac0a956b12d31568341651b8dd35eda9db7b72 /tests | |
parent | 4c32ab7b729b7bb8e2a59eb4f8a0b3c657e0f2a1 (diff) | |
parent | 98eb190e048ee9ea0bd27f36589bda3e34c12d0a (diff) | |
download | nextcloud-server-e5a6698ec0125d0183b3e71d27e4d22dae0431bc.tar.gz nextcloud-server-e5a6698ec0125d0183b3e71d27e4d22dae0431bc.zip |
Merge pull request #45811 from nextcloud/add-test-for-profile-page-controller
test: add tests for ProfilePageController
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/ProfilePageControllerTest.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/Core/Controller/ProfilePageControllerTest.php b/tests/Core/Controller/ProfilePageControllerTest.php new file mode 100644 index 00000000000..361f93ff409 --- /dev/null +++ b/tests/Core/Controller/ProfilePageControllerTest.php @@ -0,0 +1,78 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace Core\Controller; + +use OC\Core\Controller\ProfilePageController; +use OC\Profile\ProfileManager; +use OC\UserStatus\Manager; +use OCP\AppFramework\Services\IInitialState; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\INavigationManager; +use OCP\IRequest; +use OCP\IUser; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\Share\IManager; +use Test\TestCase; + +class ProfilePageControllerTest extends TestCase { + + private IUserManager $userManager; + private ProfilePageController $controller; + + protected function setUp(): void { + parent::setUp(); + + $request = $this->createMock(IRequest::class); + $initialStateService = $this->createMock(IInitialState::class); + $profileManager = $this->createMock(ProfileManager::class); + $shareManager = $this->createMock(IManager::class); + $this->userManager = $this->createMock(IUserManager::class); + $userSession = $this->createMock(IUserSession::class); + $userStatusManager = $this->createMock(Manager::class); + $navigationManager = $this->createMock(INavigationManager::class); + $eventDispatcher = $this->createMock(IEventDispatcher::class); + + $this->controller = new ProfilePageController( + 'core', + $request, + $initialStateService, + $profileManager, + $shareManager, + $this->userManager, + $userSession, + $userStatusManager, + $navigationManager, + $eventDispatcher, + ); + } + + public function testUserNotFound(): void { + $this->userManager->method('get') + ->willReturn(null); + + $response = $this->controller->index('bob'); + + $this->assertTrue($response->isThrottled()); + } + + public function testUserDisabled(): void { + $user = $this->createMock(IUser::class); + $user->method('isEnabled') + ->willReturn(false); + + $this->userManager->method('get') + ->willReturn($user); + + $response = $this->controller->index('bob'); + + $this->assertFalse($response->isThrottled()); + } +} |