Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
4.29% covered (danger)
4.29%
3 / 70
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_regex_ipv6_test
4.29% covered (danger)
4.29%
3 / 70
60.00% covered (warning)
60.00%
3 / 5
26.92
0.00% covered (danger)
0.00%
0 / 1
 setUp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 positive_match_data
0.00% covered (danger)
0.00%
0 / 54
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
 test_positive_match
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_negative_match
100.00% covered (success)
100.00%
1 / 1
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
14class phpbb_regex_ipv6_test extends phpbb_test_case
15{
16    protected $regex;
17
18    protected function setUp(): void
19    {
20        $this->regex = get_preg_expression('ipv6');
21    }
22
23    public static function positive_match_data()
24    {
25        return array(
26            // Full length IPv6 address
27            array('2001:0db8:85a3:0000:0000:8a2e:0370:1337'),
28            array('0000:0000:0000:0000:0000:0000:0000:0001'),
29            array('3FFE:0b00:0000:0000:0001:0000:0000:000a'),
30            array('3ffe:0b00:0000:0000:0001:0000:0000:000a'),
31            array('2002:0db8:0000:0000:0000:dead:1337:d00d'),
32
33            // No leading zeroes in the group
34            array('2001:db8:85a3:0:0:8a2e:370:1337'),
35            array('2001:db8:85a3:c:d:8a2e:370:1337'),
36
37            // Consecutive all-zero groups
38            array('2001:db8:85a3::8a2e:370:1337'),
39            array('1::2:3:4:5:6:7'),
40            array('1::2:3:4:5:6'),
41            array('1::2:3:4:5'),
42            array('1::2:3:4'),
43            array('1::2:3'),
44            array('1::2'),
45
46            // Last 32bit in dotted quad notation
47            array('2001:db8:0:1::192.168.0.2'),
48
49            // IPv4-compatible IPv6 address
50            array('::13.1.68.3'),
51            array('0:0:0:0:0:0:13.1.68.3'),
52
53            // IPv4-mapped IPv6 address
54            array('::ffff:c000:280'),
55            array('::ffff:c000:0280'),
56            array('::ffff:192.0.2.128'),
57            array('0:0:0:0:0:ffff:c000:280'),
58            array('0:0:0:0:0:ffff:c000:0280'),
59            array('0:0:0:0:0:ffff:192.0.2.128'),
60            array('0000:0000:0000:0000:0000:ffff:c000:280'),
61            array('0000:0000:0000:0000:0000:ffff:c000:0280'),
62            array('0000:0000:0000:0000:0000:ffff:192.0.2.128'),
63
64            // No trailing zeroes
65            array('fe80::'),
66            array('2002::'),
67            array('2001:db8::'),
68            array('2001:0db8:1234::'),
69            array('1:2:3:4:5:6::'),
70            array('1:2:3:4:5::'),
71            array('1:2:3:4::'),
72            array('1:2:3::'),
73            array('1:2::'),
74
75            // No leading zeroes
76            array('::2:3:4:5:6:7:8'),
77            array('::2:3:4:5:6:7'),
78            array('::2:3:4:5:6'),
79            array('::2:3:4:5'),
80            array('::2:3:4'),
81            array('::2:3'),
82            array('::1'),
83            array('::8'),
84            array('::c'),
85            array('::abcd'),
86
87            // All zeroes
88            array('::'),
89            array('0:0:0:0:0:0:0:0'),
90            array('0000:0000:0000:0000:0000:0000:0000:0000'),
91
92            // More tests
93            array('2::10'),
94            array('0:0::0:0:1'),
95            array('0:0:0:0:0:0:0:1'),
96            array('::ffff:0:0'),
97        );
98    }
99
100    public static function negative_match_data()
101    {
102        return array(
103            // Empty address
104            array(''),
105
106            // IPv4 address
107            array('192.168.0.2'),
108
109            // Out of scope
110            array('abcd:efgh:0000::0'),
111            array('::ffff:192.168.255.256'),
112
113            // Double ::
114            array('2001::23de::2002'),
115            array('3ffe:b00::1::b'),
116            array('::1111:2222:3333:4444:5555:6666::'),
117
118            // Too many blocks
119            array('2001:0db8:85a3:08d3:1319:8a2e:0370:1337:4430'),
120
121            // More tests
122            array('02001:0000:1234:0000:0000:C1C0:ABCD:9876'),
123            array('2001:0000:1234: 0000:0000:C1C0:ABCD:9876'),
124            array('::ffff:192x168.255.255'),
125        );
126    }
127
128    /**
129    * @dataProvider positive_match_data
130    */
131    public function test_positive_match($address)
132    {
133        $this->assertEquals(1, preg_match($this->regex, $address));
134    }
135
136    /**
137    * @dataProvider negative_match_data
138    */
139    public function test_negative_match($address)
140    {
141        $this->assertEquals(0, preg_match($this->regex, $address));
142    }
143}
144