@@ 200-254 (lines=55) @@ | ||
197 | $this->assertSame($expectedJson, $scope->toJson()); |
|
198 | } |
|
199 | ||
200 | public function testSerializingItemResourceWithHasOneDasherizedInclude() |
|
201 | { |
|
202 | $this->manager->parseIncludes('co-author'); |
|
203 | ||
204 | $bookData = [ |
|
205 | 'id' => 1, |
|
206 | 'title' => 'Foo', |
|
207 | 'year' => '1991', |
|
208 | '_author' => [ |
|
209 | 'id' => 1, |
|
210 | 'name' => 'Dave', |
|
211 | ], |
|
212 | '_co_author' => [ |
|
213 | 'id' => 2, |
|
214 | 'name' => 'Jim', |
|
215 | ], |
|
216 | ]; |
|
217 | ||
218 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
219 | ||
220 | $scope = new Scope($this->manager, $resource); |
|
221 | ||
222 | $expected = [ |
|
223 | 'data' => [ |
|
224 | 'type' => 'books', |
|
225 | 'id' => '1', |
|
226 | 'attributes' => [ |
|
227 | 'title' => 'Foo', |
|
228 | 'year' => 1991, |
|
229 | ], |
|
230 | 'relationships' => [ |
|
231 | 'co-author' => [ |
|
232 | 'data' => [ |
|
233 | 'type' => 'people', |
|
234 | 'id' => '2', |
|
235 | ], |
|
236 | ], |
|
237 | ], |
|
238 | ], |
|
239 | 'included' => [ |
|
240 | [ |
|
241 | 'type' => 'people', |
|
242 | 'id' => '2', |
|
243 | 'attributes' => [ |
|
244 | 'name' => 'Jim', |
|
245 | ], |
|
246 | ], |
|
247 | ], |
|
248 | ]; |
|
249 | ||
250 | $this->assertSame($expected, $scope->toArray()); |
|
251 | ||
252 | $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"co-author":{"data":{"type":"people","id":"2"}}}},"included":[{"type":"people","id":"2","attributes":{"name":"Jim"}}]}'; |
|
253 | $this->assertSame($expectedJson, $scope->toJson()); |
|
254 | } |
|
255 | ||
256 | public function testSerializingItemResourceWithEmptyHasOneInclude() |
|
257 | { |
|
@@ 514-565 (lines=52) @@ | ||
511 | $this->assertSame($expectedJson, $scope->toJson()); |
|
512 | } |
|
513 | ||
514 | public function testSerializingCollectionResourceWithoutIncludes() |
|
515 | { |
|
516 | $booksData = [ |
|
517 | [ |
|
518 | 'id' => 1, |
|
519 | 'title' => 'Foo', |
|
520 | 'year' => '1991', |
|
521 | '_author' => [ |
|
522 | 'id' => 1, |
|
523 | 'name' => 'Dave', |
|
524 | ], |
|
525 | ], |
|
526 | [ |
|
527 | 'id' => 2, |
|
528 | 'title' => 'Bar', |
|
529 | 'year' => '1997', |
|
530 | '_author' => [ |
|
531 | 'id' => 2, |
|
532 | 'name' => 'Bob', |
|
533 | ], |
|
534 | ], |
|
535 | ]; |
|
536 | ||
537 | $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books'); |
|
538 | $scope = new Scope($this->manager, $resource); |
|
539 | ||
540 | $expected = [ |
|
541 | 'data' => [ |
|
542 | [ |
|
543 | 'type' => 'books', |
|
544 | 'id' => '1', |
|
545 | 'attributes' => [ |
|
546 | 'title' => 'Foo', |
|
547 | 'year' => 1991, |
|
548 | ], |
|
549 | ], |
|
550 | [ |
|
551 | 'type' => 'books', |
|
552 | 'id' => '2', |
|
553 | 'attributes' => [ |
|
554 | 'title' => 'Bar', |
|
555 | 'year' => 1997, |
|
556 | ], |
|
557 | ], |
|
558 | ], |
|
559 | ]; |
|
560 | ||
561 | $this->assertSame($expected, $scope->toArray()); |
|
562 | ||
563 | $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997}}]}'; |
|
564 | $this->assertSame($expectedJson, $scope->toJson()); |
|
565 | } |
|
566 | ||
567 | public function testSerializingCollectionResourceWithHasOneInclude() |
|
568 | { |
|
@@ 933-987 (lines=55) @@ | ||
930 | $this->assertSame($expectedJson, $scope->toJson()); |
|
931 | } |
|
932 | ||
933 | public function testSerializingCollectionResourceWithMeta() |
|
934 | { |
|
935 | $booksData = [ |
|
936 | [ |
|
937 | 'id' => 1, |
|
938 | 'title' => 'Foo', |
|
939 | 'year' => '1991', |
|
940 | '_author' => [ |
|
941 | 'name' => 'Dave', |
|
942 | ], |
|
943 | ], |
|
944 | [ |
|
945 | 'id' => 2, |
|
946 | 'title' => 'Bar', |
|
947 | 'year' => '1997', |
|
948 | '_author' => [ |
|
949 | 'name' => 'Bob', |
|
950 | ], |
|
951 | ], |
|
952 | ]; |
|
953 | ||
954 | $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books'); |
|
955 | $resource->setMetaValue('foo', 'bar'); |
|
956 | ||
957 | $scope = new Scope($this->manager, $resource); |
|
958 | ||
959 | $expected = [ |
|
960 | 'data' => [ |
|
961 | [ |
|
962 | 'type' => 'books', |
|
963 | 'id' => '1', |
|
964 | 'attributes' => [ |
|
965 | 'title' => 'Foo', |
|
966 | 'year' => 1991, |
|
967 | ], |
|
968 | ], |
|
969 | [ |
|
970 | 'type' => 'books', |
|
971 | 'id' => '2', |
|
972 | 'attributes' => [ |
|
973 | 'title' => 'Bar', |
|
974 | 'year' => 1997, |
|
975 | ], |
|
976 | ], |
|
977 | ], |
|
978 | 'meta' => [ |
|
979 | 'foo' => 'bar', |
|
980 | ], |
|
981 | ]; |
|
982 | ||
983 | $this->assertSame($expected, $scope->toArray()); |
|
984 | ||
985 | $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997}}],"meta":{"foo":"bar"}}'; |
|
986 | $this->assertSame($expectedJson, $scope->toJson()); |
|
987 | } |
|
988 | ||
989 | public function testSerializingCollectionResourceWithDuplicatedIncludeData() |
|
990 | { |