7
7
use PHPUnit \Framework \TestCase ;
8
8
9
9
class ProtectionTest extends TestCase {
10
+ public function testRemoveGlobals () {
11
+ $ globals = [
12
+ "_ENV " => [
13
+ "somekey " => "somevalue " ,
14
+ ]
15
+ ];
16
+
17
+ self ::assertArrayHasKey ("somekey " , $ globals ["_ENV " ]);
18
+ $ updated = Protection::removeGlobals ($ globals );
19
+ self ::assertArrayNotHasKey ("_ENV " , $ updated );
20
+ self ::assertNotNull ($ globals );
21
+ }
22
+
10
23
public function testOverride () {
11
24
$ env = ["somekey " => "somevalue " ];
12
- $ server = [];
13
- $ get = [];
14
- $ post = [];
15
- $ files = [];
16
- $ cookie = [];
17
- $ session = [];
18
25
$ globals = [
19
26
"_ENV " => $ env ,
20
27
];
@@ -26,54 +33,30 @@ public function testOverride() {
26
33
27
34
self ::assertEquals ("somevalue " , $ env ["somekey " ]);
28
35
29
- Protection::overrideInternals (
30
- $ globals ,
31
- $ env ,
32
- $ server ,
33
- $ get ,
34
- $ post ,
35
- $ files ,
36
- $ cookie ,
37
- $ session
38
- );
36
+ Protection::overrideInternals ($ globals );
39
37
40
- self ::assertInstanceOf (ProtectedGlobal::class, $ env );
38
+ self ::assertInstanceOf (ProtectedGlobal::class, $ _ENV );
41
39
self ::assertEquals ("somevalue " , $ env ["somekey " ]);
42
40
}
43
41
44
42
public function testWhitelist () {
45
43
$ env = ["somekey " => "somevalue " , "anotherkey " => "anothervalue " ];
46
- $ server = [];
47
- $ get = [];
48
- $ post = [];
49
- $ files = [];
50
- $ cookie = [];
51
- $ session = [];
52
44
$ globals = [
53
45
"_ENV " => $ env ,
54
46
];
55
- Protection::removeGlobals (
47
+ $ whitelist = Protection::removeGlobals (
56
48
$ globals ,
57
49
[
58
50
"_ENV " => [
59
51
"anotherkey " ,
60
52
],
61
53
]
62
54
);
63
- Protection::overrideInternals (
64
- $ globals ,
65
- $ env ,
66
- $ server ,
67
- $ get ,
68
- $ post ,
69
- $ files ,
70
- $ cookie ,
71
- $ session
72
- );
55
+ Protection::overrideInternals ($ whitelist );
73
56
74
- self ::assertEquals ("anothervalue " , $ env ["anotherkey " ]);
57
+ self ::assertEquals ("anothervalue " , $ _ENV ["anotherkey " ]);
75
58
self ::expectException (ProtectedGlobalException::class);
76
- $ variable = $ env ["somevalue " ];
59
+ $ value = $ _ENV ["somevalue " ];
77
60
}
78
61
79
62
public function testWhitelistMany () {
@@ -93,7 +76,7 @@ public function testWhitelistMany() {
93
76
94
77
Protection::removeGlobals ($ env );
95
78
Protection::removeGlobals ($ server );
96
- $ fixedGlobals = Protection::removeGlobals (
79
+ $ whitelisted = Protection::removeGlobals (
97
80
$ globals ,
98
81
[
99
82
"_GET " => [
@@ -108,55 +91,12 @@ public function testWhitelistMany() {
108
91
109
92
);
110
93
111
- Protection::overrideInternals (
112
- $ fixedGlobals ,
113
- $ env ,
114
- $ server ,
115
- $ get ,
116
- $ post ,
117
- $ files ,
118
- $ cookie ,
119
- $ session
120
- );
94
+ Protection::overrideInternals ($ whitelisted );
121
95
122
- self ::assertEquals ("Y2K " , $ get ["name " ]);
123
- self ::assertEquals ("postvalue2 " , $ post ["postkey2 " ]);
96
+ self ::assertEquals ("Y2K " , $ _GET ["name " ]);
97
+ self ::assertEquals ("postvalue2 " , $ _POST ["postkey2 " ]);
124
98
self ::expectException (ProtectedGlobalException::class);
125
- $ variable = $ post ["postkey1 " ];
126
- }
127
-
128
- public function testWhitelistNotExists () {
129
- $ env = [];
130
- $ server = [];
131
- $ get = ["name " => "Cody " , "species " => "Feline " ];
132
- $ post = [];
133
- $ files = [];
134
- $ cookie = [];
135
- $ session = [];
136
- $ globals = [
137
- "_GET " => $ get ,
138
- ];
139
- $ globals = Protection::removeGlobals (
140
- $ globals ,
141
- [
142
- "_GET " => [
143
- "name " ,
144
- "age " ,
145
- ],
146
- ]
147
- );
148
- Protection::overrideInternals (
149
- $ globals ,
150
- $ env ,
151
- $ server ,
152
- $ get ,
153
- $ post ,
154
- $ files ,
155
- $ cookie ,
156
- $ session
157
- );
158
-
159
- self ::assertEquals ("Cody " , $ get ["name " ]);
160
- self ::assertNull ($ get ["age " ]);
99
+ $ variable = $ _POST ["postkey1 " ];
100
+ var_dump ($ variable );
161
101
}
162
102
}
0 commit comments