diff --git a/src/JsonSchema/Uri/UriRetriever.php b/src/JsonSchema/Uri/UriRetriever.php index f4ba2ecd..b2445a7e 100644 --- a/src/JsonSchema/Uri/UriRetriever.php +++ b/src/JsonSchema/Uri/UriRetriever.php @@ -51,7 +51,7 @@ public function confirmMediaType($uriRetriever, $uri) return; } - if (Validator::SCHEMA_MEDIA_TYPE === $contentType) { + if (in_array($contentType, array(Validator::SCHEMA_MEDIA_TYPE, 'application/json'))) { return; } diff --git a/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php b/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php index 7409fd23..d98cebd6 100644 --- a/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php +++ b/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php @@ -222,7 +222,7 @@ public function testResolvePointerFragmentNoArray() $schema, 'http://example.org/schema.json#/definitions/foo' ); } - + /** * @expectedException JsonSchema\Exception\UriResolverException */ @@ -233,4 +233,40 @@ public function testResolveExcessLevelUp() '../schema.json#', 'http://example.org/schema.json#' ); } + + public function testConfirmMediaTypeAcceptsJsonSchemaType() + { + $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + + $retriever->expects($this->at(0)) + ->method('getContentType') + ->will($this->returnValue('application/schema+json')); + + $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); + } + + public function testConfirmMediaTypeAcceptsJsonType() + { + $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + + $retriever->expects($this->at(0)) + ->method('getContentType') + ->will($this->returnValue('application/json')); + + $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); + } + + /** + * @expectedException \JsonSchema\Exception\InvalidSchemaMediaTypeException + */ + public function testConfirmMediaTypeThrowsExceptionForUnsupportedTypes() + { + $retriever = $this->getMock('JsonSchema\Uri\UriRetriever', array('getContentType')); + + $retriever->expects($this->at(0)) + ->method('getContentType') + ->will($this->returnValue('text/html')); + + $this->assertEquals(null, $retriever->confirmMediaType($retriever, null)); + } }