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