8000 [HttpFoundation] Fix AcceptHeader · symfony/symfony@395c004 · GitHub
[go: up one dir, main page]

Skip to content

Commit 395c004

Browse files
committed
[HttpFoundation] Fix AcceptHeader
1 parent b126664 commit 395c004

File tree

3 files changed

+71
-65
lines changed

3 files changed

+71
-65
lines changed

src/Symfony/Component/HttpFoundation/AcceptHeader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function first()
146146
{
147147
$this->sort();
148148

149-
return !empty($this->items) ? current($this->items) : null;
149+
return !empty($this->items) ? $this->items[0] : null;
150150
}
151151

152152
/**

src/Symfony/Component/HttpFoundation/Tests/AcceptHeaderItemTest.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@ public function testFromString($string, $value, array $attributes)
2525
$this->assertEquals($attributes, $item->getAttributes());
2626
}
2727

28+
public function provideFromStringData()
29+
{
30+
return array(
31+
array(
32+
'text/html',
33+
'text/html', array()
34+
),
35+
array(
36+
'"this;should,not=matter"',
37+
'this;should,not=matter', array()
38+
),
39+
array(
40+
"text/plain; charset=utf-8;param=\"this;should,not=matter\";\tfootnotes=true",
41+
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true')
42+
),
43+
array(
44+
'"this;should,not=matter";charset=utf-8',
45+
'this;should,not=matter', array('charset' => 'utf-8')
46+
),
47+
);
48+
}
49+
2850
/**
2951
* @dataProvider provideToStringData
3052
*/
@@ -34,6 +56,20 @@ public function testToString($value, array $attributes, $string)
3456
$this->assertEquals($string, (string) $item);
3557
}
3658

59+
public function provideToStringData()
60+
{
61+
return array(
62+
array(
63+
'text/html', array(),
64+
'text/html'
65+
),
66+
array(
67+
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'),
68+
'text/plain;charset=utf-8;param="this;should,not=matter";footnotes=true'
69+
),
70+
);
71+
}
72+
3773
public function testValue()
3874
{
3975
$item = new AcceptHeaderItem('value', array());
@@ -73,40 +109,4 @@ public function testAttribute()
73109
$this->assertEquals('value', $item->getAttribute('test'));
74110
$this->assertEquals('value', $item->getAttribute('test', 'default'));
75111
}
76-
77-
public function provideFromStringData()
78-
{
79-
return array(
80-
array(
81-
'text/html',
82-
'text/html', array()
83-
),
84-
array(
85-
'"this;should,not=matter"',
86-
'this;should,not=matter', array()
87-
),
88-
array(
89-
"text/plain; charset=utf-8;param=\"this;should,not=matter\";\tfootnotes=true",
90-
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true')
91-
),
92-
array(
93-
'"this;should,not=matter";charset=utf-8',
94-
'this;should,not=matter', array('charset' => 'utf-8')
95-
),
96-
);
97-
}
98-
99-
public function provideToStringData()
100-
{
101-
return array(
102-
array(
103-
'text/html', array(),
104-
'text/html'
105-
),
106-
array(
107-
'text/plain', array('charset' => 'utf-8', 'param' => 'this;should,not=matter', 'footnotes' => 'true'),
108-
'text/plain;charset=utf-8;param="this;should,not=matter";footnotes=true'
109-
),
110-
);
111-
}
112112
}

src/Symfony/Component/HttpFoundation/Tests/AcceptHeaderTest.php

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
class AcceptHeaderTest extends \PHPUnit_Framework_TestCase
1818
{
19+
public function testFirst()
20+
{
21+
$header = AcceptHeader::fromString('text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c');
22+
$this->assertSame('text/html', $header->first()->getValue());
23+
}
24+
1925
/**
2026
* @dataProvider provideFromStringData
2127
*/
@@ -30,6 +36,17 @@ public function testFromString($string, array $items)
3036
$this->assertEquals($items, $parsed);
3137
}
3238

39+
public function provideFromStringData()
40+
{
41+
return array(
42+
array('', array()),
43+
array('gzip', array(new AcceptHeaderItem('gzip'))),
44+
array('gzip,deflate,sdch', array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))),
45+
array("gzip, deflate\t,sdch", array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))),
46+
array('"this;should,not=matter"', array(new AcceptHeaderItem('this;should,not=matter'))),
47+
);
48+
}
49+
3350
/**
3451
* @dataProvider provideToStringData
3552
*/
@@ -39,6 +56,16 @@ public function testToString(array $items, $string)
3956
$this->assertEquals($string, (string) $header);
4057
}
4158

59+
public function provideToStringData()
60+
{
61+
return array(
62+
array(array(), ''),
63+
array(array(new AcceptHeaderItem('gzip')), 'gzip'),
64+
array(array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')), 'gzip,deflate,sdch'),
65+
array(array(new AcceptHeaderItem('this;should,not=matter')), 'this;should,not=matter'),
66+
);
67+
}
68+
4269
/**
4370
* @dataProvider provideFilterData
4471
*/
@@ -48,6 +75,13 @@ public function testFilter($string, $filter, array $values)
4875
$this->assertEquals($values, array_keys($header->all()));
4976
}
5077

78+
public function provideFilterData()
79+
{
80+
return array(
81+
array('fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', '/fr.*/', array('fr-FR', 'fr')),
82+
);
83+
}
84+
5185
/**
5286
* @dataProvider provideSortingData
5387
*/
@@ -57,24 +91,6 @@ public function testSorting($string, array $values)
5791
$this->assertEquals($values, array_keys($header->all()));
5892
}
5993

60-
public function provideFromStringData()
61-
{
62-
return array(
63-
array('', array()),
64-
array('gzip', array(new AcceptHeaderItem('gzip'))),
65-
array('gzip,deflate,sdch', array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))),
66-
array("gzip, deflate\t,sdch", array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch'))),
67-
array('"this;should,not=matter"', array(new AcceptHeaderItem('this;should,not=matter'))),
68-
);
69-
}
70-
71-
public function provideFilterData()
72-
{
73-
return array(
74-
array('fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4', '/fr.*/', array('fr-FR', 'fr')),
75-
);
76-
}
77-
7894
public function provideSortingData()
7995
{
8096
return array(
@@ -83,14 +99,4 @@ public function provideSortingData()
8399
'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', '*')),
84100
);
85101
}
86-
87-
public function provideToStringData()
88-
{
89-
return array(
90-
array(array(), ''),
91-
array(array(new AcceptHeaderItem('gzip')), 'gzip'),
92-
array(array(new AcceptHeaderItem('gzip'), new AcceptHeaderItem('deflate'), new AcceptHeaderItem('sdch')), 'gzip,deflate,sdch'),
93-
array(array(new AcceptHeaderItem('this;should,not=matter')), 'this;should,not=matter'),
94-
);
95-
}
96102
}

0 commit comments

Comments
 (0)
0