From 2fc171eeec372658f26bfad26f3d638176fd8d7c Mon Sep 17 00:00:00 2001 From: William DURAND Date: Sat, 14 Dec 2013 15:08:14 +0100 Subject: [PATCH] Add AcceptHeader::isMediaRange() method --- src/Negotiation/AcceptHeader.php | 5 +++++ tests/Negotiation/Tests/AcceptHeaderTest.php | 19 +++++++++++++++++++ .../Tests/FormatNegotiatorTest.php | 9 +++++++++ 3 files changed, 33 insertions(+) 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(), + ), + ), ); }