- md5
- 29933cf5a08e000f29d5fcf069b512d1
- sha1
- 55ca65ac2c7079301b96e026d84c9d18383faf0a
- sha256
- 53271919daaa63b06084eca6c82b8da285b70204608c1f916fcadaec51edd798
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
<?php
namespace Negotiation\Tests;
use Negotiation\EncodingNegotiator;
class EncodingNegotiatorTest extends TestCase
{
/**
* @var EncodingNegotiator
*/
private $negotiator;
protected function setUp()
{
$this->negotiator = new EncodingNegotiator();
}
public function testGetBestReturnsNullWithUnmatchedHeader()
{
$this->assertNull($this->negotiator->getBest('foo, bar, yo', array('baz')));
}
/**
* @dataProvider dataProviderForTestGetBest
*/
public function testGetBest($accept, $priorities, $expected)
{
$accept = $this->negotiator->getBest($accept, $priorities);
if (null === $accept) {
$this->assertNull($expected);
} else {
$this->assertInstanceOf('Negotiation\AcceptEncoding', $accept);
$this->assertEquals($expected, $accept->getValue());
}
}
public static function dataProviderForTestGetBest()
{
return array(
array('gzip;q=1.0, identity; q=0.5, *;q=0', array('identity'), 'identity'),
array('gzip;q=0.5, identity; q=0.5, *;q=0.7', array('bzip', 'foo'), 'bzip'),
array('gzip;q=0.7, identity; q=0.5, *;q=0.7', array('gzip', 'foo'), 'gzip'),
# Quality of source factors
array('gzip;q=0.7,identity', array('identity;q=0.5', 'gzip;q=0.9'), 'gzip;q=0.9'),
);
}
public function testGetBestRespectsQualityOfSource()
{
$accept = $this->negotiator->getBest('gzip;q=0.7,identity', array('identity;q=0.5', 'gzip;q=0.9'));
$this->assertInstanceOf('Negotiation\AcceptEncoding', $accept);
$this->assertEquals('gzip', $accept->getType());
}
/**
* @dataProvider dataProviderForTestParseAcceptHeader
*/
public function testParseAcceptHeader($header, $expected)
{
$accepts = $this->call_private_method('Negotiation\Negotiator', 'parseHeader', $this->negotiator, array($header));
$this->assertSame($expected, $accepts);
}
public static function dataProviderForTestParseAcceptHeader()
{
return array(
array('gzip,deflate,sdch', array('gzip', 'deflate', 'sdch')),
array("gzip, deflate\t,sdch", array('gzip', 'deflate', 'sdch')),
array('gzip;q=1.0, identity; q=0.5, *;q=0', array('gzip;q=1.0', 'identity; q=0.5', '*;q=0')),
);
}
}
The same content is in 13 releases, Joomla 4.0.0-alpha7 to 4.0.0-beta7. See them all, or every version of this file.