@@ -27,4 +27,140 @@ public function testGetWebService() {
2727 $ record ['country_code ' ],
2828 );
2929 }
30+
31+ public function testIpv4 ()
32+ {
33+ $ IP2Location = new IP2LocationCoresController ();
34+ $ this ->assertTrue ($ IP2Location ->isIpv4 ('8.8.8.8 ' ));
35+ }
36+
37+ public function testInvalidIpv4 ()
38+ {
39+ $ IP2Location = new IP2LocationCoresController ();
40+ $ this ->assertFalse ($ IP2Location ->isIpv4 ('8.8.8.555 ' ));
41+ }
42+
43+ public function testIpv6 ()
44+ {
45+ $ IP2Location = new IP2LocationCoresController ();
46+ $ this ->assertTrue ($ IP2Location ->isIpv6 ('2001:4860:4860::8888 ' ));
47+ }
48+
49+ public function testInvalidIpv6 ()
50+ {
51+ $ IP2Location = new IP2LocationCoresController ();
52+ $ this ->assertFalse ($ IP2Location ->isIpv6 ('2001:4860:4860::ZZZZ ' ));
53+ }
54+
55+ public function testIpv4Decimal ()
56+ {
57+ $ IP2Location = new IP2LocationCoresController ();
58+ $ this ->assertEquals (
59+ 134744072 ,
60+ $ IP2Location ->ipv4ToDecimal ('8.8.8.8 ' )
61+ );
62+ }
63+
64+ public function testDecimalIpv4 ()
65+ {
66+ $ IP2Location = new IP2LocationCoresController ();
67+ $ this ->assertEquals (
68+ '8.8.8.8 ' ,
69+ $ IP2Location ->decimalToIpv4 ('134744072 ' )
70+ );
71+ }
72+
73+ public function testIpv6Decimal ()
74+ {
75+ $ IP2Location = new IP2LocationCoresController ();
76+ $ this ->assertEquals (
77+ '42541956123769884636017138956568135816 ' ,
78+ $ IP2Location ->ipv6ToDecimal ('2001:4860:4860::8888 ' )
79+ );
80+ }
81+
82+ public function testDecimalIpv6 ()
83+ {
84+ $ IP2Location = new IP2LocationCoresController ();
85+ $ this ->assertEquals (
86+ '2001:4860:4860::8888 ' ,
87+ $ IP2Location ->decimalToIpv6 ('42541956123769884636017138956568135816 ' )
88+ );
89+ }
90+
91+ public function testIpv4ToCidr ()
92+ {
93+ $ IP2Location = new IP2LocationCoresController ();
94+ $ this ->assertEqualsCanonicalizing (
95+ ['8.0.0.0/8 ' ],
96+ $ IP2Location ->ipv4ToCidr ('8.0.0.0 ' , '8.255.255.255 ' )
97+ );
98+ }
99+
100+ public function testCidrToIpv4 ()
101+ {
102+ $ IP2Location = new IP2LocationCoresController ();
103+ $ this ->assertEqualsCanonicalizing (
104+ [
105+ 'ip_start ' => '8.0.0.0 ' ,
106+ 'ip_end ' => '8.255.255.255 ' ,
107+ ],
108+ $ IP2Location ->cidrToIpv4 ('8.0.0.0/8 ' )
109+ );
110+ }
111+
112+ public function testIpv6ToCidr ()
113+ {
114+ $ IP2Location = new IP2LocationCoresController ();
115+ $ this ->assertEqualsCanonicalizing (
116+ [
117+ '2002::1234:abcd:ffff:c0a8:0/109 ' ,
118+ '2002::1234:abcd:ffff:c0b0:0/108 ' ,
119+ '2002::1234:abcd:ffff:c0c0:0/106 ' ,
120+ '2002::1234:abcd:ffff:c100:0/104 ' ,
121+ '2002::1234:abcd:ffff:c200:0/103 ' ,
122+ '2002::1234:abcd:ffff:c400:0/102 ' ,
123+ '2002::1234:abcd:ffff:c800:0/101 ' ,
124+ '2002::1234:abcd:ffff:d000:0/100 ' ,
125+ '2002::1234:abcd:ffff:e000:0/99 ' ,
126+ '2002:0:0:1234:abce::/79 ' ,
127+ '2002:0:0:1234:abd0::/76 ' ,
128+ '2002:0:0:1234:abe0::/75 ' ,
129+ '2002:0:0:1234:ac00::/70 ' ,
130+ '2002:0:0:1234:b000::/68 ' ,
131+ '2002:0:0:1234:c000::/66 ' ,
132+ ],
133+ $ IP2Location ->ipv6ToCidr ('2002:0000:0000:1234:abcd:ffff:c0a8:0000 ' , '2002:0000:0000:1234:ffff:ffff:ffff:ffff ' )
134+ );
135+ }
136+
137+ public function testCidrToIpv6 ()
138+ {
139+ $ IP2Location = new IP2LocationCoresController ();
140+ $ this ->assertEqualsCanonicalizing (
141+ [
142+ 'ip_start ' => '2002:0000:0000:1234:abcd:ffff:c0a8:0101 ' ,
143+ 'ip_end ' => '2002:0000:0000:1234:ffff:ffff:ffff:ffff ' ,
144+ ],
145+ $ IP2Location ->cidrToIpv6 ('2002::1234:abcd:ffff:c0a8:101/64 ' )
146+ );
147+ }
148+
149+ public function testCompressIpv6 ()
150+ {
151+ $ IP2Location = new IP2LocationCoresController ();
152+ $ this ->assertEquals (
153+ '2002::1234:ffff:ffff:ffff:ffff ' ,
154+ $ IP2Location ->compressIpv6 ('2002:0000:0000:1234:ffff:ffff:ffff:ffff ' )
155+ );
156+ }
157+
158+ public function testExpandIpv6 ()
159+ {
160+ $ IP2Location = new IP2LocationCoresController ();
161+ $ this ->assertEquals (
162+ '2002:0000:0000:1234:ffff:ffff:ffff:ffff ' ,
163+ $ IP2Location ->expandIpv6 ('2002::1234:ffff:ffff:ffff:ffff ' )
164+ );
165+ }
30166}
0 commit comments