This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Copyright 2016 Facebook, Inc. |
||
4 | * |
||
5 | * You are hereby granted a non-exclusive, worldwide, royalty-free license to |
||
6 | * use, copy, modify, and distribute this software in source code or binary |
||
7 | * form for use in connection with the web services and APIs provided by |
||
8 | * Facebook. |
||
9 | * |
||
10 | * As with any software that integrates with the Facebook platform, your use |
||
11 | * of this software is subject to the Facebook Developer Principles and |
||
12 | * Policies [http://developers.facebook.com/policy/]. This copyright notice |
||
13 | * shall be included in all copies or substantial portions of the software. |
||
14 | * |
||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
21 | * DEALINGS IN THE SOFTWARE. |
||
22 | * |
||
23 | */ |
||
24 | namespace Facebook\Tests\GraphNodes; |
||
25 | |||
26 | use Facebook\FacebookApp; |
||
27 | use Facebook\FacebookRequest; |
||
28 | use Facebook\FacebookResponse; |
||
29 | use Facebook\GraphNodes\GraphNodeFactory; |
||
30 | |||
31 | class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase |
||
32 | { |
||
33 | /** |
||
34 | * @var \Facebook\FacebookRequest |
||
35 | */ |
||
36 | protected $request; |
||
37 | |||
38 | View Code Duplication | protected function setUp() |
|
0 ignored issues
–
show
|
|||
39 | { |
||
40 | $app = new FacebookApp('123', 'foo_app_secret'); |
||
41 | $this->request = new FacebookRequest( |
||
42 | $app, |
||
43 | 'foo_token', |
||
44 | 'GET', |
||
45 | '/me/photos?keep=me', |
||
46 | ['foo' => 'bar'], |
||
47 | 'foo_eTag', |
||
48 | 'v1337' |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | View Code Duplication | public function testAValidGraphNodeResponseWillNotThrow() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
53 | { |
||
54 | $data = '{"id":"123","name":"foo"}'; |
||
55 | $res = new FacebookResponse($this->request, $data); |
||
56 | |||
57 | $factory = new GraphNodeFactory($res); |
||
58 | $factory->validateResponseCastableAsGraphNode(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
63 | */ |
||
64 | View Code Duplication | public function testANonGraphNodeResponseWillThrow() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
65 | { |
||
66 | $data = '{"data":[{"id":"123","name":"foo"},{"id":"1337","name":"bar"}]}'; |
||
67 | $res = new FacebookResponse($this->request, $data); |
||
68 | |||
69 | $factory = new GraphNodeFactory($res); |
||
70 | $factory->validateResponseCastableAsGraphNode(); |
||
71 | } |
||
72 | |||
73 | View Code Duplication | public function testAValidGraphEdgeResponseWillNotThrow() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
74 | { |
||
75 | $data = '{"data":[{"id":"123","name":"foo"},{"id":"1337","name":"bar"}]}'; |
||
76 | $res = new FacebookResponse($this->request, $data); |
||
77 | |||
78 | $factory = new GraphNodeFactory($res); |
||
79 | $factory->validateResponseCastableAsGraphEdge(); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
84 | */ |
||
85 | View Code Duplication | public function testANonGraphEdgeResponseWillThrow() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
86 | { |
||
87 | $data = '{"id":"123","name":"foo"}'; |
||
88 | $res = new FacebookResponse($this->request, $data); |
||
89 | |||
90 | $factory = new GraphNodeFactory($res); |
||
91 | $factory->validateResponseCastableAsGraphEdge(); |
||
92 | } |
||
93 | |||
94 | public function testOnlyNumericArraysAreCastableAsAGraphEdge() |
||
95 | { |
||
96 | $shouldPassOne = GraphNodeFactory::isCastableAsGraphEdge([]); |
||
97 | $shouldPassTwo = GraphNodeFactory::isCastableAsGraphEdge(['foo', 'bar']); |
||
98 | $shouldFail = GraphNodeFactory::isCastableAsGraphEdge(['faz' => 'baz']); |
||
99 | |||
100 | $this->assertTrue($shouldPassOne, 'Expected the given array to be castable as a GraphEdge.'); |
||
101 | $this->assertTrue($shouldPassTwo, 'Expected the given array to be castable as a GraphEdge.'); |
||
102 | $this->assertFalse($shouldFail, 'Expected the given array to not be castable as a GraphEdge.'); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
107 | */ |
||
108 | public function testInvalidSubClassesWillThrow() |
||
109 | { |
||
110 | GraphNodeFactory::validateSubclass('FooSubClass'); |
||
111 | } |
||
112 | |||
113 | public function testValidSubClassesWillNotThrow() |
||
114 | { |
||
115 | GraphNodeFactory::validateSubclass('\Facebook\GraphNodes\GraphNode'); |
||
116 | GraphNodeFactory::validateSubclass('\Facebook\GraphNodes\GraphAlbum'); |
||
117 | GraphNodeFactory::validateSubclass('\Facebook\Tests\Fixtures\MyFooGraphNode'); |
||
118 | } |
||
119 | |||
120 | public function testCastingAsASubClassObjectWillInstantiateTheSubClass() |
||
121 | { |
||
122 | $data = '{"id":"123","name":"foo"}'; |
||
123 | $res = new FacebookResponse($this->request, $data); |
||
124 | |||
125 | $factory = new GraphNodeFactory($res); |
||
126 | $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode'); |
||
127 | |||
128 | $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject); |
||
129 | } |
||
130 | |||
131 | public function testASubClassMappingWillAutomaticallyInstantiateSubClass() |
||
132 | { |
||
133 | $data = '{"id":"123","name":"Foo Name","foo_object":{"id":"1337","name":"Should be sub classed!"}}'; |
||
134 | $res = new FacebookResponse($this->request, $data); |
||
135 | |||
136 | $factory = new GraphNodeFactory($res); |
||
137 | $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode'); |
||
138 | $fooObject = $mySubClassObject->getField('foo_object'); |
||
139 | |||
140 | $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject); |
||
141 | $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooSubClassGraphNode', $fooObject); |
||
142 | } |
||
143 | |||
144 | View Code Duplication | public function testAnUnknownGraphNodeWillBeCastAsAGenericGraphNode() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
145 | { |
||
146 | $data = json_encode([ |
||
147 | 'id' => '123', |
||
148 | 'name' => 'Foo Name', |
||
149 | 'unknown_object' => [ |
||
150 | 'id' => '1337', |
||
151 | 'name' => 'Should be generic!', |
||
152 | ], |
||
153 | ]); |
||
154 | $res = new FacebookResponse($this->request, $data); |
||
155 | |||
156 | $factory = new GraphNodeFactory($res); |
||
157 | |||
158 | $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode'); |
||
159 | $unknownObject = $mySubClassObject->getField('unknown_object'); |
||
160 | |||
161 | $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject); |
||
162 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $unknownObject); |
||
163 | $this->assertNotInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $unknownObject); |
||
164 | } |
||
165 | |||
166 | View Code Duplication | public function testAListFromGraphWillBeCastAsAGraphEdge() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
167 | { |
||
168 | $data = json_encode([ |
||
169 | 'data' => [ |
||
170 | [ |
||
171 | 'id' => '123', |
||
172 | 'name' => 'Foo McBar', |
||
173 | 'link' => 'http://facebook/foo', |
||
174 | ], |
||
175 | [ |
||
176 | 'id' => '1337', |
||
177 | 'name' => 'Bar McBaz', |
||
178 | 'link' => 'http://facebook/bar', |
||
179 | ], |
||
180 | ], |
||
181 | 'paging' => [ |
||
182 | 'next' => 'http://facebook/next', |
||
183 | 'previous' => 'http://facebook/prev', |
||
184 | ], |
||
185 | ]); |
||
186 | $res = new FacebookResponse($this->request, $data); |
||
187 | |||
188 | $factory = new GraphNodeFactory($res); |
||
189 | $graphEdge = $factory->makeGraphEdge(); |
||
190 | $graphData = $graphEdge->asArray(); |
||
191 | |||
192 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphEdge', $graphEdge); |
||
193 | $this->assertEquals([ |
||
194 | 'id' => '123', |
||
195 | 'name' => 'Foo McBar', |
||
196 | 'link' => 'http://facebook/foo', |
||
197 | ], $graphData[0]); |
||
198 | $this->assertEquals([ |
||
199 | 'id' => '1337', |
||
200 | 'name' => 'Bar McBaz', |
||
201 | 'link' => 'http://facebook/bar', |
||
202 | ], $graphData[1]); |
||
203 | } |
||
204 | |||
205 | View Code Duplication | public function testAGraphNodeWillBeCastAsAGraphNode() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
206 | { |
||
207 | $data = json_encode([ |
||
208 | 'id' => '123', |
||
209 | 'name' => 'Foo McBar', |
||
210 | 'link' => 'http://facebook/foo', |
||
211 | ]); |
||
212 | $res = new FacebookResponse($this->request, $data); |
||
213 | |||
214 | $factory = new GraphNodeFactory($res); |
||
215 | $graphNode = $factory->makeGraphNode(); |
||
216 | $graphData = $graphNode->asArray(); |
||
217 | |||
218 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $graphNode); |
||
219 | $this->assertEquals([ |
||
220 | 'id' => '123', |
||
221 | 'name' => 'Foo McBar', |
||
222 | 'link' => 'http://facebook/foo', |
||
223 | ], $graphData); |
||
224 | } |
||
225 | |||
226 | View Code Duplication | public function testAGraphNodeWithARootDataKeyWillBeCastAsAGraphNode() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
227 | { |
||
228 | $data = json_encode([ |
||
229 | 'data' => [ |
||
230 | 'id' => '123', |
||
231 | 'name' => 'Foo McBar', |
||
232 | 'link' => 'http://facebook/foo', |
||
233 | ], |
||
234 | ]); |
||
235 | |||
236 | $res = new FacebookResponse($this->request, $data); |
||
237 | |||
238 | $factory = new GraphNodeFactory($res); |
||
239 | $graphNode = $factory->makeGraphNode(); |
||
240 | $graphData = $graphNode->asArray(); |
||
241 | |||
242 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $graphNode); |
||
243 | $this->assertEquals([ |
||
244 | 'id' => '123', |
||
245 | 'name' => 'Foo McBar', |
||
246 | 'link' => 'http://facebook/foo', |
||
247 | ], $graphData); |
||
248 | } |
||
249 | |||
250 | public function testAGraphEdgeWillBeCastRecursively() |
||
251 | { |
||
252 | $someUser = [ |
||
253 | 'id' => '123', |
||
254 | 'name' => 'Foo McBar', |
||
255 | ]; |
||
256 | $likesCollection = [ |
||
257 | 'data' => [ |
||
258 | [ |
||
259 | 'id' => '1', |
||
260 | 'name' => 'Sammy Kaye Powers', |
||
261 | 'is_sexy' => true, |
||
262 | ], |
||
263 | [ |
||
264 | 'id' => '2', |
||
265 | 'name' => 'Yassine Guedidi', |
||
266 | 'is_sexy' => true, |
||
267 | ], |
||
268 | [ |
||
269 | 'id' => '3', |
||
270 | 'name' => 'Fosco Marotto', |
||
271 | 'is_sexy' => true, |
||
272 | ], |
||
273 | [ |
||
274 | 'id' => '4', |
||
275 | 'name' => 'Foo McUgly', |
||
276 | 'is_sexy' => false, |
||
277 | ], |
||
278 | ], |
||
279 | 'paging' => [ |
||
280 | 'next' => 'http://facebook/next_likes', |
||
281 | 'previous' => 'http://facebook/prev_likes', |
||
282 | ], |
||
283 | ]; |
||
284 | $commentsCollection = [ |
||
285 | 'data' => [ |
||
286 | [ |
||
287 | 'id' => '42_1', |
||
288 | 'from' => $someUser, |
||
289 | 'message' => 'Foo comment.', |
||
290 | 'created_time' => '2014-07-15T03:54:34+0000', |
||
291 | 'likes' => $likesCollection, |
||
292 | ], |
||
293 | [ |
||
294 | 'id' => '42_2', |
||
295 | 'from' => $someUser, |
||
296 | 'message' => 'Bar comment.', |
||
297 | 'created_time' => '2014-07-15T04:11:24+0000', |
||
298 | 'likes' => $likesCollection, |
||
299 | ], |
||
300 | ], |
||
301 | 'paging' => [ |
||
302 | 'next' => 'http://facebook/next_comments', |
||
303 | 'previous' => 'http://facebook/prev_comments', |
||
304 | ], |
||
305 | ]; |
||
306 | $dataFromGraph = [ |
||
307 | 'data' => [ |
||
308 | [ |
||
309 | 'id' => '1337_1', |
||
310 | 'from' => $someUser, |
||
311 | 'story' => 'Some great foo story.', |
||
312 | 'likes' => $likesCollection, |
||
313 | 'comments' => $commentsCollection, |
||
314 | ], |
||
315 | [ |
||
316 | 'id' => '1337_2', |
||
317 | 'from' => $someUser, |
||
318 | 'to' => [ |
||
319 | 'data' => [$someUser], |
||
320 | ], |
||
321 | 'message' => 'Some great bar message.', |
||
322 | 'likes' => $likesCollection, |
||
323 | 'comments' => $commentsCollection, |
||
324 | ], |
||
325 | ], |
||
326 | 'paging' => [ |
||
327 | 'next' => 'http://facebook/next', |
||
328 | 'previous' => 'http://facebook/prev', |
||
329 | ], |
||
330 | ]; |
||
331 | $data = json_encode($dataFromGraph); |
||
332 | $res = new FacebookResponse($this->request, $data); |
||
333 | |||
334 | $factory = new GraphNodeFactory($res); |
||
335 | $graphNode = $factory->makeGraphEdge(); |
||
336 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphEdge', $graphNode); |
||
337 | |||
338 | // Story |
||
339 | $storyObject = $graphNode[0]; |
||
340 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $storyObject['from']); |
||
341 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphEdge', $storyObject['likes']); |
||
342 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphEdge', $storyObject['comments']); |
||
343 | |||
344 | // Story Comments |
||
345 | $storyComments = $storyObject['comments']; |
||
346 | $firstStoryComment = $storyComments[0]; |
||
347 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $firstStoryComment['from']); |
||
348 | |||
349 | // Message |
||
350 | $messageObject = $graphNode[1]; |
||
351 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphEdge', $messageObject['to']); |
||
352 | $toUsers = $messageObject['to']; |
||
353 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $toUsers[0]); |
||
354 | } |
||
355 | |||
356 | public function testAGraphEdgeWillGenerateTheProperParentGraphEdges() |
||
357 | { |
||
358 | $likesList = [ |
||
359 | 'data' => [ |
||
360 | [ |
||
361 | 'id' => '1', |
||
362 | 'name' => 'Sammy Kaye Powers', |
||
363 | ], |
||
364 | ], |
||
365 | 'paging' => [ |
||
366 | 'cursors' => [ |
||
367 | 'after' => 'like_after_cursor', |
||
368 | 'before' => 'like_before_cursor', |
||
369 | ], |
||
370 | ], |
||
371 | ]; |
||
372 | |||
373 | $photosList = [ |
||
374 | 'data' => [ |
||
375 | [ |
||
376 | 'id' => '777', |
||
377 | 'name' => 'Foo Photo', |
||
378 | 'likes' => $likesList, |
||
379 | ], |
||
380 | ], |
||
381 | 'paging' => [ |
||
382 | 'cursors' => [ |
||
383 | 'after' => 'photo_after_cursor', |
||
384 | 'before' => 'photo_before_cursor', |
||
385 | ], |
||
386 | ], |
||
387 | ]; |
||
388 | |||
389 | $data = json_encode([ |
||
390 | 'data' => [ |
||
391 | [ |
||
392 | 'id' => '111', |
||
393 | 'name' => 'Foo McBar', |
||
394 | 'likes' => $likesList, |
||
395 | 'photos' => $photosList, |
||
396 | ], |
||
397 | [ |
||
398 | 'id' => '222', |
||
399 | 'name' => 'Bar McBaz', |
||
400 | 'likes' => $likesList, |
||
401 | 'photos' => $photosList, |
||
402 | ], |
||
403 | ], |
||
404 | 'paging' => [ |
||
405 | 'next' => 'http://facebook/next', |
||
406 | 'previous' => 'http://facebook/prev', |
||
407 | ], |
||
408 | ]); |
||
409 | $res = new FacebookResponse($this->request, $data); |
||
410 | |||
411 | $factory = new GraphNodeFactory($res); |
||
412 | $graphEdge = $factory->makeGraphEdge(); |
||
413 | $topGraphEdge = $graphEdge->getParentGraphEdge(); |
||
414 | $childGraphEdgeOne = $graphEdge[0]['likes']->getParentGraphEdge(); |
||
415 | $childGraphEdgeTwo = $graphEdge[1]['likes']->getParentGraphEdge(); |
||
416 | $childGraphEdgeThree = $graphEdge[1]['photos']->getParentGraphEdge(); |
||
417 | $childGraphEdgeFour = $graphEdge[1]['photos'][0]['likes']->getParentGraphEdge(); |
||
418 | |||
419 | $this->assertNull($topGraphEdge); |
||
420 | $this->assertEquals('/111/likes', $childGraphEdgeOne); |
||
421 | $this->assertEquals('/222/likes', $childGraphEdgeTwo); |
||
422 | $this->assertEquals('/222/photos', $childGraphEdgeThree); |
||
423 | $this->assertEquals('/777/likes', $childGraphEdgeFour); |
||
424 | } |
||
425 | } |
||
426 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.