SettingsServiceTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
eloc 26
c 3
b 0
f 0
dl 0
loc 59
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPasswordExpiryTimestampReturnsExpectedResultDataProvider() 0 35 1
A getPasswordExpiryTimestampReturnsExpectedResult() 0 11 1
1
<?php
2
3
namespace Derhansen\FeChangePwd\Tests\Unit\Service;
4
5
/*
6
 * This file is part of the Extension "fe_change_pwd" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
use Derhansen\FeChangePwd\Service\SettingsService;
13
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
14
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
15
16
/**
17
 * Class SettingsServiceTest
18
 */
19
class SettingsServiceTest extends UnitTestCase
20
{
21
    /**
22
     * @return array
23
     */
24
    public function getPasswordExpiryTimestampReturnsExpectedResultDataProvider()
25
    {
26
        return [
27
            'no settings' => [
28
                [],
29
                new \DateTime(),
30
                0,
31
            ],
32
            'passwordExpiration disabled' => [
33
                [
34
                    'passwordExpiration' => [
35
                        'enabled' => 0,
36
                    ],
37
                ],
38
                new \DateTime(),
39
                0,
40
            ],
41
            'default validityInDays of 90 days if not set' => [
42
                [
43
                    'passwordExpiration' => [
44
                        'enabled' => 1,
45
                    ],
46
                ],
47
                \DateTime::createFromFormat('d.m.Y H:i:s e', '01.01.2018 00:00:00 UTC'),
48
                1522540800,
49
            ],
50
            'sets configured validityInDays' => [
51
                [
52
                    'passwordExpiration' => [
53
                        'enabled' => 1,
54
                        'validityInDays' => 30,
55
                    ],
56
                ],
57
                \DateTime::createFromFormat('d.m.Y H:i:s e', '01.01.2018 00:00:00 UTC'),
58
                1517356800,
59
            ],
60
        ];
61
    }
62
63
    /**
64
     * @test
65
     * @dataProvider getPasswordExpiryTimestampReturnsExpectedResultDataProvider
66
     */
67
    public function getPasswordExpiryTimestampReturnsExpectedResult($settings, $currentDate, $expected)
68
    {
69
        $service = new SettingsService();
70
71
        $GLOBALS['TSFE'] = static::getMockBuilder(TypoScriptFrontendController::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

71
        $GLOBALS['TSFE'] = static::/** @scrutinizer ignore-call */ getMockBuilder(TypoScriptFrontendController::class)
Loading history...
72
            ->disableOriginalConstructor()
73
            ->getMock();
74
        $GLOBALS['TSFE']->tmpl = new \stdClass();
75
        $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_fechangepwd.']['settings.'] = $settings;
76
77
        self::assertEquals($expected, $service->getPasswordExpiryTimestamp($currentDate));
78
    }
79
}
80