1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\types\DateTime;
6
7/**
8 * @group plugin_struct
9 * @group plugins
10 */
11class Type_DateTime_struct_test extends StructTest
12{
13
14    /**
15     * DataProvider for successful validations
16     */
17    public function validate_success()
18    {
19        return array(
20            array('2017-04-12', '2017-04-12 00:00'),
21            array('2017-04-12 ', '2017-04-12 00:00'),
22            array(' 2017-04-12 ', '2017-04-12 00:00'),
23            array('2017-04-12 10:11', '2017-04-12 10:11'),
24            array('2017-04-12 10:11:12', '2017-04-12 10:11'),
25            array('2017-04-12 whatever', '2017-04-12 00:00'),
26            array('2017-4-3', '2017-04-03 00:00'),
27            array('917-4-3', '917-04-03 00:00'),
28        );
29    }
30
31    /**
32     * @dataProvider validate_success
33     */
34    public function test_validation_success($input, $expect)
35    {
36        $date = new DateTime();
37
38        $this->assertEquals($expect, $date->validate($input));
39    }
40
41    /**
42     * DataProvider for failed validations
43     */
44    public function validate_fail()
45    {
46        return array(
47            array('2017-02-31'),
48            array('2017-13-31'),
49            array('2017-04-12 24:00'),
50            array('2017-04-12 23:70'),
51        );
52    }
53
54    /**
55     * @dataProvider validate_fail
56     * @expectedException \dokuwiki\plugin\struct\meta\ValidationException
57     */
58    public function test_validation_fail($input)
59    {
60        $date = new DateTime();
61
62        $date->validate($input);
63    }
64}
65