~fkooman/vpn-user-portal

ref: 57df62b9a04e9b2391ca809e5ff9d76e524eceb1 vpn-user-portal/tests/ExpiryTest.php -rw-r--r-- 1.5 KiB
57df62b9François Kooman update CHANGES 1 year, 4 months ago
                                                                                
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
<?php

/*
 * eduVPN - End-user friendly VPN.
 *
 * Copyright: 2016-2019, The Commons Conservancy eduVPN Programme
 * SPDX-License-Identifier: AGPL-3.0+
 */

namespace LC\Portal\Tests;

use DateInterval;
use DateTime;
use LC\Portal\Expiry;
use PHPUnit\Framework\TestCase;

class ExpiryTest extends TestCase
{
    /**
     * @return void
     */
    public function testLong()
    {
        $dataSet = [
            // sessionExpiry, expiresAt, currentDate
            ['P90D',  '2021-07-05T04:00:00+02:00', '2021-04-06T09:00:00+02:00'],
            ['P7D',   '2021-04-13T04:00:00+02:00', '2021-04-06T09:00:00+02:00'],
            ['PT12H', '2021-04-06T21:00:00+02:00', '2021-04-06T09:00:00+02:00'],
            ['P3D',   '2021-04-09T09:00:00+02:00', '2021-04-06T09:00:00+02:00'],
            ['P7D',   '2021-04-12T04:00:00+02:00', '2021-04-06T00:00:00+02:00'],
            ['P7D',   '2021-04-12T04:00:00+02:00', '2021-04-06T01:00:00+02:00'],
            ['P7D',   '2021-04-12T04:00:00+02:00', '2021-04-06T02:00:00+02:00'],
            ['P7D',   '2021-04-12T04:00:00+02:00', '2021-04-06T03:00:00+02:00'],
            ['P7D',   '2021-04-13T04:00:00+02:00', '2021-04-06T04:00:00+02:00'],
            ['P7D',   '2021-04-13T04:00:00+02:00', '2021-04-06T05:00:00+02:00'],
        ];

        foreach ($dataSet as $dataPoint) {
            $dateTime = new DateTime($dataPoint[2]);
            $expiryInterval = Expiry::calculate(new DateInterval($dataPoint[0]), $dateTime);
            $this->assertSame($dataPoint[1], $dateTime->add($expiryInterval)->format(DateTime::ATOM));
        }
    }
}