Skip to content

Commit 870eaad

Browse files
committed
Merge pull request #259 from bighappyface/application-json
feat(UriRetriever): application/json support
2 parents 05ce776 + 0e7add4 commit 870eaad

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/JsonSchema/Uri/UriRetriever.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function confirmMediaType($uriRetriever, $uri)
5151
return;
5252
}
5353

54-
if (Validator::SCHEMA_MEDIA_TYPE === $contentType) {
54+
if (in_array($contentType, array(Validator::SCHEMA_MEDIA_TYPE, 'application/json'))) {
5555
return;
5656
}
5757

tests/JsonSchema/Tests/Uri/UriRetrieverTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function testResolvePointerFragmentNoArray()
222222
$schema, 'http://example.org/schema.json#/definitions/foo'
223223
);
224224
}
225-
225+
226226
/**
227227
* @expectedException JsonSchema\Exception\UriResolverException
228228
*/
@@ -233,4 +233,40 @@ public function testResolveExcessLevelUp()
233233
'../schema.json#', 'http://example.org/schema.json#'
234234
);
235235
}
236+
237+
public function testConfirmMediaTypeAcceptsJsonSchemaType()
238+
{
239+
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
240+
241+
$retriever->expects($this->at(0))
242+
->method('getContentType')
243+
->will($this->returnValue('application/schema+json'));
244+
245+
$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
246+
}
247+
248+
public function testConfirmMediaTypeAcceptsJsonType()
249+
{
250+
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
251+
252+
$retriever->expects($this->at(0))
253+
->method('getContentType')
254+
->will($this->returnValue('application/json'));
255+
256+
$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
257+
}
258+
259+
/**
260+
* @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException
261+
*/
262+
public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes()
263+
{
264+
$retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType'));
265+
266+
$retriever->expects($this->at(0))
267+
->method('getContentType')
268+
->will($this->returnValue('text/html'));
269+
270+
$this->assertEquals(null, $retriever->confirmMediaType($retriever, null));
271+
}
236272
}

0 commit comments

Comments
 (0)