]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/DateTimeFormatTest.php
Merge remote-tracking branch 'upstream/develop' into item-view
[friendica.git] / tests / src / Util / DateTimeFormatTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Util;
23
24 use Friendica\Test\MockedTest;
25 use Friendica\Util\DateTimeFormat;
26
27 class DateTimeFormatTest extends MockedTest
28 {
29         public function dataYearMonth()
30         {
31                 return [
32                         'validNormal' => [
33                                 'input' => '1990-10',
34                                 'assert' => true,
35                         ],
36                         'validOneCharMonth' => [
37                                 'input' => '1990-1',
38                                 'assert' => true,
39                         ],
40                         'validTwoCharMonth' => [
41                                 'input' => '1990-01',
42                                 'assert' => true,
43                         ],
44                         'invalidFormat' => [
45                                 'input' => '199-11',
46                                 'assert' => false,
47                         ],
48                         'invalidFormat2' => [
49                                 'input' => '1990-15',
50                                 'assert' => false,
51                         ],
52                         'invalidFormat3' => [
53                                 'input' => '99-101',
54                                 'assert' => false,
55                         ],
56                         'invalidFormat4' => [
57                                 'input' => '11-1990',
58                                 'assert' => false,
59                         ],
60                         'invalidFuture' => [
61                                 'input' => '3030-12',
62                                 'assert' => false,
63                         ],
64                         'invalidYear' => [
65                                 'input' => '-100-10',
66                                 'assert' => false,
67                         ],
68                 ];
69         }
70
71         /**
72          * @dataProvider dataYearMonth
73          */
74         public function testIsYearMonth(string $input, bool $assert)
75         {
76                 $dtFormat = new DateTimeFormat();
77
78                 self::assertEquals($assert, $dtFormat->isYearMonth($input));
79         }
80 }