Conditions | 1 |
Paths | 1 |
Total Lines | 168 |
Code Lines | 119 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
93 | public function testAllowedActions() |
||
94 | { |
||
95 | $adminUser = $this->objFromFixture(Member::class, 'admin'); |
||
96 | |||
97 | $response = $this->get("UnsecuredController/"); |
||
98 | $this->assertEquals( |
||
99 | 200, |
||
100 | $response->getStatusCode(), |
||
101 | 'Access granted on index action without $allowed_actions on defining controller, ' . 'when called without an action in the URL' |
||
102 | ); |
||
103 | |||
104 | $response = $this->get("UnsecuredController/index"); |
||
105 | $this->assertEquals( |
||
106 | 200, |
||
107 | $response->getStatusCode(), |
||
108 | 'Access denied on index action without $allowed_actions on defining controller, ' . 'when called with an action in the URL' |
||
109 | ); |
||
110 | |||
111 | $response = $this->get("UnsecuredController/method1"); |
||
112 | $this->assertEquals( |
||
113 | 403, |
||
114 | $response->getStatusCode(), |
||
115 | 'Access denied on action without $allowed_actions on defining controller, ' . 'when called without an action in the URL' |
||
116 | ); |
||
117 | |||
118 | $response = $this->get("AccessBaseController/"); |
||
119 | $this->assertEquals( |
||
120 | 200, |
||
121 | $response->getStatusCode(), |
||
122 | 'Access granted on index with empty $allowed_actions on defining controller, ' . 'when called without an action in the URL' |
||
123 | ); |
||
124 | |||
125 | $response = $this->get("AccessBaseController/index"); |
||
126 | $this->assertEquals( |
||
127 | 200, |
||
128 | $response->getStatusCode(), |
||
129 | 'Access granted on index with empty $allowed_actions on defining controller, ' . 'when called with an action in the URL' |
||
130 | ); |
||
131 | |||
132 | $response = $this->get("AccessBaseController/method1"); |
||
133 | $this->assertEquals( |
||
134 | 403, |
||
135 | $response->getStatusCode(), |
||
136 | 'Access denied on action with empty $allowed_actions on defining controller' |
||
137 | ); |
||
138 | |||
139 | $response = $this->get("AccessBaseController/method2"); |
||
140 | $this->assertEquals( |
||
141 | 403, |
||
142 | $response->getStatusCode(), |
||
143 | 'Access denied on action with empty $allowed_actions on defining controller, ' . 'even when action is allowed in subclasses (allowed_actions don\'t inherit)' |
||
144 | ); |
||
145 | |||
146 | $response = $this->get("AccessSecuredController/"); |
||
147 | $this->assertEquals( |
||
148 | 200, |
||
149 | $response->getStatusCode(), |
||
150 | 'Access granted on index with non-empty $allowed_actions on defining controller, ' . 'even when index isn\'t specifically mentioned in there' |
||
151 | ); |
||
152 | |||
153 | $response = $this->get("AccessSecuredController/method1"); |
||
154 | $this->assertEquals( |
||
155 | 403, |
||
156 | $response->getStatusCode(), |
||
157 | 'Access denied on action which is only defined in parent controller, ' . 'even when action is allowed in currently called class (allowed_actions don\'t inherit)' |
||
158 | ); |
||
159 | |||
160 | $response = $this->get("AccessSecuredController/method2"); |
||
161 | $this->assertEquals( |
||
162 | 200, |
||
163 | $response->getStatusCode(), |
||
164 | 'Access granted on action originally defined with empty $allowed_actions on parent controller, ' . 'because it has been redefined in the subclass' |
||
165 | ); |
||
166 | |||
167 | $response = $this->get("AccessSecuredController/templateaction"); |
||
168 | $this->assertEquals( |
||
169 | 403, |
||
170 | $response->getStatusCode(), |
||
171 | 'Access denied on action with $allowed_actions on defining controller, ' . 'if action is not a method but rather a template discovered by naming convention' |
||
172 | ); |
||
173 | |||
174 | $response = $this->get("AccessSecuredController/templateaction"); |
||
175 | $this->assertEquals( |
||
176 | 403, |
||
177 | $response->getStatusCode(), |
||
178 | 'Access denied on action with $allowed_actions on defining controller, ' . 'if action is not a method but rather a template discovered by naming convention' |
||
179 | ); |
||
180 | |||
181 | Member::actAs($adminUser, function () { |
||
182 | $response = $this->get("AccessSecuredController/templateaction"); |
||
183 | $this->assertEquals( |
||
184 | 200, |
||
185 | $response->getStatusCode(), |
||
186 | 'Access granted for logged in admin on action with $allowed_actions on defining controller, ' . 'if action is not a method but rather a template discovered by naming convention' |
||
187 | ); |
||
188 | }); |
||
189 | |||
190 | $response = $this->get("AccessSecuredController/adminonly"); |
||
191 | $this->assertEquals( |
||
192 | 403, |
||
193 | $response->getStatusCode(), |
||
194 | 'Access denied on action with $allowed_actions on defining controller, ' . 'when restricted by unmatched permission code' |
||
195 | ); |
||
196 | |||
197 | $response = $this->get("AccessSecuredController/aDmiNOnlY"); |
||
198 | $this->assertEquals( |
||
199 | 403, |
||
200 | $response->getStatusCode(), |
||
201 | 'Access denied on action with $allowed_actions on defining controller, ' . 'regardless of capitalization' |
||
202 | ); |
||
203 | |||
204 | $response = $this->get('AccessSecuredController/protectedmethod'); |
||
205 | $this->assertEquals( |
||
206 | 404, |
||
207 | $response->getStatusCode(), |
||
208 | "Access denied to protected method even if its listed in allowed_actions" |
||
209 | ); |
||
210 | |||
211 | Member::actAs($adminUser, function () { |
||
212 | $response = $this->get("AccessSecuredController/adminonly"); |
||
213 | $this->assertEquals( |
||
214 | 200, |
||
215 | $response->getStatusCode(), |
||
216 | "Permission codes are respected when set in \$allowed_actions" |
||
217 | ); |
||
218 | }); |
||
219 | |||
220 | $response = $this->get('AccessBaseController/extensionmethod1'); |
||
221 | $this->assertEquals( |
||
222 | 200, |
||
223 | $response->getStatusCode(), |
||
224 | "Access granted to method defined in allowed_actions on extension, " . "where method is also defined on extension" |
||
225 | ); |
||
226 | |||
227 | $response = $this->get('AccessSecuredController/extensionmethod1'); |
||
228 | $this->assertEquals( |
||
229 | 200, |
||
230 | $response->getStatusCode(), |
||
231 | "Access granted to method defined in allowed_actions on extension, " . "where method is also defined on extension, even when called in a subclass" |
||
232 | ); |
||
233 | |||
234 | $response = $this->get('AccessBaseController/extensionmethod2'); |
||
235 | $this->assertEquals( |
||
236 | 404, |
||
237 | $response->getStatusCode(), |
||
238 | "Access denied to method not defined in allowed_actions on extension, " . "where method is also defined on extension" |
||
239 | ); |
||
240 | |||
241 | $response = $this->get('IndexSecuredController/'); |
||
242 | $this->assertEquals( |
||
243 | 403, |
||
244 | $response->getStatusCode(), |
||
245 | "Access denied when index action is limited through allowed_actions, " . "and doesn't satisfy checks, and action is empty" |
||
246 | ); |
||
247 | |||
248 | $response = $this->get('IndexSecuredController/index'); |
||
249 | $this->assertEquals( |
||
250 | 403, |
||
251 | $response->getStatusCode(), |
||
252 | "Access denied when index action is limited through allowed_actions, " . "and doesn't satisfy checks" |
||
253 | ); |
||
254 | |||
255 | Member::actAs($adminUser, function () { |
||
256 | $response = $this->get('IndexSecuredController/'); |
||
257 | $this->assertEquals( |
||
258 | 200, |
||
259 | $response->getStatusCode(), |
||
260 | "Access granted when index action is limited through allowed_actions, " . "and does satisfy checks" |
||
261 | ); |
||
497 |