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