FrontendUserServiceTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 25
c 0
b 0
f 0
dl 0
loc 53
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mustChangePasswordReturnsExpectedResultDataProvider() 0 27 1
A mustChangePasswordReturnsExpectedResult() 0 13 1
1
<?php
2
3
/*
4
 * This file is part of the Extension "fe_change_pwd" for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.txt file that was distributed with this source code.
8
 */
9
10
use Derhansen\FeChangePwd\Service\FrontendUserService;
11
use TYPO3\CMS\Core\Session\UserSessionManager;
12
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
13
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
14
15
/**
16
 * Class FrontendUserServiceTest
17
 */
18
class FrontendUserServiceTest extends UnitTestCase
19
{
20
    /**
21
     * @return array
22
     */
23
    public function mustChangePasswordReturnsExpectedResultDataProvider()
24
    {
25
        return [
26
            'no frontend user' => [
27
                [],
28
                false,
29
            ],
30
            'must change password' => [
31
                [
32
                    'must_change_password' => 1,
33
                    'password_expiry_date' => 0,
34
                ],
35
                true,
36
            ],
37
            'password expired' => [
38
                [
39
                    'must_change_password' => 0,
40
                    'password_expiry_date' => 1538194307,
41
                ],
42
                true,
43
            ],
44
            'password not expired and no password change required' => [
45
                [
46
                    'must_change_password' => 0,
47
                    'password_expiry_date' => 0,
48
                ],
49
                false,
50
            ],
51
        ];
52
    }
53
54
    /**
55
     * @test
56
     * @dataProvider mustChangePasswordReturnsExpectedResultDataProvider
57
     */
58
    public function mustChangePasswordReturnsExpectedResult($feUserRecord, $expected)
59
    {
60
        $userSessionManager = static::getMockBuilder(UserSessionManager::class)
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::getMockBuilder() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        $userSessionManager = static::/** @scrutinizer ignore-call */ getMockBuilder(UserSessionManager::class)
Loading history...
61
            ->disableOriginalConstructor()
62
            ->getMock();
63
64
        $feUser = new FrontendUserAuthentication();
65
        $feUser->initializeUserSessionManager($userSessionManager);
66
67
        $service = new FrontendUserService();
68
        $GLOBALS['TSFE'] = new \stdClass();
69
        $GLOBALS['TSFE']->fe_user = $feUser;
70
        self::assertEquals($expected, $service->mustChangePassword($feUserRecord));
71
    }
72
}
73