Skip to content

Commit

Permalink
feat(UriRetriever): application/json support
Browse files Browse the repository at this point in the history
  • Loading branch information
bighappyface committed Apr 28, 2016
1 parent 05ce776 commit 0e7add4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/JsonSchema/Uri/UriRetriever.php
Expand Up @@ -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;
}

Expand Down
38 changes: 37 additions & 1 deletion tests/JsonSchema/Tests/Uri/UriRetrieverTest.php
Expand Up @@ -222,7 +222,7 @@ public function testResolvePointerFragmentNoArray()
$schema, 'http://example.org/schema.json#/definitions/foo'
);
}

/**
* @expectedException JsonSchema\Exception\UriResolverException
*/
Expand All @@ -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));
}
}

0 comments on commit 0e7add4

Please sign in to comment.