ILIAS  release_7 Revision v7.30-3-g800a261c036
DateFormatTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once("libs/composer/vendor/autoload.php");
6
8use PHPUnit\Framework\TestCase;
9
10class DateFormatTest extends TestCase
11{
12 public function testFactory()
13 {
14 $f = new ILIAS\Data\Factory();
15 $df = $f->dateFormat();
16 $this->assertInstanceOf(DateFormat\Factory::class, $df);
17 return $df;
18 }
19
24 {
25 $this->assertInstanceOf(DateFormat\DateFormat::class, $df->standard());
26 $this->assertInstanceOf(DateFormat\DateFormat::class, $df->germanShort());
27 $this->assertInstanceOf(DateFormat\DateFormat::class, $df->germanLong());
28 $this->assertInstanceOf(DateFormat\FormatBuilder::class, $df->custom());
29 }
30
35 {
36 $expect = [
37 '.', ',', '-', '/', ' ', 'd', 'jS', 'l', 'D', 'W', 'm', 'F', 'M', 'Y', 'y'
38 ];
39 $format = $df->custom()
40 ->dot()->comma()->dash()->slash()->space()
41 ->day()->dayOrdinal()->weekday()->weekdayShort()
42 ->week()->month()->monthSpelled()->monthSpelledShort()
43 ->year()->twoDigitYear()
44 ->get();
45
46 $this->assertEquals(
47 $expect,
48 $format->toArray()
49 );
50
51 $this->assertEquals(
52 implode('', $expect),
53 $format->toString()
54 );
55 }
56
57 public function testInvalidTokens()
58 {
59 $this->expectException(\InvalidArgumentException::class);
60 new DateFormat\DateFormat(['x', '2']);
61 }
62}
An exception for terminatinating execution or to throw for unit testing.
testDateFormatBuilderAndGetters(DateFormat\Factory $df)
@depends testFactory
testDateFormatFactory(DateFormat\Factory $df)
@depends testFactory
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition: DateFormat.php:11
Factory for Date Formats.
Definition: Factory.php:10
Builds data types.
Definition: Factory.php:20
$format
Definition: metadata.php:218