File
2 years ago
Fixtures
2 years ago
Session
2 years ago
schema
2 years ago
AcceptHeaderItemTest.php
2 years ago
AcceptHeaderTest.php
2 years ago
ApacheRequestTest.php
2 years ago
BinaryFileResponseTest.php
2 years ago
CookieTest.php
2 years ago
ExpressionRequestMatcherTest.php
2 years ago
FileBagTest.php
2 years ago
HeaderBagTest.php
2 years ago
IpUtilsTest.php
2 years ago
JsonResponseTest.php
2 years ago
ParameterBagTest.php
2 years ago
RedirectResponseTest.php
2 years ago
RequestMatcherTest.php
2 years ago
RequestStackTest.php
2 years ago
RequestTest.php
2 years ago
ResponseFunctionalTest.php
2 years ago
ResponseHeaderBagTest.php
2 years ago
ResponseTest.php
2 years ago
ResponseTestCase.php
2 years ago
ServerBagTest.php
2 years ago
StreamedResponseTest.php
2 years ago
AcceptHeaderTest.php
107 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | * |
| 11 | * Modified by impress-org on 23-January-2024 using Strauss. |
| 12 | * @see https://github.com/BrianHenryIE/strauss |
| 13 | */ |
| 14 | |
| 15 | namespace Give\Vendors\Symfony\Component\HttpFoundation\Tests; |
| 16 | |
| 17 | use PHPUnit\Framework\TestCase; |
| 18 | use Give\Vendors\Symfony\Component\HttpFoundation\AcceptHeader; |
| 19 | use Give\Vendors\Symfony\Component\HttpFoundation\AcceptHeaderItem; |
| 20 | |
| 21 | class AcceptHeaderTest extends TestCase |
| 22 | { |
| 23 | public function testFirst() |
| 24 | { |
| 25 | $header = AcceptHeader::fromString('text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c'); |
| 26 | $this->assertSame('text/html', $header->first()->getValue()); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @dataProvider provideFromStringData |
| 31 | */ |
| 32 | public function testFromString($string, array $items) |
| 33 | { |
| 34 | $header = AcceptHeader::fromString($string); |
| 35 | $parsed = array_values($header->all()); |
| 36 | // reset index since the fixtures don't have them set |
| 37 | foreach ($parsed as $item) { |
| 38 | $item->setIndex(0); |
| 39 | } |
| 40 | $this->assertEquals($items, $parsed); |
| 41 | } |
| 42 | |
| 43 | public function provideFromStringData() |
| 44 | { |
| 45 | return [ |
| 46 | ['', []], |
| 47 | ['gzip', [new AcceptHeaderItem('gzip')]], |
| 48 | ['gzip,deflate,sdch', [new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')]], |
| 49 | ["gzip, deflate\t,sdch", [new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')]], |
| 50 | ['"this;should,not=matter"', [new AcceptHeaderItem('this;should,not=matter')]], |
| 51 | ]; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @dataProvider provideToStringData |
| 56 | */ |
| 57 | public function testToString(array $items, $string) |
| 58 | { |
| 59 | $header = new AcceptHeader($items); |
| 60 | $this->assertEquals($string, (string) $header); |
| 61 | } |
| 62 | |
| 63 | public function provideToStringData() |
| 64 | { |
| 65 | return [ |
| 66 | [[], ''], |
| 67 | [[new AcceptHeaderItem('gzip')], 'gzip'], |
| 68 | [[new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')], 'gzip,deflate,sdch'], |
| 69 | [[new AcceptHeaderItem('this;should,not=matter')], 'this;should,not=matter'], |
| 70 | ]; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @dataProvider provideFilterData |
| 75 | */ |
| 76 | public function testFilter($string, $filter, array $values) |
| 77 | { |
| 78 | $header = AcceptHeader::fromString($string)->filter($filter); |
| 79 | $this->assertEquals($values, array_keys($header->all())); |
| 80 | } |
| 81 | |
| 82 | public function provideFilterData() |
| 83 | { |
| 84 | return [ |
| 85 | ['fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', '/fr.*/', ['fr-FR', 'fr']], |
| 86 | ]; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @dataProvider provideSortingData |
| 91 | */ |
| 92 | public function testSorting($string, array $values) |
| 93 | { |
| 94 | $header = AcceptHeader::fromString($string); |
| 95 | $this->assertEquals($values, array_keys($header->all())); |
| 96 | } |
| 97 | |
| 98 | public function provideSortingData() |
| 99 | { |
| 100 | return [ |
| 101 | 'quality has priority' => ['*;q=0.3,ISO-8859-1,utf-8;q=0.7', ['ISO-8859-1', 'utf-8', '*']], |
| 102 | 'order matters when q is equal' => ['*;q=0.3,ISO-8859-1;q=0.7,utf-8;q=0.7', ['ISO-8859-1', 'utf-8', '*']], |
| 103 | 'order matters when q is equal2' => ['*;q=0.3,utf-8;q=0.7,ISO-8859-1;q=0.7', ['utf-8', 'ISO-8859-1', '*']], |
| 104 | ]; |
| 105 | } |
| 106 | } |
| 107 |