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