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