commit | author | age
|
5f8ada
|
1 |
<?php |
AM |
2 |
|
|
3 |
/** |
|
4 |
* Test class to test rcube_browser class |
|
5 |
* |
|
6 |
* @package Tests |
|
7 |
*/ |
|
8 |
class Framework_Browser extends PHPUnit_Framework_TestCase |
|
9 |
{ |
|
10 |
|
|
11 |
/** |
|
12 |
* Class constructor |
|
13 |
*/ |
|
14 |
function test_class() |
|
15 |
{ |
|
16 |
$object = new rcube_browser(); |
|
17 |
|
|
18 |
$this->assertInstanceOf('rcube_browser', $object, "Class constructor"); |
|
19 |
} |
18d802
|
20 |
|
SF |
21 |
/** |
|
22 |
* @dataProvider browsers |
|
23 |
*/ |
3373e4
|
24 |
function test_browser($useragent, $opera, $chrome, $ie, $ns, $safari, $mz) |
18d802
|
25 |
{ |
SF |
26 |
|
|
27 |
$object = $this->getBrowser($useragent); |
|
28 |
|
|
29 |
$this->assertEquals($opera, $object->opera, 'Check for Opera failed'); |
|
30 |
$this->assertEquals($chrome, $object->chrome, 'Check for Chrome failed'); |
|
31 |
$this->assertEquals($ie, $object->ie, 'Check for IE failed'); |
|
32 |
$this->assertEquals($ns, $object->ns, 'Check for NS failed'); |
|
33 |
$this->assertEquals($safari, $object->safari, 'Check for Safari failed'); |
|
34 |
$this->assertEquals($mz, $object->mz, 'Check for MZ failed'); |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* @dataProvider os |
|
39 |
*/ |
|
40 |
function test_os($useragent, $windows, $linux, $unix, $mac) |
|
41 |
{ |
|
42 |
$object = $this->getBrowser($useragent); |
|
43 |
|
|
44 |
$this->assertEquals($windows, $object->win, 'Check Result of Windows'); |
|
45 |
$this->assertEquals($linux, $object->linux, 'Check Result of Linux'); |
|
46 |
$this->assertEquals($mac, $object->mac, 'Check Result of Mac'); |
|
47 |
$this->assertEquals($unix, $object->unix, 'Check Result of Unix'); |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* @dataProvider versions |
|
53 |
*/ |
|
54 |
function test_version($useragent, $version) |
|
55 |
{ |
|
56 |
$object = $this->getBrowser($useragent); |
|
57 |
$this->assertEquals($version, $object->ver); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* @dataProvider dom |
|
62 |
*/ |
|
63 |
function test_dom($useragent, $dom) |
|
64 |
{ |
|
65 |
$object = $this->getBrowser($useragent); |
|
66 |
$this->assertEquals($dom, $object->dom); |
|
67 |
|
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* @dataProvider pngalpha |
|
72 |
*/ |
|
73 |
function test_pngalpha($useragent, $pngalpha) |
|
74 |
{ |
|
75 |
$object = $this->getBrowser($useragent); |
|
76 |
$this->assertEquals($pngalpha, $object->pngalpha); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* @dataProvider imgdata |
|
81 |
*/ |
|
82 |
function test_imgdata($useragent, $imgdata) |
|
83 |
{ |
|
84 |
$object = $this->getBrowser($useragent); |
|
85 |
$this->assertEquals($imgdata, $object->imgdata); |
|
86 |
} |
|
87 |
|
|
88 |
function versions() |
|
89 |
{ |
|
90 |
return $this->extractDataSet(array('version')); |
|
91 |
} |
|
92 |
|
|
93 |
function pngalpha() |
|
94 |
{ |
|
95 |
return $this->extractDataSet(array('canPNGALPHA')); |
|
96 |
} |
|
97 |
|
|
98 |
function imgdata() |
|
99 |
{ |
|
100 |
return $this->extractDataSet(array('canIMGDATA')); |
|
101 |
} |
|
102 |
|
|
103 |
private function extractDataSet($keys) |
|
104 |
{ |
|
105 |
$keys = array_merge(array('useragent'), $keys); |
|
106 |
|
|
107 |
$browser = $this->useragents(); |
|
108 |
|
|
109 |
$extracted = array(); |
|
110 |
|
|
111 |
foreach ($browser as $label => $data) { |
|
112 |
foreach($keys as $key) { |
|
113 |
$extracted[$data['useragent']][] = $data[$key]; |
|
114 |
} |
|
115 |
|
|
116 |
} |
|
117 |
|
|
118 |
return $extracted; |
|
119 |
} |
|
120 |
|
|
121 |
function lang() |
|
122 |
{ |
|
123 |
return $this->extractDataSet(array('lang')); |
|
124 |
} |
|
125 |
|
|
126 |
function dom() |
|
127 |
{ |
|
128 |
return $this->extractDataSet(array('hasDOM')); |
|
129 |
} |
|
130 |
|
|
131 |
function browsers() |
|
132 |
{ |
3373e4
|
133 |
return $this->extractDataSet(array('isOpera','isChrome','isIE','isNS','isSafari','isMZ')); |
18d802
|
134 |
} |
SF |
135 |
|
|
136 |
function useragents() |
|
137 |
{ |
|
138 |
return array( |
|
139 |
'WIN: Mozilla Firefox ' => array( |
|
140 |
'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1', |
|
141 |
'version' => '1.8', //Version |
|
142 |
'isWin' => true, //isWindows |
|
143 |
'isLinux' => false, |
|
144 |
'isMac' => false, //isMac |
|
145 |
'isUnix' => false, //isUnix |
|
146 |
'isOpera' => false, //isOpera |
|
147 |
'isChrome' => false, //isChrome |
|
148 |
'isIE' => false, //isIE |
|
149 |
'isNS' => false, //isNS |
|
150 |
'isSafari' => false, //isSafari |
|
151 |
'isMZ' => true, //isMZ |
|
152 |
'lang' => 'en-US', //lang |
|
153 |
'hasDOM' => true, //hasDOM |
|
154 |
'canPNGALPHA' => true, //canPNGALPHA |
|
155 |
'canIMGDATA' => true, //canIMGDATA |
|
156 |
), |
|
157 |
'LINUX: Bon Echo ' => array( |
|
158 |
'useragent' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20070222 BonEcho/2.0.0.1', |
|
159 |
'version' => '1.8', //Version |
|
160 |
'isWin' => false, //isWindows |
|
161 |
'isLinux' => true, |
|
162 |
'isMac' => false, //isMac |
|
163 |
'isUnix' => false, //isUnix |
|
164 |
'isOpera' => false, //isOpera |
|
165 |
'isChrome' => false, //isChrome |
|
166 |
'isIE' => false, //isIE |
|
167 |
'isNS' => false, //isNS |
|
168 |
'isSafari' => false, //isSafari |
|
169 |
'isMZ' => true, //isMZ |
|
170 |
'lang' => 'en-US', //lang |
|
171 |
'hasDOM' => true, //hasDOM |
|
172 |
'canPNGALPHA' => true, //canPNGALPHA |
|
173 |
'canIMGDATA' => true, //canIMGDATA |
|
174 |
), |
|
175 |
|
|
176 |
'Chrome Mac' => array( |
|
177 |
'useragent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.461.0 Safari/534.3', |
3373e4
|
178 |
'version' => '6', //Version |
18d802
|
179 |
'isWin' => false, //isWindows |
SF |
180 |
'isLinux' => false, |
|
181 |
'isMac' => true, //isMac |
|
182 |
'isUnix' => false, //isUnix |
|
183 |
'isOpera' => false, //isOpera |
|
184 |
'isChrome' => true, //isChrome |
|
185 |
'isIE' => false, //isIE |
|
186 |
'isNS' => false, //isNS |
|
187 |
'isSafari' => false, //isSafari |
|
188 |
'isMZ' => false, //isMZ |
|
189 |
'lang' => 'en-US', //lang |
|
190 |
'hasDOM' => false, //hasDOM |
|
191 |
'canPNGALPHA' => false, //canPNGALPHA |
|
192 |
'canIMGDATA' => true, //canIMGDATA |
|
193 |
), |
741ddc
|
194 |
|
AM |
195 |
'IE 11' => array( |
|
196 |
'useragent' => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko', |
|
197 |
'version' => '11.0', //Version |
|
198 |
'isWin' => true, //isWindows |
|
199 |
'isLinux' => false, |
|
200 |
'isMac' => false, //isMac |
|
201 |
'isUnix' => false, //isUnix |
|
202 |
'isOpera' => false, //isOpera |
|
203 |
'isChrome' => false, //isChrome |
|
204 |
'isIE' => true, //isIE |
|
205 |
'isNS' => false, //isNS |
|
206 |
'isSafari' => false, //isSafari |
|
207 |
'isMZ' => false, //isMZ |
|
208 |
'lang' => '', //lang |
|
209 |
'hasDOM' => true, //hasDOM |
|
210 |
'canPNGALPHA' => true, //canPNGALPHA |
|
211 |
'canIMGDATA' => false, //canIMGDATA |
|
212 |
), |
03f169
|
213 |
|
AM |
214 |
'Opera 15' => array( |
|
215 |
'useragent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36 OPR/15.0.1147.24', |
|
216 |
'version' => '15.0', //Version |
|
217 |
'isWin' => true, //isWindows |
|
218 |
'isLinux' => false, |
|
219 |
'isMac' => false, //isMac |
|
220 |
'isUnix' => false, //isUnix |
|
221 |
'isOpera' => true, //isOpera |
|
222 |
'isChrome' => false, //isChrome |
|
223 |
'isIE' => false, //isIE |
|
224 |
'isNS' => false, //isNS |
|
225 |
'isSafari' => false, //isSafari |
|
226 |
'isMZ' => false, //isMZ |
|
227 |
'lang' => '', //lang |
|
228 |
'hasDOM' => true, //hasDOM |
|
229 |
'canPNGALPHA' => true, //canPNGALPHA |
|
230 |
'canIMGDATA' => true, //canIMGDATA |
|
231 |
), |
18d802
|
232 |
); |
SF |
233 |
} |
|
234 |
|
|
235 |
function os() |
|
236 |
{ |
|
237 |
return $this->extractDataSet(array('isWin','isLinux','isUnix','isMac')); |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* @param string $useragent |
|
242 |
* @return rcube_browser |
|
243 |
*/ |
|
244 |
private function getBrowser($useragent) |
|
245 |
{ |
|
246 |
/** @var $object rcube_browser */ |
|
247 |
$_SERVER['HTTP_USER_AGENT'] = $useragent; |
|
248 |
|
|
249 |
$object = new rcube_browser(); |
|
250 |
|
|
251 |
return $object; |
|
252 |
} |
5f8ada
|
253 |
} |