1
|
|
|
<?php |
2
|
|
|
namespace Browscap\BrowscapBundle\Tests; |
3
|
|
|
|
4
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
5
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
6
|
|
|
|
7
|
|
|
class BrowscapTest extends WebTestCase |
8
|
|
|
{ |
9
|
|
|
protected static function createKernel(array $options = array()) |
10
|
|
|
{ |
11
|
|
|
$env = @$options['env'] ?: 'test'; |
12
|
|
|
|
13
|
|
|
return new AppKernel($env, true); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
$fs = new Filesystem(); |
19
|
|
|
$fs->remove(sys_get_temp_dir().'/BrowscapBundle/'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function tearDown() |
23
|
|
|
{ |
24
|
|
|
static::$kernel = null; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testService() { |
28
|
|
|
|
29
|
|
|
$client = static::createClient(); |
30
|
|
|
|
31
|
|
|
$bc = $client->getContainer()->get('browscap'); |
32
|
|
|
|
33
|
|
|
$this->assertInstanceOf('Browscap\BrowscapBundle\Browscap', $bc); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider getBrowsers |
38
|
|
|
*/ |
39
|
|
|
public function testBrowsers($browser, array $expected) { |
40
|
|
|
|
41
|
|
|
$client = static::createClient(); |
42
|
|
|
|
43
|
|
|
$bc = $client->getContainer()->get('browscap'); |
44
|
|
|
$result = $bc->getBrowser($browser, true); |
45
|
|
|
|
46
|
|
|
foreach ($expected as $key => $value) { |
47
|
|
|
|
48
|
|
|
$this->assertEquals($value, $result[$key]); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Data Provider for testBrowsers |
54
|
|
|
*/ |
55
|
|
|
public function getBrowsers() { |
56
|
|
|
|
57
|
|
|
return array( |
58
|
|
|
array( |
59
|
|
|
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/24.0', |
60
|
|
|
array( |
61
|
|
|
'Parent' => 'Firefox 24.0', |
62
|
|
|
'Platform' => 'Linux', |
63
|
|
|
'CssVersion' => 3, |
64
|
|
|
), |
65
|
|
|
), |
66
|
|
|
array( |
67
|
|
|
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', |
68
|
|
|
array( |
69
|
|
|
'Parent' => 'IE 10.0', |
70
|
|
|
'Platform' => 'Win7', |
71
|
|
|
'CssVersion' => 3, |
72
|
|
|
), |
73
|
|
|
), |
74
|
|
|
array( |
75
|
|
|
'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', |
76
|
|
|
array( |
77
|
|
|
'Parent' => 'Android Browser 4.0', |
78
|
|
|
'Platform' => 'Android', |
79
|
|
|
'CssVersion' => 3, |
80
|
|
|
'isMobileDevice' => true, |
81
|
|
|
), |
82
|
|
|
), |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|