@@ -19,7 +19,7 @@ protected function getJsonString($filename)
19
19
}
20
20
21
21
/**
22
- * @test parse() with valid JSON API returns Document Object
22
+ * @test
23
23
*/
24
24
public function testParseSimpleResource ()
25
25
{
@@ -41,13 +41,13 @@ public function testParseSimpleResource()
41
41
$ this ->assertSame ($ resource ->getType (), 'articles ' );
42
42
$ this ->assertSame ($ resource ->getId (), '1 ' );
43
43
$ this ->assertTrue ($ resource ->hasAttributes ());
44
- $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , $ resource ->getAttributes ());
44
+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , $ resource ->getAttributes ());
45
45
$ this ->assertTrue ($ resource ->hasRelationships ());
46
- $ this ->assertInstanceOf ('Art4\JsonApiClient\RelationshipCollection ' , $ resource ->getRelationships ());
46
+ $ this ->assertInstanceOf ('Art4\JsonApiClient\RelationshipCollection ' , $ resource ->getRelationships ());
47
47
}
48
48
49
49
/**
50
- * @test parse() with valid JSON API returns Document Object
50
+ * @test
51
51
*/
52
52
public function testParseSimpleResourceIdentifier ()
53
53
{
@@ -69,4 +69,61 @@ public function testParseSimpleResourceIdentifier()
69
69
$ this ->assertSame ($ resource ->getType (), 'articles ' );
70
70
$ this ->assertSame ($ resource ->getId (), '1 ' );
71
71
}
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
+ }
72
129
}
0 commit comments