@@ 55-74 (lines=20) @@ | ||
52 | ); |
|
53 | } |
|
54 | ||
55 | public function testAGraphNodeWillBeCastAsAGraphNode() |
|
56 | { |
|
57 | $data = json_encode([ |
|
58 | 'id' => '123', |
|
59 | 'name' => 'Foo McBar', |
|
60 | 'link' => 'http://facebook/foo', |
|
61 | ]); |
|
62 | $res = new FacebookResponse($this->request, $data); |
|
63 | ||
64 | $factory = new GraphObjectFactory($res); |
|
65 | $graphObject = $factory->makeGraphObject(); |
|
66 | $graphData = $graphObject->asArray(); |
|
67 | ||
68 | $this->assertInstanceOf('\Facebook\GraphNodes\GraphObject', $graphObject); |
|
69 | $this->assertEquals([ |
|
70 | 'id' => '123', |
|
71 | 'name' => 'Foo McBar', |
|
72 | 'link' => 'http://facebook/foo', |
|
73 | ], $graphData); |
|
74 | } |
|
75 | ||
76 | public function testAListFromGraphWillBeCastAsAGraphEdge() |
|
77 | { |
@@ 144-164 (lines=21) @@ | ||
141 | $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooSubClassGraphNode', $fooObject); |
|
142 | } |
|
143 | ||
144 | public function testAnUnknownGraphNodeWillBeCastAsAGenericGraphNode() |
|
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 | public function testAListFromGraphWillBeCastAsAGraphEdge() |
|
167 | { |
|
@@ 205-224 (lines=20) @@ | ||
202 | ], $graphData[1]); |
|
203 | } |
|
204 | ||
205 | public function testAGraphNodeWillBeCastAsAGraphNode() |
|
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 | public function testAGraphNodeWithARootDataKeyWillBeCastAsAGraphNode() |
|
227 | { |
|
@@ 226-248 (lines=23) @@ | ||
223 | ], $graphData); |
|
224 | } |
|
225 | ||
226 | public function testAGraphNodeWithARootDataKeyWillBeCastAsAGraphNode() |
|
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 | { |