From 0e7add4652d09be6bcf4a59d14742e6468215a10 Mon Sep 17 00:00:00 2001 From: bighappyface Date: Thu, 28 Apr 2016 08:29:49 -0500 Subject: [PATCH] feat(UriRetriever): application/json support --- src/JsonSchema/Uri/UriRetriever.php | 2 +- .../JsonSchema/Tests/Uri/UriRetrieverTest.php | 38 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) 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)); + } }