@@ -11,14 +11,71 @@ require __DIR__ . '/bootstrap.php';
1111class PhpInfoTest extends TestCase
1212{
1313
14+ private const SESSION_ID = 'foobar,baz ' ;
15+ private const WALDO_1337 = 'waldo-fred-1337 ' ;
16+ private const WALDO_1338 = 'waldo-quux-1338 ' ;
17+
18+
19+ protected function setUp (): void
20+ {
21+ $ _SERVER ['HTTP_WALDO_FRED ' ] = self ::WALDO_1337 ;
22+ $ _SERVER ['HTTP_COOKIE ' ] = 'PHPSESSID= ' . urlencode (self ::SESSION_ID );
23+ $ _COOKIE ['PHPSESSID ' ] = self ::SESSION_ID ;
24+
25+ session_set_save_handler (new TestSessionHandler (self ::SESSION_ID ));
26+ session_start ();
27+ }
28+
29+
30+ protected function tearDown (): void
31+ {
32+ session_destroy ();
33+ }
34+
35+
1436 public function testGetHtml (): void
1537 {
16- $ phpInfo = new PhpInfo ();
17- $ html = $ phpInfo ->getHtml ();
38+ $ html = (new PhpInfo ())->getHtml ();
1839 Assert::contains ('<div id="phpinfo"> ' , $ html );
1940 Assert::contains ('disable_functions ' , $ html );
2041 }
2142
43+
44+ public function testGetHtmlSessionIdSanitization (): void
45+ {
46+ $ html = (new PhpInfo ())->getHtml ();
47+ Assert::notContains (self ::SESSION_ID , $ html );
48+ Assert::notContains (urlencode (self ::SESSION_ID ), $ html );
49+ Assert::contains ('[***] ' , $ html );
50+ }
51+
52+
53+ public function testGetHtmlSessionIdSanitizationCustomReplacement (): void
54+ {
55+ $ phpInfo = new PhpInfo ();
56+ $ phpInfo ->addSanitization (self ::SESSION_ID , 'yeah, sure ' );
57+ Assert::contains ('yeah, sure ' , $ phpInfo ->getHtml ());
58+ }
59+
60+
61+ public function testGetHtmlDoNotSanitizeSessionIdButWhy (): void
62+ {
63+ $ phpInfo = new PhpInfo ();
64+ $ html = $ phpInfo ->doNotSanitizeSessionId ()->getHtml ();
65+ Assert::contains (self ::SESSION_ID , $ html );
66+ Assert::contains (urlencode (self ::SESSION_ID ), $ html );
67+ }
68+
69+
70+ public function testGetHtmlAddSanitization (): void
71+ {
72+ $ phpInfo = new PhpInfo ();
73+ Assert::contains (self ::WALDO_1337 , $ phpInfo ->getHtml ());
74+ $ html = $ phpInfo ->addSanitization (self ::WALDO_1337 , self ::WALDO_1338 )->getHtml ();
75+ Assert::notContains (self ::WALDO_1337 , $ html );
76+ Assert::contains (self ::WALDO_1338 , $ html );
77+ }
78+
2279}
2380
2481(new PhpInfoTest ())->run ();
0 commit comments