@@ -19,7 +19,7 @@ protected function getJsonString($filename)
1919 }
2020
2121 /**
22- * @test parse() with valid JSON API returns Document Object
22+ * @test
2323 */
2424 public function testParseSimpleResource ()
2525 {
@@ -41,13 +41,13 @@ public function testParseSimpleResource()
4141 $ this ->assertSame ($ resource ->getType (), 'articles ' );
4242 $ this ->assertSame ($ resource ->getId (), '1 ' );
4343 $ this ->assertTrue ($ resource ->hasAttributes ());
44- $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , $ resource ->getAttributes ());
44+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , $ resource ->getAttributes ());
4545 $ this ->assertTrue ($ resource ->hasRelationships ());
46- $ this ->assertInstanceOf ('Art4\JsonApiClient\RelationshipCollection ' , $ resource ->getRelationships ());
46+ $ this ->assertInstanceOf ('Art4\JsonApiClient\RelationshipCollection ' , $ resource ->getRelationships ());
4747 }
4848
4949 /**
50- * @test parse() with valid JSON API returns Document Object
50+ * @test
5151 */
5252 public function testParseSimpleResourceIdentifier ()
5353 {
@@ -69,4 +69,61 @@ public function testParseSimpleResourceIdentifier()
6969 $ this ->assertSame ($ resource ->getType (), 'articles ' );
7070 $ this ->assertSame ($ resource ->getId (), '1 ' );
7171 }
72+
73+ /**
74+ * @test
75+ */
76+ public function testParseResourceObject ()
77+ {
78+ $ string = $ this ->getJsonString ('03_resource_object.js ' );
79+ $ document = Helper::parse ($ string );
80+
81+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Document ' , $ document );
82+ $ this ->assertFalse ($ document ->hasErrors ());
83+ $ this ->assertFalse ($ document ->hasMeta ());
84+ $ this ->assertFalse ($ document ->hasJsonapi ());
85+ $ this ->assertFalse ($ document ->hasLinks ());
86+ $ this ->assertFalse ($ document ->hasIncluded ());
87+ $ this ->assertTrue ($ document ->hasData ());
88+
89+ $ resource = $ document ->getData ();
90+
91+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Resource ' , $ resource );
92+ $ this ->assertFalse ($ resource ->hasMeta ());
93+ $ this ->assertSame ($ resource ->getType (), 'articles ' );
94+ $ this ->assertSame ($ resource ->getId (), '1 ' );
95+ $ this ->assertTrue ($ resource ->hasAttributes ());
96+ $ this ->assertTrue ($ resource ->hasRelationships ());
97+
98+ $ attributes = $ resource ->getAttributes ();
99+
100+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , $ attributes );
101+ $ this ->assertTrue ($ attributes ->__isset ('title ' ));
102+ $ this ->assertSame ($ attributes ->get ('title ' ), 'Rails is Omakase ' );
103+
104+ $ collection = $ resource ->getRelationships ();
105+
106+ $ this ->assertInstanceOf ('Art4\JsonApiClient\RelationshipCollection ' , $ collection );
107+ $ this ->assertTrue ($ collection ->__isset ('author ' ));
108+
109+ $ author = $ collection ->get ('author ' );
110+
111+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Relationship ' , $ author );
112+ $ this ->assertTrue ($ author ->hasLinks ());
113+ $ this ->assertTrue ($ author ->hasData ());
114+
115+ $ links = $ author ->getLinks ();
116+
117+ $ this ->assertInstanceOf ('Art4\JsonApiClient\RelationshipLink ' , $ links );
118+ $ this ->assertTrue ($ links ->__isset ('self ' ));
119+ $ this ->assertSame ($ links ->get ('self ' ), '/articles/1/relationships/author ' );
120+ $ this ->assertTrue ($ links ->__isset ('related ' ));
121+ $ this ->assertSame ($ links ->get ('related ' ), '/articles/1/author ' );
122+
123+ $ data = $ author ->getData ();
124+
125+ $ this ->assertInstanceOf ('Art4\JsonApiClient\ResourceIdentifier ' , $ data );
126+ $ this ->assertSame ($ data ->getType (), 'people ' );
127+ $ this ->assertSame ($ data ->getId (), '9 ' );
128+ }
72129}
0 commit comments