aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Authentication/Login/UserDisabledCheckCommandTest.php
blob: ee4e171d443a496723d46a162839a465ad42ad09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

declare(strict_types=1);

namespace Test\Authentication\Login;

use OC\Authentication\Login\UserDisabledCheckCommand;
use OC\Core\Controller\LoginController;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

class UserDisabledCheckCommandTest extends ALoginTestCommand {
	/** @var IUserManager|MockObject */
	private $userManager;

	/** @var LoggerInterface|MockObject */
	private $logger;

	protected function setUp(): void {
		parent::setUp();

		$this->userManager = $this->createMock(IUserManager::class);
		$this->logger = $this->createMock(LoggerInterface::class);

		$this->cmd = new UserDisabledCheckCommand(
			$this->userManager,
			$this->logger
		);
	}

	public function testProcessNonExistingUser(): void {
		$data = $this->getBasicLoginData();
		$this->userManager->expects($this->once())
			->method('get')
			->with($this->username)
			->willReturn(null);

		$result = $this->cmd->process($data);

		$this->assertTrue($result->isSuccess());
	}

	public function testProcessDisabledUser(): void {
		$data = $this->getBasicLoginData();
		$this->userManager->expects($this->once())
			->method('get')
			->with($this->username)
			->willReturn($this->user);
		$this->user->expects($this->once())
			->method('isEnabled')
			->willReturn(false);

		$result = $this->cmd->process($data);

		$this->assertFalse($result->isSuccess());
		$this->assertSame(LoginController::LOGIN_MSG_USERDISABLED, $result->getErrorMessage());
	}

	public function testProcess(): void {
		$data = $this->getBasicLoginData();
		$this->userManager->expects($this->once())
			->method('get')
			->with($this->username)
			->willReturn($this->user);
		$this->user->expects($this->once())
			->method('isEnabled')
			->willReturn(true);

		$result = $this->cmd->process($data);

		$this->assertTrue($result->isSuccess());
	}
}