@@ 307-342 (lines=36) @@ | ||
304 | $this->assertSame($expectedJson, $scope->toJson()); |
|
305 | } |
|
306 | ||
307 | public function testSerializingItemResourceWithMeta() |
|
308 | { |
|
309 | $bookData = [ |
|
310 | 'id' => 1, |
|
311 | 'title' => 'Foo', |
|
312 | 'year' => '1991', |
|
313 | '_author' => [ |
|
314 | 'id' => 1, |
|
315 | 'name' => 'Dave', |
|
316 | ], |
|
317 | ]; |
|
318 | ||
319 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
320 | $resource->setMetaValue('foo', 'bar'); |
|
321 | ||
322 | $scope = new Scope($this->manager, $resource); |
|
323 | ||
324 | $expected = [ |
|
325 | 'data' => [ |
|
326 | 'type' => 'books', |
|
327 | 'id' => '1', |
|
328 | 'attributes' => [ |
|
329 | 'title' => 'Foo', |
|
330 | 'year' => 1991, |
|
331 | ], |
|
332 | ], |
|
333 | 'meta' => [ |
|
334 | 'foo' => 'bar', |
|
335 | ], |
|
336 | ]; |
|
337 | ||
338 | $this->assertSame($expected, $scope->toArray()); |
|
339 | ||
340 | $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991}},"meta":{"foo":"bar"}}'; |
|
341 | $this->assertSame($expectedJson, $scope->toJson()); |
|
342 | } |
|
343 | ||
344 | public function testSerializingCollectionResourceWithoutIncludes() |
|
345 | { |
|
@@ 985-1022 (lines=38) @@ | ||
982 | $this->assertSame($expectedJson, $scope->toJson()); |
|
983 | } |
|
984 | ||
985 | public function testSerializingItemResourceWithSelfLink() |
|
986 | { |
|
987 | $baseUrl = 'http://example.com'; |
|
988 | $this->manager->setSerializer(new JsonApiSerializer($baseUrl)); |
|
989 | ||
990 | $bookData = [ |
|
991 | 'id' => 1, |
|
992 | 'title' => 'Foo', |
|
993 | 'year' => '1991', |
|
994 | '_author' => [ |
|
995 | 'id' => 1, |
|
996 | 'name' => 'Dave', |
|
997 | ], |
|
998 | ]; |
|
999 | ||
1000 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
1001 | ||
1002 | $scope = new Scope($this->manager, $resource); |
|
1003 | ||
1004 | $expected = [ |
|
1005 | 'data' => [ |
|
1006 | 'type' => 'books', |
|
1007 | 'id' => '1', |
|
1008 | 'attributes' => [ |
|
1009 | 'title' => 'Foo', |
|
1010 | 'year' => 1991, |
|
1011 | ], |
|
1012 | 'links' => [ |
|
1013 | 'self' => 'http://example.com/books/1', |
|
1014 | ], |
|
1015 | ], |
|
1016 | ]; |
|
1017 | ||
1018 | $this->assertSame($expected, $scope->toArray()); |
|
1019 | ||
1020 | $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"links":{"self":"http:\/\/example.com\/books\/1"}}}'; |
|
1021 | $this->assertSame($expectedJson, $scope->toJson()); |
|
1022 | } |
|
1023 | ||
1024 | public function testSerializingCollectionResourceWithSelfLink() |
|
1025 | { |