|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Fracture\Http\Headers; |
|
5
|
|
|
|
|
6
|
|
|
use Exception; |
|
7
|
|
|
use ReflectionClass; |
|
8
|
|
|
use PHPUnit_Framework_TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class ContentTypeTest extends PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @covers Fracture\Http\Headers\ContentType::__construct |
|
15
|
|
|
* @covers Fracture\Http\Headers\ContentType::prepare |
|
16
|
|
|
* @covers Fracture\Http\Headers\ContentType::getParsedData |
|
17
|
|
|
*/ |
|
18
|
|
|
public function testEmptyInstance() |
|
19
|
|
|
{ |
|
20
|
|
|
$instance = new ContentType; |
|
21
|
|
|
$instance->prepare(); |
|
22
|
|
|
$this->assertEquals(null, $instance->getParsedData()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @covers Fracture\Http\Headers\ContentType::__construct |
|
28
|
|
|
* @covers Fracture\Http\Headers\ContentType::prepare |
|
29
|
|
|
* @covers Fracture\Http\Headers\ContentType::contains |
|
30
|
|
|
* |
|
31
|
|
|
* @covers Fracture\Http\Headers\ContentType::extractData |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testPreparedResult() |
|
34
|
|
|
{ |
|
35
|
|
|
$instance = new ContentType('text/html'); |
|
36
|
|
|
$instance->prepare(); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertTrue($instance->contains('text/html')); |
|
39
|
|
|
$this->assertFalse($instance->contains('image/png')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @covers Fracture\Http\Headers\ContentType::__construct |
|
45
|
|
|
* @covers Fracture\Http\Headers\ContentType::prepare |
|
46
|
|
|
* @covers Fracture\Http\Headers\ContentType::contains |
|
47
|
|
|
* |
|
48
|
|
|
* @covers Fracture\Http\Headers\ContentType::extractData |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testPreparedCustomTypeResult() |
|
51
|
|
|
{ |
|
52
|
|
|
$instance = new ContentType('application/json;version=3'); |
|
53
|
|
|
$instance->prepare(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertTrue($instance->contains('application/json')); |
|
56
|
|
|
$this->assertFalse($instance->contains('application/json;version=3')); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @covers Fracture\Http\Headers\ContentType::__construct |
|
62
|
|
|
* @covers Fracture\Http\Headers\ContentType::setValue |
|
63
|
|
|
* @covers Fracture\Http\Headers\ContentType::prepare |
|
64
|
|
|
* @covers Fracture\Http\Headers\ContentType::contains |
|
65
|
|
|
* |
|
66
|
|
|
* @covers Fracture\Http\Headers\ContentType::extractData |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testPreparedResultAterManualAlteration() |
|
69
|
|
|
{ |
|
70
|
|
|
$instance = new ContentType('application/json'); |
|
71
|
|
|
$instance->setValue('image/png'); |
|
72
|
|
|
$instance->prepare(); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertTrue($instance->contains('image/png')); |
|
75
|
|
|
$this->assertFalse($instance->contains('text/html')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @covers Fracture\Http\Headers\ContentType::__construct |
|
81
|
|
|
* @covers Fracture\Http\Headers\ContentType::setValue |
|
82
|
|
|
* @covers Fracture\Http\Headers\ContentType::prepare |
|
83
|
|
|
* @covers Fracture\Http\Headers\ContentType::getParsedData |
|
84
|
|
|
* |
|
85
|
|
|
* @covers Fracture\Http\Headers\ContentType::extractData |
|
86
|
|
|
* |
|
87
|
|
|
* @dataProvider provideVariousInputs |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testVariousInputs($expected, $parameter) |
|
90
|
|
|
{ |
|
91
|
|
|
$instance = new ContentType; |
|
92
|
|
|
$instance->setValue($parameter); |
|
93
|
|
|
$instance->prepare(); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals($expected, $instance->getParsedData()); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
public function provideVariousInputs() |
|
100
|
|
|
{ |
|
101
|
|
|
return [ |
|
102
|
|
|
[ |
|
103
|
|
|
'expected' => ['value' => 'application/json'], |
|
104
|
|
|
'data' => 'application/json', |
|
105
|
|
|
], |
|
106
|
|
|
[ |
|
107
|
|
|
'expected' => ['value' => 'application/json', 'version' => '1'], |
|
108
|
|
|
'data' => 'application/json;version=1', |
|
109
|
|
|
], |
|
110
|
|
|
[ |
|
111
|
|
|
'expected' => ['value' => 'text/html', 'charset' => 'utf-8'], |
|
112
|
|
|
'data' => 'text/html; charset=utf-8', |
|
113
|
|
|
], |
|
114
|
|
|
[ |
|
115
|
|
|
'expected' => ['value' => 'multipart/form-data', 'boundary' => 'AaB03x'], |
|
116
|
|
|
'data' => 'multipart/form-data; boundary=AaB03x', |
|
117
|
|
|
], |
|
118
|
|
|
[ |
|
119
|
|
|
'expected' => [], |
|
120
|
|
|
'data' => '; ', |
|
121
|
|
|
], |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @covers Fracture\Http\Headers\ContentType::__construct |
|
128
|
|
|
* @covers Fracture\Http\Headers\ContentType::getName |
|
129
|
|
|
*/ |
|
130
|
|
|
public function testGivenName() |
|
131
|
|
|
{ |
|
132
|
|
|
$instance = new ContentType; |
|
133
|
|
|
$this->assertSame('Content-Type', $instance->getName()); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|