@@ -19,9 +19,10 @@ public function testRequestedResourceHasRequestHost()
19
19
$ json = $ this
20
20
->withApiRoutes ()
21
21
->getJsonApi ("http://www.example.com/api/v1/posts/ $ id " )
22
+ ->assertStatus (200 )
22
23
->json ();
23
24
24
- $ this ->assertLinks ( ' http://www.example.com ' , $ id , $ json );
25
+ $ this ->assertSelfLink ( " http://www.example.com/api/v1/posts/ $ id" , $ json );
25
26
}
26
27
27
28
/**
@@ -35,9 +36,62 @@ public function testRequestedResourceDoesNotHaveHost()
35
36
$ json = $ this
36
37
->withApiRoutes ()
37
38
->getJsonApi ("http://www.example.com/api/v1/posts/ $ id " )
39
+ ->assertStatus (200 )
38
40
->json ();
39
41
40
- $ this ->assertLinks ('' , $ id , $ json );
42
+ $ this ->assertSelfLink ("/api/v1/posts/ $ id " , $ json );
43
+ }
44
+
45
+ /**
46
+ * If there is no URL namespace, the URL must be properly formed.
47
+ */
48
+ public function testRequestResourceDoesNotHaveUrlNamespace ()
49
+ {
50
+ $ id = factory (Post::class)->create ()->getKey ();
51
+ config ()->set ('json-api-default.url.namespace ' , null );
52
+
53
+ $ json = $ this
54
+ ->withApiRoutes ()
55
+ ->getJsonApi ("http://www.example.com/posts/ $ id " )
56
+ ->assertStatus (200 )
57
+ ->json ();
58
+
59
+ $ this ->assertSelfLink ("http://www.example.com/posts/ $ id " , $ json );
60
+ }
61
+
62
+ /**
63
+ * If there is no URL namespace, the URL must be properly formed.
64
+ */
65
+ public function testRequestResourceHasEmptyUrlNamespace ()
66
+ {
67
+ $ id = factory (Post::class)->create ()->getKey ();
68
+ config ()->set ('json-api-default.url.namespace ' , '' );
69
+
70
+ $ json = $ this
71
+ ->withApiRoutes ()
72
+ ->getJsonApi ("http://www.example.com/posts/ $ id " )
73
+ ->assertStatus (200 )
74
+ ->json ();
75
+
76
+ $ this ->assertSelfLink ("http://www.example.com/posts/ $ id " , $ json );
77
+ }
78
+
79
+ /**
80
+ * If there is no URL host and namespace, the URL must be properly formed.
81
+ */
82
+ public function testRequestResourceDoesNotHaveHostAndUrlNamespace ()
83
+ {
84
+ $ id = factory (Post::class)->create ()->getKey ();
85
+ config ()->set ('json-api-default.url.host ' , false );
86
+ config ()->set ('json-api-default.url.namespace ' , null );
87
+
88
+ $ json = $ this
89
+ ->withApiRoutes ()
90
+ ->getJsonApi ("http://www.example.com/posts/ $ id " )
91
+ ->assertStatus (200 )
92
+ ->json ();
93
+
94
+ $ this ->assertSelfLink ("/posts/ $ id " , $ json );
41
95
}
42
96
43
97
/**
@@ -52,7 +106,7 @@ public function testSerializedResourceHasAppHost()
52
106
config ()->set ('json-api-default.url.host ' , null );
53
107
54
108
$ json = json_api ('default ' )->encoder ()->serializeData ($ post );
55
- $ this ->assertLinks ( $ host , $ post ->getKey (), $ json );
109
+ $ this ->assertSelfLink ( " http://www.example.com/api/v1/posts/ { $ post ->getKey ()}" , $ json );
56
110
}
57
111
58
112
/**
@@ -67,7 +121,7 @@ public function testSerializedResourceHasSpecificHost()
67
121
config ()->set ('json-api-default.url.host ' , $ host = 'http://www.example.com ' );
68
122
69
123
$ json = json_api ('default ' )->encoder ()->serializeData ($ post );
70
- $ this ->assertLinks ( $ host , $ post ->getKey (), $ json );
124
+ $ this ->assertSelfLink ( " http://www.example.com/api/v1/posts/ { $ post ->getKey ()}" , $ json );
71
125
}
72
126
73
127
/**
@@ -82,20 +136,19 @@ public function testSerializedResourceDoesNotHaveAppHost()
82
136
config ()->set ('json-api-default.url.host ' , false );
83
137
84
138
$ json = json_api ('default ' )->encoder ()->serializeData ($ post );
85
- $ this ->assertLinks ( '' , $ post ->getKey (), $ json );
139
+ $ this ->assertSelfLink ( " /api/v1/posts/ { $ post ->getKey ()}" , $ json );
86
140
}
87
141
88
142
/**
89
- * @param $host
90
- * @param $id
143
+ * @param $link
91
144
* @param array $json
92
145
*/
93
- private function assertLinks ( $ host , $ id , array $ json )
146
+ private function assertSelfLink ( $ link , array $ json )
94
147
{
95
148
$ this ->assertArraySubset ([
96
149
'data ' => [
97
150
'links ' => [
98
- 'self ' => " $ host /api/v1/posts/ $ id " ,
151
+ 'self ' => $ link ,
99
152
],
100
153
],
101
154
], $ json );
0 commit comments