@@ 73-127 (lines=55) @@ | ||
70 | $this->assertSame($expectedJson, $scope->toJson()); |
|
71 | } |
|
72 | ||
73 | public function testSerializingItemResourceWithHasOneDasherizedInclude() |
|
74 | { |
|
75 | $this->manager->parseIncludes('co-author'); |
|
76 | ||
77 | $bookData = [ |
|
78 | 'id' => 1, |
|
79 | 'title' => 'Foo', |
|
80 | 'year' => '1991', |
|
81 | '_author' => [ |
|
82 | 'id' => 1, |
|
83 | 'name' => 'Dave', |
|
84 | ], |
|
85 | '_co_author' => [ |
|
86 | 'id' => 2, |
|
87 | 'name' => 'Jim', |
|
88 | ], |
|
89 | ]; |
|
90 | ||
91 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
92 | ||
93 | $scope = new Scope($this->manager, $resource); |
|
94 | ||
95 | $expected = [ |
|
96 | 'data' => [ |
|
97 | 'type' => 'books', |
|
98 | 'id' => '1', |
|
99 | 'attributes' => [ |
|
100 | 'title' => 'Foo', |
|
101 | 'year' => 1991, |
|
102 | ], |
|
103 | 'relationships' => [ |
|
104 | 'co-author' => [ |
|
105 | 'data' => [ |
|
106 | 'type' => 'people', |
|
107 | 'id' => '2', |
|
108 | ], |
|
109 | ], |
|
110 | ], |
|
111 | ], |
|
112 | 'included' => [ |
|
113 | [ |
|
114 | 'type' => 'people', |
|
115 | 'id' => '2', |
|
116 | 'attributes' => [ |
|
117 | 'name' => 'Jim', |
|
118 | ], |
|
119 | ], |
|
120 | ], |
|
121 | ]; |
|
122 | ||
123 | $this->assertSame($expected, $scope->toArray()); |
|
124 | ||
125 | $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"}}]}'; |
|
126 | $this->assertSame($expectedJson, $scope->toJson()); |
|
127 | } |
|
128 | ||
129 | public function testSerializingItemResourceWithEmptyHasOneInclude() |
|
130 | { |
|
@@ 344-395 (lines=52) @@ | ||
341 | $this->assertSame($expectedJson, $scope->toJson()); |
|
342 | } |
|
343 | ||
344 | public function testSerializingCollectionResourceWithoutIncludes() |
|
345 | { |
|
346 | $booksData = [ |
|
347 | [ |
|
348 | 'id' => 1, |
|
349 | 'title' => 'Foo', |
|
350 | 'year' => '1991', |
|
351 | '_author' => [ |
|
352 | 'id' => 1, |
|
353 | 'name' => 'Dave', |
|
354 | ], |
|
355 | ], |
|
356 | [ |
|
357 | 'id' => 2, |
|
358 | 'title' => 'Bar', |
|
359 | 'year' => '1997', |
|
360 | '_author' => [ |
|
361 | 'id' => 2, |
|
362 | 'name' => 'Bob', |
|
363 | ], |
|
364 | ], |
|
365 | ]; |
|
366 | ||
367 | $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books'); |
|
368 | $scope = new Scope($this->manager, $resource); |
|
369 | ||
370 | $expected = [ |
|
371 | 'data' => [ |
|
372 | [ |
|
373 | 'type' => 'books', |
|
374 | 'id' => '1', |
|
375 | 'attributes' => [ |
|
376 | 'title' => 'Foo', |
|
377 | 'year' => 1991, |
|
378 | ], |
|
379 | ], |
|
380 | [ |
|
381 | 'type' => 'books', |
|
382 | 'id' => '2', |
|
383 | 'attributes' => [ |
|
384 | 'title' => 'Bar', |
|
385 | 'year' => 1997, |
|
386 | ], |
|
387 | ], |
|
388 | ], |
|
389 | ]; |
|
390 | ||
391 | $this->assertSame($expected, $scope->toArray()); |
|
392 | ||
393 | $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997}}]}'; |
|
394 | $this->assertSame($expectedJson, $scope->toJson()); |
|
395 | } |
|
396 | ||
397 | public function testSerializingCollectionResourceWithHasOneInclude() |
|
398 | { |
|
@@ 763-817 (lines=55) @@ | ||
760 | $this->assertSame($expectedJson, $scope->toJson()); |
|
761 | } |
|
762 | ||
763 | public function testSerializingCollectionResourceWithMeta() |
|
764 | { |
|
765 | $booksData = [ |
|
766 | [ |
|
767 | 'id' => 1, |
|
768 | 'title' => 'Foo', |
|
769 | 'year' => '1991', |
|
770 | '_author' => [ |
|
771 | 'name' => 'Dave', |
|
772 | ], |
|
773 | ], |
|
774 | [ |
|
775 | 'id' => 2, |
|
776 | 'title' => 'Bar', |
|
777 | 'year' => '1997', |
|
778 | '_author' => [ |
|
779 | 'name' => 'Bob', |
|
780 | ], |
|
781 | ], |
|
782 | ]; |
|
783 | ||
784 | $resource = new Collection($booksData, new JsonApiBookTransformer(), 'books'); |
|
785 | $resource->setMetaValue('foo', 'bar'); |
|
786 | ||
787 | $scope = new Scope($this->manager, $resource); |
|
788 | ||
789 | $expected = [ |
|
790 | 'data' => [ |
|
791 | [ |
|
792 | 'type' => 'books', |
|
793 | 'id' => '1', |
|
794 | 'attributes' => [ |
|
795 | 'title' => 'Foo', |
|
796 | 'year' => 1991, |
|
797 | ], |
|
798 | ], |
|
799 | [ |
|
800 | 'type' => 'books', |
|
801 | 'id' => '2', |
|
802 | 'attributes' => [ |
|
803 | 'title' => 'Bar', |
|
804 | 'year' => 1997, |
|
805 | ], |
|
806 | ], |
|
807 | ], |
|
808 | 'meta' => [ |
|
809 | 'foo' => 'bar', |
|
810 | ], |
|
811 | ]; |
|
812 | ||
813 | $this->assertSame($expected, $scope->toArray()); |
|
814 | ||
815 | $expectedJson = '{"data":[{"type":"books","id":"1","attributes":{"title":"Foo","year":1991}},{"type":"books","id":"2","attributes":{"title":"Bar","year":1997}}],"meta":{"foo":"bar"}}'; |
|
816 | $this->assertSame($expectedJson, $scope->toJson()); |
|
817 | } |
|
818 | ||
819 | public function testSerializingCollectionResourceWithDuplicatedIncludeData() |
|
820 | { |