99use PHPUnit \Framework \TestCase ;
1010use FacebookAds \ParamBuilder ;
1111use FacebookAds \Constants ;
12+ use FacebookAds \AppendixProvider ;
13+
14+ require_once __DIR__ . '/../src/util/AppendixProvider.php ' ;
1215
1316final class GetClientIpTest extends TestCase
1417{
1518 private $ paramBuilder ;
1619 private $ reflection ;
20+ private $ appendix_is_new ;
21+ private $ appendix_is_normal ;
1722
1823 protected function setUp (): void
1924 {
25+ // Get the actual appendix values from AppendixProvider
26+ $ this ->appendix_is_new = AppendixProvider::getAppendix (true );
27+ $ this ->appendix_is_normal = AppendixProvider::getAppendix (false );
28+
29+ // Initialize ParamBuilder and reflection for accessing private methods
2030 $ this ->paramBuilder = new ParamBuilder ();
2131 $ this ->reflection = new ReflectionClass ($ this ->paramBuilder );
2232 }
@@ -87,7 +97,7 @@ public function testGetClientIpIPv6PublicPrioritization()
8797 self ::IPV4_PUBLIC ,
8898 null
8999 );
90- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
100+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_new , $ result );
91101
92102 // IPv6 public from request should beat IPv4 public from cookie
93103 $ result = $ this ->invokePrivateStaticMethod (
@@ -96,7 +106,7 @@ public function testGetClientIpIPv6PublicPrioritization()
96106 self ::IPV6_PUBLIC ,
97107 null
98108 );
99- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
109+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
100110
101111 // IPv6 public from cookie should beat IPv6 public from request (cookie priority)
102112 $ anotherIPv6Public = '2001:db8::1 ' ;
@@ -106,7 +116,7 @@ public function testGetClientIpIPv6PublicPrioritization()
106116 $ anotherIPv6Public ,
107117 null
108118 );
109- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
119+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_new , $ result );
110120 }
111121
112122 public function testGetClientIpIPv4PublicHandling ()
@@ -119,7 +129,7 @@ public function testGetClientIpIPv4PublicHandling()
119129 $ anotherIPv4Public ,
120130 null
121131 );
122- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
132+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_new , $ result );
123133
124134 // IPv4 public from request when no cookie available
125135 $ result = $ this ->invokePrivateStaticMethod (
@@ -128,7 +138,7 @@ public function testGetClientIpIPv4PublicHandling()
128138 self ::IPV4_PUBLIC ,
129139 null
130140 );
131- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
141+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
132142
133143 // IPv4 public from remote address when no other sources
134144 $ result = $ this ->invokePrivateStaticMethod (
@@ -137,7 +147,7 @@ public function testGetClientIpIPv4PublicHandling()
137147 null ,
138148 self ::IPV4_PUBLIC
139149 );
140- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
150+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
141151 }
142152
143153 public function testGetClientIpPublicOverPrivatePrioritization ()
@@ -149,7 +159,7 @@ public function testGetClientIpPublicOverPrivatePrioritization()
149159 self ::IPV4_PUBLIC ,
150160 null
151161 );
152- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
162+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
153163
154164 // Public IPv4 from request should beat private IPv4 from cookie
155165 $ result = $ this ->invokePrivateStaticMethod (
@@ -158,7 +168,7 @@ public function testGetClientIpPublicOverPrivatePrioritization()
158168 self ::IPV4_PUBLIC ,
159169 null
160170 );
161- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
171+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
162172
163173 // Public IPv6 from request should beat private IPv4 from cookie
164174 $ result = $ this ->invokePrivateStaticMethod (
@@ -167,7 +177,7 @@ public function testGetClientIpPublicOverPrivatePrioritization()
167177 self ::IPV6_PUBLIC ,
168178 null
169179 );
170- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
180+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
171181 }
172182
173183 public function testGetClientIpLanguageTokenHandling ()
@@ -191,7 +201,7 @@ public function testGetClientIpLanguageTokenHandling()
191201 null ,
192202 null
193203 );
194- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
204+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_new , $ result );
195205
196206 // Should use default language token for request-sourced IPs
197207 $ result = $ this ->invokePrivateStaticMethod (
@@ -200,7 +210,7 @@ public function testGetClientIpLanguageTokenHandling()
200210 self ::IPV4_PUBLIC ,
201211 null
202212 );
203- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
213+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
204214 }
205215
206216 public function testGetClientIpFromCookieHelper ()
@@ -379,7 +389,7 @@ public function testEdgeCasesAndErrorHandling()
379389 self ::IPV4_PUBLIC ,
380390 null
381391 );
382- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
392+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
383393
384394 // Test with empty cookies array
385395 $ result = $ this ->invokePrivateStaticMethod (
@@ -388,7 +398,7 @@ public function testEdgeCasesAndErrorHandling()
388398 self ::IPV4_PUBLIC ,
389399 null
390400 );
391- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
401+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
392402
393403 // Test with empty FBI cookie value
394404 $ result = $ this ->invokePrivateStaticMethod (
@@ -397,7 +407,7 @@ public function testEdgeCasesAndErrorHandling()
397407 self ::IPV4_PUBLIC ,
398408 null
399409 );
400- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
410+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
401411
402412 // Test with whitespace in IP values
403413 $ result = $ this ->invokePrivateStaticMethod (
@@ -415,7 +425,7 @@ public function testEdgeCasesAndErrorHandling()
415425 self ::IPV4_PUBLIC ,
416426 null
417427 );
418- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
428+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
419429 }
420430
421431 public function testComplexPrioritizationScenarios ()
@@ -427,7 +437,7 @@ public function testComplexPrioritizationScenarios()
427437 self ::IPV6_PRIVATE ,
428438 null
429439 );
430- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
440+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_new , $ result );
431441
432442 // IPv4 private from cookie vs IPv6 public from request
433443 $ result = $ this ->invokePrivateStaticMethod (
@@ -436,7 +446,7 @@ public function testComplexPrioritizationScenarios()
436446 self ::IPV6_PUBLIC ,
437447 null
438448 );
439- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
449+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
440450
441451 // Mixed valid and invalid IPs
442452 $ result = $ this ->invokePrivateStaticMethod (
@@ -445,7 +455,7 @@ public function testComplexPrioritizationScenarios()
445455 self ::IPV4_PUBLIC ,
446456 self ::INVALID_IP
447457 );
448- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
458+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
449459 }
450460
451461 public function testRealWorldScenarios ()
@@ -459,7 +469,7 @@ public function testRealWorldScenarios()
459469 self ::IPV4_PUBLIC ,
460470 self ::IPV4_PRIVATE
461471 );
462- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
472+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
463473
464474 // Load balancer scenario with IPv6
465475 $ result = $ this ->invokePrivateStaticMethod (
@@ -468,7 +478,7 @@ public function testRealWorldScenarios()
468478 self ::IPV6_PUBLIC ,
469479 self ::IPV4_PRIVATE
470480 );
471- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
481+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
472482
473483 // CDN scenario with multiple forwarded IPs
474484 $ result = $ this ->invokePrivateStaticMethod (
@@ -477,7 +487,7 @@ public function testRealWorldScenarios()
477487 self ::IPV4_PUBLIC . ', 203.0.113.1, 198.51.100.1 ' ,
478488 '198.51.100.1 '
479489 );
480- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
490+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
481491
482492 // Proxy chain scenario
483493 $ result = $ this ->invokePrivateStaticMethod (
@@ -486,7 +496,7 @@ public function testRealWorldScenarios()
486496 self ::IPV6_PUBLIC ,
487497 self ::IPV4_PRIVATE
488498 );
489- $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
499+ $ this ->assertEquals (self ::IPV6_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
490500 }
491501
492502 public function testSpecialIPAddresses ()
@@ -528,7 +538,7 @@ public function testSpecialIPAddresses()
528538
529539 foreach ($ publicByPHPFilterIPv4 as $ ip ) {
530540 $ result = $ this ->invokePrivateStaticMethod ('getClientIp ' , [], $ ip , null );
531- $ this ->assertEquals ($ ip . '. ' . LANGUAGE_TOKEN , $ result , "Expected processed result for IP: $ ip " );
541+ $ this ->assertEquals ($ ip . '. ' . $ this -> appendix_is_normal , $ result , "Expected processed result for IP: $ ip " );
532542 }
533543
534544 // Test some IPv6 addresses that should be considered public
@@ -539,7 +549,7 @@ public function testSpecialIPAddresses()
539549
540550 foreach ($ publicIPv6Addresses as $ ip ) {
541551 $ result = $ this ->invokePrivateStaticMethod ('getClientIp ' , [], $ ip , null );
542- $ this ->assertEquals ($ ip . '. ' . LANGUAGE_TOKEN , $ result , "Expected processed result for IPv6: $ ip " );
552+ $ this ->assertEquals ($ ip . '. ' . $ this -> appendix_is_normal , $ result , "Expected processed result for IPv6: $ ip " );
543553 }
544554
545555 // Test IPv6 multicast addresses - PHP's filter_var treats these as public
@@ -552,7 +562,7 @@ public function testSpecialIPAddresses()
552562
553563 foreach ($ ipv6MulticastAddresses as $ ip ) {
554564 $ result = $ this ->invokePrivateStaticMethod ('getClientIp ' , [], $ ip , null );
555- $ this ->assertEquals ($ ip . '. ' . LANGUAGE_TOKEN , $ result , "Expected processed result for IPv6 multicast: $ ip " );
565+ $ this ->assertEquals ($ ip . '. ' . $ this -> appendix_is_normal , $ result , "Expected processed result for IPv6 multicast: $ ip " );
556566 }
557567 }
558568
@@ -622,7 +632,7 @@ public function testBoundaryConditions()
622632 self ::IPV4_PUBLIC ,
623633 null
624634 );
625- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
635+ $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . $ this -> appendix_is_normal , $ result );
626636
627637 // Test with empty string IP
628638 $ result = $ this ->invokePrivateStaticMethod (
@@ -657,7 +667,10 @@ public function testPerformanceConsiderations()
657667 $ originalXForwardedFor ,
658668 $ originalRemoteAddress
659669 );
660- $ this ->assertEquals (self ::IPV4_PUBLIC . '. ' . LANGUAGE_TOKEN , $ result );
670+ $ this ->assertEquals (
671+ self ::IPV4_PUBLIC . '. ' . $ this ->appendix_is_new ,
672+ $ result
673+ );
661674 }
662675
663676 // Verify inputs were not modified
0 commit comments