| @@ 21-71 (lines=51) @@ | ||
| 18 | $this->manager->setSerializer(new JsonApiSerializer()); |
|
| 19 | } |
|
| 20 | ||
| 21 | public function testSerializingItemResourceWithHasOneInclude() |
|
| 22 | { |
|
| 23 | $this->manager->parseIncludes('author'); |
|
| 24 | ||
| 25 | $bookData = [ |
|
| 26 | 'id' => 1, |
|
| 27 | 'title' => 'Foo', |
|
| 28 | 'year' => '1991', |
|
| 29 | '_author' => [ |
|
| 30 | 'id' => 1, |
|
| 31 | 'name' => 'Dave', |
|
| 32 | ], |
|
| 33 | ]; |
|
| 34 | ||
| 35 | $resource = new Item($bookData, new JsonApiBookTransformer(), 'books'); |
|
| 36 | ||
| 37 | $scope = new Scope($this->manager, $resource); |
|
| 38 | ||
| 39 | $expected = [ |
|
| 40 | 'data' => [ |
|
| 41 | 'type' => 'books', |
|
| 42 | 'id' => '1', |
|
| 43 | 'attributes' => [ |
|
| 44 | 'title' => 'Foo', |
|
| 45 | 'year' => 1991, |
|
| 46 | ], |
|
| 47 | 'relationships' => [ |
|
| 48 | 'author' => [ |
|
| 49 | 'data' => [ |
|
| 50 | 'type' => 'people', |
|
| 51 | 'id' => '1', |
|
| 52 | ], |
|
| 53 | ], |
|
| 54 | ], |
|
| 55 | ], |
|
| 56 | 'included' => [ |
|
| 57 | [ |
|
| 58 | 'type' => 'people', |
|
| 59 | 'id' => '1', |
|
| 60 | 'attributes' => [ |
|
| 61 | 'name' => 'Dave', |
|
| 62 | ], |
|
| 63 | ], |
|
| 64 | ], |
|
| 65 | ]; |
|
| 66 | ||
| 67 | $this->assertSame($expected, $scope->toArray()); |
|
| 68 | ||
| 69 | $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"relationships":{"author":{"data":{"type":"people","id":"1"}}}},"included":[{"type":"people","id":"1","attributes":{"name":"Dave"}}]}'; |
|
| 70 | $this->assertSame($expectedJson, $scope->toJson()); |
|
| 71 | } |
|
| 72 | ||
| 73 | public function testSerializingItemResourceWithHasOneDasherizedInclude() |
|
| 74 | { |
|
| @@ 985-1036 (lines=52) @@ | ||
| 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 | 'relationships' => [ |
|
| 1016 | 'author' => [ |
|
| 1017 | 'links' => [ |
|
| 1018 | 'self' => 'http://example.com/books/1/relationships/author', |
|
| 1019 | 'related' => 'http://example.com/books/1/author', |
|
| 1020 | ], |
|
| 1021 | ], |
|
| 1022 | 'co-author' => [ |
|
| 1023 | 'links' => [ |
|
| 1024 | 'self' => 'http://example.com/books/1/relationships/co-author', |
|
| 1025 | 'related' => 'http://example.com/books/1/co-author', |
|
| 1026 | ], |
|
| 1027 | ], |
|
| 1028 | ], |
|
| 1029 | ], |
|
| 1030 | ]; |
|
| 1031 | ||
| 1032 | $this->assertSame($expected, $scope->toArray()); |
|
| 1033 | ||
| 1034 | $expectedJson = '{"data":{"type":"books","id":"1","attributes":{"title":"Foo","year":1991},"links":{"self":"http:\/\/example.com\/books\/1"},"relationships":{"author":{"links":{"self":"http:\/\/example.com\/books\/1\/relationships\/author","related":"http:\/\/example.com\/books\/1\/author"}},"co-author":{"links":{"self":"http:\/\/example.com\/books\/1\/relationships\/co-author","related":"http:\/\/example.com\/books\/1\/co-author"}}}}}'; |
|
| 1035 | $this->assertSame($expectedJson, $scope->toJson()); |
|
| 1036 | } |
|
| 1037 | ||
| 1038 | public function testSerializingCollectionResourceWithSelfLink() |
|
| 1039 | { |
|