-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
10,937 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpFoundation\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\AcceptHeaderItem; | ||
|
||
class AcceptHeaderItemTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideFromStringData | ||
*/ | ||
public function testFromString($string, $value, array $attributes) | ||
{ | ||
$item = AcceptHeaderItem::fromString($string); | ||
$this->assertEquals($value, $item->getValue()); | ||
$this->assertEquals($attributes, $item->getAttributes()); | ||
} | ||
|
||
public function provideFromStringData() | ||
{ | ||
return array( | ||
array( | ||
'text/html', | ||
'text/html', array(), | ||
), | ||
array( | ||
'"this;should,not=matter"', | ||
'this;should,not=matter', array(), | ||
), | ||
array( | ||
"text/plain; charset=utf-8;param=\"this;should,not=matter\";\tfootnotes=true", | ||
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'), | ||
), | ||
array( | ||
'"this;should,not=matter";charset=utf-8', | ||
'this;should,not=matter', array('charset' => 'utf-8'), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider provideToStringData | ||
*/ | ||
public function testToString($value, array $attributes, $string) | ||
{ | ||
$item = new AcceptHeaderItem($value, $attributes); | ||
$this->assertEquals($string, (string) $item); | ||
} | ||
|
||
public function provideToStringData() | ||
{ | ||
return array( | ||
array( | ||
'text/html', array(), | ||
'text/html', | ||
), | ||
array( | ||
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'), | ||
'text/plain;charset=utf-8;param="this;should,not=matter";footnotes=true', | ||
), | ||
); | ||
} | ||
|
||
public function testValue() | ||
{ | ||
$item = new AcceptHeaderItem('value', array()); | ||
$this->assertEquals('value', $item->getValue()); | ||
|
||
$item->setValue('new value'); | ||
$this->assertEquals('new value', $item->getValue()); | ||
|
||
$item->setValue(1); | ||
$this->assertEquals('1', $item->getValue()); | ||
} | ||
|
||
public function testQuality() | ||
{ | ||
$item = new AcceptHeaderItem('value', array()); | ||
$this->assertEquals(1.0, $item->getQuality()); | ||
|
||
$item->setQuality(0.5); | ||
$this->assertEquals(0.5, $item->getQuality()); | ||
|
||
$item->setAttribute('q', 0.75); | ||
$this->assertEquals(0.75, $item->getQuality()); | ||
$this->assertFalse($item->hasAttribute('q')); | ||
} | ||
|
||
public function testAttribute() | ||
{ | ||
$item = new AcceptHeaderItem('value', array()); | ||
$this->assertEquals(array(), $item->getAttributes()); | ||
$this->assertFalse($item->hasAttribute('test')); | ||
$this->assertNull($item->getAttribute('test')); | ||
$this->assertEquals('default', $item->getAttribute('test', 'default')); | ||
|
||
$item->setAttribute('test', 'value'); | ||
$this->assertEquals(array('test' => 'value'), $item->getAttributes()); | ||
$this->assertTrue($item->hasAttribute('test')); | ||
$this->assertEquals('value', $item->getAttribute('test')); | ||
$this->assertEquals('value', $item->getAttribute('test', 'default')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpFoundation\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\AcceptHeader; | ||
use Symfony\Component\HttpFoundation\AcceptHeaderItem; | ||
|
||
class AcceptHeaderTest extends TestCase | ||
{ | ||
public function testFirst() | ||
{ | ||
$header = AcceptHeader::fromString('text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c'); | ||
$this->assertSame('text/html', $header->first()->getValue()); | ||
} | ||
|
||
/** | ||
* @dataProvider provideFromStringData | ||
*/ | ||
public function testFromString($string, array $items) | ||
{ | ||
$header = AcceptHeader::fromString($string); | ||
$parsed = array_values($header->all()); | ||
// reset index since the fixtures don't have them set | ||
foreach ($parsed as $item) { | ||
$item->setIndex(0); | ||
} | ||
$this->assertEquals($items, $parsed); | ||
} | ||
|
||
public function provideFromStringData() | ||
{ | ||
return array( | ||
array('', array()), | ||
array('gzip', array(new AcceptHeaderItem('gzip'))), | ||
array('gzip,deflate,sdch', array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))), | ||
array("gzip, deflate\t,sdch", array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))), | ||
array('"this;should,not=matter"', array(new AcceptHeaderItem('this;should,not=matter'))), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider provideToStringData | ||
*/ | ||
public function testToString(array $items, $string) | ||
{ | ||
$header = new AcceptHeader($items); | ||
$this->assertEquals($string, (string) $header); | ||
} | ||
|
||
public function provideToStringData() | ||
{ | ||
return array( | ||
array(array(), ''), | ||
array(array(new AcceptHeaderItem('gzip')), 'gzip'), | ||
array(array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')), 'gzip,deflate,sdch'), | ||
array(array(new AcceptHeaderItem('this;should,not=matter')), 'this;should,not=matter'), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider provideFilterData | ||
*/ | ||
public function testFilter($string, $filter, array $values) | ||
{ | ||
$header = AcceptHeader::fromString($string)->filter($filter); | ||
$this->assertEquals($values, array_keys($header->all())); | ||
} | ||
|
||
public function provideFilterData() | ||
{ | ||
return array( | ||
array('fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', '/fr.*/', array('fr-FR', 'fr')), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider provideSortingData | ||
*/ | ||
public function testSorting($string, array $values) | ||
{ | ||
$header = AcceptHeader::fromString($string); | ||
$this->assertEquals($values, array_keys($header->all())); | ||
} | ||
|
||
public function provideSortingData() | ||
{ | ||
return array( | ||
'quality has priority' => array('*;q=0.3,ISO-8859-1,utf-8;q=0.7', array('ISO-8859-1', 'utf-8', '*')), | ||
'order matters when q is equal' => array('*;q=0.3,ISO-8859-1;q=0.7,utf-8;q=0.7', array('ISO-8859-1', 'utf-8', '*')), | ||
'order matters when q is equal2' => array('*;q=0.3,utf-8;q=0.7,ISO-8859-1;q=0.7', array('utf-8', 'ISO-8859-1', '*')), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider provideDefaultValueData | ||
*/ | ||
public function testDefaultValue($acceptHeader, $value, $expectedQuality) | ||
{ | ||
$header = AcceptHeader::fromString($acceptHeader); | ||
$this->assertSame($expectedQuality, $header->get($value)->getQuality()); | ||
} | ||
|
||
public function provideDefaultValueData() | ||
{ | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, *;q=0.3', 'text/xml', 0.3); | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', 'text/xml', 0.3); | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', 'text/html', 1.0); | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', 'text/plain', 0.5); | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*;q=0.3', '*', 0.3); | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*', '*', 1.0); | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*', 'text/xml', 1.0); | ||
yield array('text/plain;q=0.5, text/html, text/x-dvi;q=0.8, */*', 'text/*', 1.0); | ||
yield array('text/plain;q=0.5, text/html, text/*;q=0.8, */*', 'text/*', 0.8); | ||
yield array('text/plain;q=0.5, text/html, text/*;q=0.8, */*', 'text/html', 1.0); | ||
yield array('text/plain;q=0.5, text/html, text/*;q=0.8, */*', 'text/x-dvi', 0.8); | ||
yield array('*;q=0.3, ISO-8859-1;q=0.7, utf-8;q=0.7', '*', 0.3); | ||
yield array('*;q=0.3, ISO-8859-1;q=0.7, utf-8;q=0.7', 'utf-8', 0.7); | ||
yield array('*;q=0.3, ISO-8859-1;q=0.7, utf-8;q=0.7', 'SHIFT_JIS', 0.3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpFoundation\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\ApacheRequest; | ||
|
||
class ApacheRequestTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideServerVars | ||
*/ | ||
public function testUriMethods($server, $expectedRequestUri, $expectedBaseUrl, $expectedPathInfo) | ||
{ | ||
$request = new ApacheRequest(); | ||
$request->server->replace($server); | ||
|
||
$this->assertEquals($expectedRequestUri, $request->getRequestUri(), '->getRequestUri() is correct'); | ||
$this->assertEquals($expectedBaseUrl, $request->getBaseUrl(), '->getBaseUrl() is correct'); | ||
$this->assertEquals($expectedPathInfo, $request->getPathInfo(), '->getPathInfo() is correct'); | ||
} | ||
|
||
public function provideServerVars() | ||
{ | ||
return array( | ||
array( | ||
array( | ||
'REQUEST_URI' => '/foo/app_dev.php/bar', | ||
'SCRIPT_NAME' => '/foo/app_dev.php', | ||
'PATH_INFO' => '/bar', | ||
), | ||
'/foo/app_dev.php/bar', | ||
'/foo/app_dev.php', | ||
'/bar', | ||
), | ||
array( | ||
array( | ||
'REQUEST_URI' => '/foo/bar', | ||
'SCRIPT_NAME' => '/foo/app_dev.php', | ||
), | ||
'/foo/bar', | ||
'/foo', | ||
'/bar', | ||
), | ||
array( | ||
array( | ||
'REQUEST_URI' => '/app_dev.php/foo/bar', | ||
'SCRIPT_NAME' => '/app_dev.php', | ||
'PATH_INFO' => '/foo/bar', | ||
), | ||
'/app_dev.php/foo/bar', | ||
'/app_dev.php', | ||
'/foo/bar', | ||
), | ||
array( | ||
array( | ||
'REQUEST_URI' => '/foo/bar', | ||
'SCRIPT_NAME' => '/app_dev.php', | ||
), | ||
'/foo/bar', | ||
'', | ||
'/foo/bar', | ||
), | ||
array( | ||
array( | ||
'REQUEST_URI' => '/app_dev.php', | ||
'SCRIPT_NAME' => '/app_dev.php', | ||
), | ||
'/app_dev.php', | ||
'/app_dev.php', | ||
'/', | ||
), | ||
array( | ||
array( | ||
'REQUEST_URI' => '/', | ||
'SCRIPT_NAME' => '/app_dev.php', | ||
), | ||
'/', | ||
'', | ||
'/', | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.