Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
36.00% covered (danger)
36.00%
18 / 50
44.44% covered (danger)
44.44%
4 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_functions_validate_hex_colour_test
36.00% covered (danger)
36.00%
18 / 50
44.44% covered (danger)
44.44%
4 / 9
30.23
0.00% covered (danger)
0.00%
0 / 1
 positive_match_data
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 negative_match_data
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
 optional_only_data
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 strict_negative_match_data
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 nonstrict_positive_match_data
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_strict_positive_match
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 test_strict_negative_match
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 test_nonstrict_positive_match
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 test_nonstrict_negative_match
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14require_once __DIR__ . '/../../phpBB/includes/functions_user.php';
15
16class phpbb_functions_validate_hex_colour_test extends phpbb_test_case
17{
18    public static function positive_match_data()
19    {
20        return array(
21            array('a00'),
22            array('AFF'),
23            array('AA0000'),
24            array('aa00FF'),
25            array('000'),
26            array('000000'),
27        );
28    }
29
30    public static function negative_match_data()
31    {
32        return array(
33            // Invalid prefix
34            array('#aa0'),
35            array('#AA0000'),
36            array('vAA0000'),
37
38            // Invalid suffix
39            array('AA0000v'),
40
41            // Correct length, but out of hex range
42            array('ag0'),
43            array('AAG000'),
44
45            // Too long
46            array('AA00000'),
47            array('AA0000 '),
48            array('AA0000 abf'),
49            array('AA0000 AA0000'),
50
51            // empty()
52            array('0'),
53        );
54    }
55
56    public static function optional_only_data()
57    {
58        return array(
59            // The empty colour, i.e. "no colour".
60            array(''),
61        );
62    }
63
64    public static function strict_negative_match_data()
65    {
66        return array_merge(
67            self::negative_match_data(),
68            self::optional_only_data()
69        );
70    }
71
72    public static function nonstrict_positive_match_data()
73    {
74        return array_merge(
75            self::positive_match_data(),
76            self::optional_only_data()
77        );
78    }
79
80    /**
81    * @dataProvider positive_match_data
82    */
83    public function test_strict_positive_match($input)
84    {
85        $this->assertFalse(
86            phpbb_validate_hex_colour($input, false),
87            "Failed asserting that $input passes as a valid hex colour."
88        );
89    }
90
91    /**
92    * @dataProvider strict_negative_match_data
93    */
94    public function test_strict_negative_match($input)
95    {
96        $this->assertSame(
97            'WRONG_DATA',
98            phpbb_validate_hex_colour($input, false),
99            "Failed asserting that $input does not pass as a valid hex colour."
100        );
101    }
102
103    /**
104    * @dataProvider nonstrict_positive_match_data
105    */
106    public function test_nonstrict_positive_match($input)
107    {
108        $this->assertFalse(
109            phpbb_validate_hex_colour($input, true),
110            "Failed asserting that $input passes as a valid or optional hex colour."
111        );
112    }
113
114    /**
115    * @dataProvider negative_match_data
116    */
117    public function test_nonstrict_negative_match($input)
118    {
119        $this->assertSame(
120            'WRONG_DATA',
121            phpbb_validate_hex_colour($input, true),
122            "Failed asserting that $input does not pass as a valid or optional hex colour."
123        );
124    }
125}