1
|
|
|
<?php |
2
|
|
|
namespace Fam\Util\UserAgentParser; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
|
6
|
|
|
class UserAgentTest extends TestCase |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @test |
10
|
|
|
*/ |
11
|
|
|
public function os_delegatesReturnValue() |
12
|
|
|
{ |
13
|
|
|
$operatingSystem = $this->createOperatingSystemMock(); |
14
|
|
|
|
15
|
|
|
$operatingSystem->expects($this->once()) |
16
|
|
|
->method('getName') |
17
|
|
|
->will($this->returnValue(__METHOD__)); |
18
|
|
|
|
19
|
|
|
$userAgent = new UserAgent($operatingSystem, $this->createWebClientMock()); |
20
|
|
|
$this->assertEquals(__METHOD__, $userAgent->os()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @test |
25
|
|
|
*/ |
26
|
|
|
public function isOs_delegatesArgumentToOperatingSystem() |
27
|
|
|
{ |
28
|
|
|
$operatingSystem = $this->createOperatingSystemMock(); |
29
|
|
|
|
30
|
|
|
$operatingSystem->expects($this->once()) |
31
|
|
|
->method('equals') |
32
|
|
|
->with($this->equalTo(__METHOD__)); |
33
|
|
|
|
34
|
|
|
$userAgent = new UserAgent($operatingSystem, $this->createWebClientMock()); |
35
|
|
|
$userAgent->isOs(__METHOD__); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @test |
40
|
|
|
*/ |
41
|
|
|
public function isOs_delegatesReturnValue() |
42
|
|
|
{ |
43
|
|
|
$operatingSystem = $this->createOperatingSystemMock(); |
44
|
|
|
|
45
|
|
|
$operatingSystem->expects($this->once()) |
46
|
|
|
->method('equals') |
47
|
|
|
->will($this->returnValue(true)); |
48
|
|
|
|
49
|
|
|
$userAgent = new UserAgent($operatingSystem, $this->createWebClientMock()); |
50
|
|
|
$this->assertTrue($userAgent->isOs(__METHOD__)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @test |
55
|
|
|
*/ |
56
|
|
|
public function webClient_delegatesReturnValue() |
57
|
|
|
{ |
58
|
|
|
$webClient = $this->createWebClientMock(); |
59
|
|
|
|
60
|
|
|
$webClient->expects($this->once()) |
61
|
|
|
->method('getName') |
62
|
|
|
->will($this->returnValue(__METHOD__)); |
63
|
|
|
|
64
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
65
|
|
|
$this->assertEquals(__METHOD__, $userAgent->webClient()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @test |
70
|
|
|
*/ |
71
|
|
|
public function isWebClient_delegatesArgument() |
72
|
|
|
{ |
73
|
|
|
$webClient = $this->createWebClientMock(); |
74
|
|
|
|
75
|
|
|
$webClient->expects($this->once()) |
76
|
|
|
->method('isNameEquals') |
77
|
|
|
->with($this->equalTo(__METHOD__)); |
78
|
|
|
|
79
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
80
|
|
|
$userAgent->isWebClient(__METHOD__); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @test |
85
|
|
|
*/ |
86
|
|
|
public function isWebClient_delegatesReturnValue() |
87
|
|
|
{ |
88
|
|
|
$webClient = $this->createWebClientMock(); |
89
|
|
|
|
90
|
|
|
$webClient->expects($this->once()) |
91
|
|
|
->method('isNameEquals') |
92
|
|
|
->will($this->returnValue(true)); |
93
|
|
|
|
94
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
95
|
|
|
$this->assertTrue($userAgent->isWebClient(__METHOD__)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @test |
100
|
|
|
*/ |
101
|
|
|
public function webClientVersion_delegatesReturnValue() |
102
|
|
|
{ |
103
|
|
|
$webClient = $this->createWebClientMock(); |
104
|
|
|
|
105
|
|
|
$webClient->expects($this->once()) |
106
|
|
|
->method('getVersion') |
107
|
|
|
->will($this->returnValue(__METHOD__)); |
108
|
|
|
|
109
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
110
|
|
|
$this->assertEquals(__METHOD__, $userAgent->webClientVersion()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @test |
115
|
|
|
*/ |
116
|
|
|
public function isWebClientVersion_delegatesArgument() |
117
|
|
|
{ |
118
|
|
|
$webClient = $this->createWebClientMock(); |
119
|
|
|
|
120
|
|
|
$webClient->expects($this->once()) |
121
|
|
|
->method('isVersionEquals') |
122
|
|
|
->with($this->equalTo(__METHOD__)); |
123
|
|
|
|
124
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
125
|
|
|
$userAgent->isWebClientVersion(__METHOD__); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @test |
130
|
|
|
*/ |
131
|
|
|
public function isWebClientVersion_delegatesReturnValue() |
132
|
|
|
{ |
133
|
|
|
$webClient = $this->createWebClientMock(); |
134
|
|
|
|
135
|
|
|
$webClient->expects($this->once()) |
136
|
|
|
->method('isVersionEquals') |
137
|
|
|
->will($this->returnValue(true)); |
138
|
|
|
|
139
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
140
|
|
|
$this->assertTrue($userAgent->isWebClientVersion(__METHOD__)); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @test |
145
|
|
|
*/ |
146
|
|
|
public function isWebClientVersionBetween_delegatesArguments() |
147
|
|
|
{ |
148
|
|
|
$webClient = $this->createWebClientMock(); |
149
|
|
|
|
150
|
|
|
$webClient->expects($this->once()) |
151
|
|
|
->method('isVersionBetween') |
152
|
|
|
->with($this->equalTo(__CLASS__), $this->equalTo(__FUNCTION__)); |
153
|
|
|
|
154
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
155
|
|
|
$userAgent->isWebClientVersionBetween(__CLASS__, __FUNCTION__); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @test |
160
|
|
|
*/ |
161
|
|
|
public function isWebClientVersionBetween_delegatesReturnValue() |
162
|
|
|
{ |
163
|
|
|
$webClient = $this->createWebClientMock(); |
164
|
|
|
|
165
|
|
|
$webClient->expects($this->once()) |
166
|
|
|
->method('isVersionBetween') |
167
|
|
|
->will($this->returnValue(true)); |
168
|
|
|
|
169
|
|
|
$userAgent = new UserAgent($this->createOperatingSystemMock(), $webClient); |
170
|
|
|
$this->assertTrue($userAgent->isWebClientVersionBetween(__CLASS__, __FUNCTION__)); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return PHPUnit_Framework_MockObject_MockObject |
175
|
|
|
*/ |
176
|
|
|
private function createOperatingSystemMock() |
177
|
|
|
{ |
178
|
|
|
return $this->getMockBuilder(OperatingSystem::class)->getMock(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return PHPUnit_Framework_MockObject_MockObject |
183
|
|
|
*/ |
184
|
|
|
private function createWebClientMock() |
185
|
|
|
{ |
186
|
|
|
return $this->getMockBuilder(WebClient::class)->getMock(); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|