Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/JsonSchema/Uri/UriRetriever.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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));
}
}