Skip to content

Commit

Permalink
Add AcceptHeader::isMediaRange() method
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Dec 14, 2013
1 parent 8fc2f8c commit 2fc171e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Negotiation/AcceptHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ public function hasParameter($key)
{
return isset($this->parameters[$key]);
}

public function isMediaRange()
{
return false !== strpos($this->value, '*');
}
}
19 changes: 19 additions & 0 deletions tests/Negotiation/Tests/AcceptHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
}
9 changes: 9 additions & 0 deletions tests/Negotiation/Tests/FormatNegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ public static function dataProviderForGetBest()
),
)
),
array(
'*/*',
array(),
array(
'value' => '*/*',
'quality' => 0.01,
'parameters' => array(),
),
),
);
}

Expand Down

0 comments on commit 2fc171e

Please # to comment.