@@ -22,7 +22,9 @@ protected function setUp()
22
22
23
23
public function testOkWithoutBody ()
24
24
{
25
- $ this ->getJsonApi ('/api/v1/posts ' )->assertStatusCode (200 );
25
+ $ this ->getJsonApi ('/api/v1/posts ' )
26
+ ->assertStatus (200 )
27
+ ->assertHeader ('Content-Type ' , 'application/vnd.api+json ' );
26
28
}
27
29
28
30
public function testOkWithBody ()
@@ -71,9 +73,54 @@ public function testUnsupportedMediaType()
71
73
])->assertStatus (415 );
72
74
}
73
75
76
+ /**
77
+ * Can request an alternative media-type that is in our configuration.
78
+ * Note that the Symfony response automatically appends the charset to the
79
+ * content-type header if it starts with `text/`.
80
+ */
81
+ public function testAcceptable ()
82
+ {
83
+ $ this ->get ('/api/v1/posts ' , ['Accept ' => 'text/plain ' ])
84
+ ->assertStatus (200 )
85
+ ->assertHeader ('Content-Type ' , 'text/plain; charset=UTF-8 ' );
86
+ }
87
+
88
+ /**
89
+ * If we request a content type that is not in our codec configuration, we
90
+ * expect a 406 response.
91
+ */
74
92
public function testNotAcceptable ()
75
93
{
76
- $ this ->get ('/api/v1/posts ' , ['Accept ' => 'text/html ' ])->assertStatus (406 );
94
+ $ this ->get ('/api/v1/posts ' , ['Accept ' => 'application/json ' ])->assertStatus (406 );
95
+ }
96
+
97
+ /**
98
+ * The codec configuration can be changed.
99
+ */
100
+ public function testCanChangeMediaType1 ()
101
+ {
102
+ app ('config ' )->set ('json-api-default.codecs ' , [
103
+ 'encoders ' => ['application/json ' ],
104
+ 'decoders ' => ['application/json ' ],
105
+ ]);
106
+
107
+ $ this ->get ('/api/v1/posts ' , ['Accept ' => 'application/json ' ])
108
+ ->assertStatus (200 )
109
+ ->assertHeader ('Content-Type ' , 'application/json ' );
110
+ }
111
+
112
+ /**
113
+ * Not including the JSON API media type in our configuration results in a 406 response
114
+ */
115
+ public function testCanChangeMediaType2 ()
116
+ {
117
+ app ('config ' )->set ('json-api-default.codecs ' , [
118
+ 'encoders ' => ['application/json ' ],
119
+ 'decoders ' => ['application/json ' ],
120
+ ]);
121
+
122
+ $ this ->get ('/api/v1/posts ' , ['Accept ' => 'application/vnd.api+json ' ])
123
+ ->assertStatus (406 );
77
124
}
78
125
79
126
/**
0 commit comments