diff --git a/src/Negotiation/AcceptHeader.php b/src/Negotiation/AcceptHeader.php index 4312cdd..4e1ee39 100644 --- a/src/Negotiation/AcceptHeader.php +++ b/src/Negotiation/AcceptHeader.php @@ -53,4 +53,9 @@ public function hasParameter($key) { return isset($this->parameters[$key]); } + + public function isMediaRange() + { + return false !== strpos($this->value, '*'); + } } diff --git a/tests/Negotiation/Tests/AcceptHeaderTest.php b/tests/Negotiation/Tests/AcceptHeaderTest.php index 2edd23f..be7035b 100644 --- a/tests/Negotiation/Tests/AcceptHeaderTest.php +++ b/tests/Negotiation/Tests/AcceptHeaderTest.php @@ -24,4 +24,23 @@ public function testGetParameter() $this->assertNull($this->acceptHeader->getParameter('unknown')); $this->assertFalse($this->acceptHeader->getParameter('unknown', false)); } + + /** + * @dataProvider dataProviderForTestIsMediaRange + */ + public function testIsMediaRange($value, $expected) + { + $header = new AcceptHeader($value, 1.0); + + $this->assertEquals($expected, $header->isMediaRange()); + } + + public static function dataProviderForTestIsMediaRange() + { + return array( + array('text/*', true), + array('*/*', true), + array('application/json', false), + ); + } } diff --git a/tests/Negotiation/Tests/FormatNegotiatorTest.php b/tests/Negotiation/Tests/FormatNegotiatorTest.php index 4238cac..b68cf21 100644 --- a/tests/Negotiation/Tests/FormatNegotiatorTest.php +++ b/tests/Negotiation/Tests/FormatNegotiatorTest.php @@ -235,6 +235,15 @@ public static function dataProviderForGetBest() ), ) ), + array( + '*/*', + array(), + array( + 'value' => '*/*', + 'quality' => 0.01, + 'parameters' => array(), + ), + ), ); }