@@ 397-482 (lines=86) @@ | ||
394 | $this->assertSame($expectedJson, $scope->toJson()); |
|
395 | } |
|
396 | ||
397 | public function testSerializingCollectionResourceWithHasOneInclude() |
|
398 | { |
|
399 | $this->manager->parseIncludes('author'); |
|
400 | ||
401 | $booksData = [ |
|
402 | [ |
|
403 | 'id' => 1, |
|
404 | 'title' => 'Foo', |
|
405 | 'year' => '1991', |
|
406 | '_author' => [ |
|
407 | 'id' => 1, |
|
408 | 'name' => 'Dave', |
|
409 | ], |
|
410 | ], |
|
411 | [ |
|
412 | 'id' => 2, |
|
413 | 'title' => 'Bar', |
|
414 | 'year' => '1997', |
|
415 | '_author' => [ |
|
416 | 'id' => 2, |
|
417 | 'name' => 'Bob', |
|
418 | ], |
|
419 | ], |
|
420 | ]; |
|
421 | ||
422 | $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books'); |
|
423 | $scope = new Scope($this->manager, $resource); |
|
424 | ||
425 | $expected = [ |
|
426 | 'data' => [ |
|
427 | [ |
|
428 | 'type' => 'books', |
|
429 | 'id' => '1', |
|
430 | 'attributes' => [ |
|
431 | 'title' => 'Foo', |
|
432 | 'year' => 1991, |
|
433 | ], |
|
434 | 'relationships' => [ |
|
435 | 'author' => [ |
|
436 | 'data' => [ |
|
437 | 'type' => 'people', |
|
438 | 'id' => '1', |
|
439 | ], |
|
440 | ], |
|
441 | ], |
|
442 | ], |
|
443 | [ |
|
444 | 'type' => 'books', |
|
445 | 'id' => '2', |
|
446 | 'attributes' => [ |
|
447 | 'title' => 'Bar', |
|
448 | 'year' => 1997, |
|
449 | ], |
|
450 | 'relationships' => [ |
|
451 | 'author' => [ |
|
452 | 'data' => [ |
|
453 | 'type' => 'people', |
|
454 | 'id' => '2', |
|
455 | ], |
|
456 | ], |
|
457 | ], |
|
458 | ], |
|
459 | ], |
|
460 | 'included' => [ |
|
461 | [ |
|
462 | 'type' => 'people', |
|
463 | 'id' => '1', |
|
464 | 'attributes' => [ |
|
465 | 'name' => 'Dave', |
|
466 | ], |
|
467 | ], |
|
468 | [ |
|
469 | 'type' => 'people', |
|
470 | 'id' => '2', |
|
471 | 'attributes' => [ |
|
472 | 'name' => 'Bob', |
|
473 | ], |
|
474 | ], |
|
475 | ], |
|
476 | ]; |
|
477 | ||
478 | $this->assertSame($expected, $scope->toArray()); |
|
479 | ||
480 | $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"author":{"data":{"type":"people","id":"1"}}}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997},"relationships":{"author":{"data":{"type":"people","id":"2"}}}}],"included":[{"type":"people","id":"1","attributes":{"name":"Dave"}},{"type":"people","id":"2","attributes":{"name":"Bob"}}]}'; |
|
481 | $this->assertSame($expectedJson, $scope->toJson()); |
|
482 | } |
|
483 | ||
484 | public function testSerializingCollectionResourceWithEmptyHasOneInclude() |
|
485 | { |
|
@@ 899-983 (lines=85) @@ | ||
896 | $this->assertSame($expectedJson, $scope->toJson()); |
|
897 | } |
|
898 | ||
899 | public function testSerializingItemResourceWithNestedIncludes() |
|
900 | { |
|
901 | $this->manager->parseIncludes(['author', 'author.published']); |
|
902 | ||
903 | $bookData = [ |
|
904 | 'id' => 1, |
|
905 | 'title' => 'Foo', |
|
906 | 'year' => '1991', |
|
907 | '_author' => [ |
|
908 | 'id' => 1, |
|
909 | 'name' => 'Dave', |
|
910 | '_published' => [ |
|
911 | [ |
|
912 | 'id' => 1, |
|
913 | 'title' => 'Foo', |
|
914 | 'year' => '1991', |
|
915 | ], |
|
916 | [ |
|
917 | 'id' => 2, |
|
918 | 'title' => 'Bar', |
|
919 | 'year' => '2015', |
|
920 | ], |
|
921 | ], |
|
922 | ], |
|
923 | ]; |
|
924 | ||
925 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
926 | ||
927 | $scope = new Scope($this->manager, $resource); |
|
928 | ||
929 | $expected = [ |
|
930 | 'data' => [ |
|
931 | 'type' => 'books', |
|
932 | 'id' => '1', |
|
933 | 'attributes' => [ |
|
934 | 'title' => 'Foo', |
|
935 | 'year' => 1991, |
|
936 | ], |
|
937 | 'relationships' => [ |
|
938 | 'author' => [ |
|
939 | 'data' => [ |
|
940 | 'type' => 'people', |
|
941 | 'id' => '1', |
|
942 | ], |
|
943 | ], |
|
944 | ], |
|
945 | ], |
|
946 | 'included' => [ |
|
947 | [ |
|
948 | 'type' => 'books', |
|
949 | 'id' => '2', |
|
950 | 'attributes' => [ |
|
951 | 'title' => 'Bar', |
|
952 | 'year' => 2015, |
|
953 | ], |
|
954 | ], |
|
955 | [ |
|
956 | 'type' => 'people', |
|
957 | 'id' => '1', |
|
958 | 'attributes' => [ |
|
959 | 'name' => 'Dave', |
|
960 | ], |
|
961 | 'relationships' => [ |
|
962 | 'published' => [ |
|
963 | 'data' => [ |
|
964 | [ |
|
965 | 'type' => 'books', |
|
966 | 'id' => '1', |
|
967 | ], |
|
968 | [ |
|
969 | 'type' => 'books', |
|
970 | 'id' => '2', |
|
971 | ], |
|
972 | ], |
|
973 | ], |
|
974 | ], |
|
975 | ], |
|
976 | ], |
|
977 | ]; |
|
978 | ||
979 | $this->assertSame($expected, $scope->toArray()); |
|
980 | ||
981 | $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"author":{"data":{"type":"people","id":"1"}}}},"included":[{"type":"books","id":"2","attributes":{"title":"Bar","year":2015}},{"type":"people","id":"1","attributes":{"name":"Dave"},"relationships":{"published":{"data":[{"type":"books","id":"1"},{"type":"books","id":"2"}]}}}]}'; |
|
982 | $this->assertSame($expectedJson, $scope->toJson()); |
|
983 | } |
|
984 | ||
985 | public function testSerializingItemResourceWithSelfLink() |
|
986 | { |