1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
<?php namespace Aura\Accept;
class CharsetTest extends AcceptTestCase { protected $charset;
protected function newCharset($server = array()) { return new Charset\CharsetNegotiator(new ValueFactory, $server); }
/** * @dataProvider charsetProvider * @param $accept * @param $expect * @param $negotiator_class * @param $value_class */ public function testGetCharset($server, $expect, $negotiator_class, $value_class) { $charset = $this->newCharset($server); $this->assertAcceptValues($charset, $expect, $negotiator_class, $value_class); }
/** * @dataProvider charsetNegotiateProvider * @param $accept * @param $available * @param $expected */ public function testGetCharset_negotiate($server, $available, $expected) { $charset = $this->newCharset($server); $actual = $charset->negotiate($available);
if ($expected === false) { $this->assertFalse($expected, $actual); } else { $this->assertInstanceOf('Aura\Accept\Charset\CharsetValue', $actual->available); $this->assertSame($expected, $actual->available->getValue()); } }
public function charsetProvider() { return array( array( 'server' => array( 'HTTP_ACCEPT_CHARSET' => 'iso-8859-5, unicode-1-1;q=0.8', ), 'expected' => array( array( 'value' => 'iso-8859-5', 'quality' => 1.0, ), array( 'value' => 'ISO-8859-1', 'quality' => 1.0, ), array( 'value' => 'unicode-1-1', 'quality' => 0.8, ), ), 'negotiator_class' => 'Aura\Accept\Charset\CharsetNegotiator', 'value_class' => 'Aura\Accept\Charset\CharsetValue', ) ); }
public function charsetNegotiateProvider() { return array( array( 'server' => array('HTTP_ACCEPT_CHARSET' => 'iso-8859-5, unicode-1-1, *'), 'available' => array(), 'expected' => false, ), array( 'server' => array('HTTP_ACCEPT_CHARSET' => 'iso-8859-5, unicode-1-1, *'), 'available' => array('foo', 'bar'), 'expected' => 'foo' ), array( 'server' => array('HTTP_ACCEPT_CHARSET' => 'iso-8859-5, unicode-1-1, *'), 'available' => array('foo', 'UniCode-1-1'), 'expected' => 'UniCode-1-1' ), array( 'server' => array(), 'available' => array('ISO-8859-5', 'foo'), 'expected' => 'ISO-8859-5' ), array( 'server' => array('HTTP_ACCEPT_CHARSET' => 'ISO-8859-1, baz;q=0'), 'available' => array('baz'), 'expected' => false ), array( 'server' => array('HTTP_ACCEPT_CHARSET' => 'iso-8859-5, unicode-1-1'), 'available' => array('*'), 'expected' => '*' ), ); } }
|