summaryrefslogtreecommitdiff
path: root/tests/Framework/Browser.php
blob: ac92e41e9b4ce38ca73569be3ecdaf60f458237c (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php

/**
 * Test class to test rcube_browser class
 *
 * @package Tests
 */
class Framework_Browser extends PHPUnit_Framework_TestCase
{

    /**
     * Class constructor
     */
    function test_class()
    {
        $object = new rcube_browser();

        $this->assertInstanceOf('rcube_browser', $object, "Class constructor");
    }

    /**
     * @dataProvider browsers
     */
    function test_browser($useragent, $opera, $chrome, $ie, $ns, $ns4, $khtml, $safari, $mz)
    {

        $object = $this->getBrowser($useragent);

        $this->assertEquals($opera, $object->opera, 'Check for Opera failed');
        $this->assertEquals($chrome, $object->chrome, 'Check for Chrome failed');
        $this->assertEquals($ie, $object->ie, 'Check for IE failed');
        $this->assertEquals($ns, $object->ns, 'Check for NS failed');
        $this->assertEquals($ns4, $object->ns4, 'Check for NS4 failed');
        $this->assertEquals($khtml, $object->khtml, 'Check for khtml failed');
        $this->assertEquals($safari, $object->safari, 'Check for Safari failed');
        $this->assertEquals($mz, $object->mz, 'Check for MZ failed');
    }

    /**
     * @dataProvider os
     */
    function test_os($useragent, $windows, $linux, $unix, $mac)
    {
        $object = $this->getBrowser($useragent);

        $this->assertEquals($windows, $object->win, 'Check Result of Windows');
        $this->assertEquals($linux, $object->linux, 'Check Result of Linux');
        $this->assertEquals($mac, $object->mac, 'Check Result of Mac');
        $this->assertEquals($unix, $object->unix, 'Check Result of Unix');

    }

    /**
     * @dataProvider versions
     */
    function test_version($useragent, $version)
    {
        $object = $this->getBrowser($useragent);
        $this->assertEquals($version, $object->ver);
    }

    /**
     * @dataProvider dom
     */
    function test_dom($useragent, $dom)
    {
        $object = $this->getBrowser($useragent);
        $this->assertEquals($dom, $object->dom);

    }

    /**
     * @dataProvider pngalpha
     */
    function test_pngalpha($useragent, $pngalpha)
    {
        $object = $this->getBrowser($useragent);
        $this->assertEquals($pngalpha, $object->pngalpha);
    }

    /**
     * @dataProvider imgdata
     */
    function test_imgdata($useragent, $imgdata)
    {
        $object = $this->getBrowser($useragent);
        $this->assertEquals($imgdata, $object->imgdata);
    }

    function versions()
    {
        return $this->extractDataSet(array('version'));
    }

    function pngalpha()
    {
        return $this->extractDataSet(array('canPNGALPHA'));
    }

    function imgdata()
    {
        return $this->extractDataSet(array('canIMGDATA'));
    }

    private function extractDataSet($keys)
    {
        $keys = array_merge(array('useragent'), $keys);

        $browser = $this->useragents();

        $extracted = array();

        foreach ($browser as $label => $data) {
            foreach($keys as $key) {
                $extracted[$data['useragent']][] = $data[$key];
            }

        }

        return $extracted;
    }

    function lang()
    {
        return $this->extractDataSet(array('lang'));
    }

    function dom()
    {
        return $this->extractDataSet(array('hasDOM'));
    }

    function browsers()
    {
        return $this->extractDataSet(array('isOpera','isChrome','isIE','isNS','isNS4','isKHTML','isSafari','isMZ'));
    }

    function useragents()
    {
        return array(
             'WIN: Mozilla Firefox ' => array(
                 'useragent'    => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
                 'version'      => '1.8',                                                                                      //Version
                 'isWin'        => true,                                                                                           //isWindows
                 'isLinux'      => false,
                 'isMac'        => false,                                                                                           //isMac
                 'isUnix'       => false,                                                                                           //isUnix
                 'isOpera'      => false,                                                                                           //isOpera
                 'isChrome'     => false,                                                                                           //isChrome
                 'isIE'         => false,                                                                                           //isIE
                 'isNS'         => false,                                                                                           //isNS
                 'isNS4'        => false,                                                                                           //isNS4
                 'isKHTML'      => false,                                                                                           //isKHTML
                 'isSafari'     => false,                                                                                           //isSafari
                 'isMZ'         => true,                                                                                           //isMZ
                 'lang'         => 'en-US',                                                                               //lang
                 'hasDOM'       => true,                                                                                            //hasDOM
                 'canPNGALPHA'  => true,                                                                                            //canPNGALPHA
                 'canIMGDATA'   => true,                                                                                            //canIMGDATA
             ),
            'LINUX: Bon Echo ' => array(
                 'useragent'    => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20070222 BonEcho/2.0.0.1',
                 'version'      => '1.8',                                                                                      //Version
                 'isWin'        => false,                                                                                           //isWindows
                 'isLinux'      => true,
                 'isMac'        => false,                                                                                           //isMac
                 'isUnix'       => false,                                                                                           //isUnix
                 'isOpera'      => false,                                                                                           //isOpera
                 'isChrome'     => false,                                                                                           //isChrome
                 'isIE'         => false,                                                                                           //isIE
                 'isNS'         => false,                                                                                           //isNS
                 'isNS4'        => false,                                                                                           //isNS4
                 'isKHTML'      => false,                                                                                           //isKHTML
                 'isSafari'     => false,                                                                                           //isSafari
                 'isMZ'         => true,                                                                                           //isMZ
                 'lang'         => 'en-US',                                                                               //lang
                 'hasDOM'       => true,                                                                                            //hasDOM
                 'canPNGALPHA'  => true,                                                                                            //canPNGALPHA
                 'canIMGDATA'   => true,                                                                                            //canIMGDATA
             ),

            'Chrome Mac' => array(
                 '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',
                 'version'      => '5',                                                                                      //Version
                 'isWin'        => false,                                                                                           //isWindows
                 'isLinux'      => false,
                 'isMac'        => true,                                                                                           //isMac
                 'isUnix'       => false,                                                                                           //isUnix
                 'isOpera'      => false,                                                                                           //isOpera
                 'isChrome'     => true,                                                                                           //isChrome
                 'isIE'         => false,                                                                                           //isIE
                 'isNS'         => false,                                                                                           //isNS
                 'isNS4'        => false,                                                                                           //isNS4
                 'isKHTML'      => true,                                                                                           //isKHTML
                 'isSafari'     => false,                                                                                           //isSafari
                 'isMZ'         => false,                                                                                           //isMZ
                 'lang'         => 'en-US',                                                                               //lang
                 'hasDOM'       => false,                                                                                            //hasDOM
                 'canPNGALPHA'  => false,                                                                                            //canPNGALPHA
                 'canIMGDATA'   => true,                                                                                            //canIMGDATA
             ),

            'IE 11' => array(
                 'useragent'    => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
                 'version'      => '11.0',                                                                                      //Version
                 'isWin'        => true,                                                                                           //isWindows
                 'isLinux'      => false,
                 'isMac'        => false,                                                                                           //isMac
                 'isUnix'       => false,                                                                                           //isUnix
                 'isOpera'      => false,                                                                                           //isOpera
                 'isChrome'     => false,                                                                                           //isChrome
                 'isIE'         => true,                                                                                           //isIE
                 'isNS'         => false,                                                                                           //isNS
                 'isNS4'        => false,                                                                                           //isNS4
                 'isKHTML'      => false,                                                                                           //isKHTML
                 'isSafari'     => false,                                                                                           //isSafari
                 'isMZ'         => false,                                                                                           //isMZ
                 'lang'         => '',                                                                                         //lang
                 'hasDOM'       => true,                                                                                            //hasDOM
                 'canPNGALPHA'  => true,                                                                                            //canPNGALPHA
                 'canIMGDATA'   => false,                                                                                            //canIMGDATA
             ),
        );
    }

    function os()
    {
        return $this->extractDataSet(array('isWin','isLinux','isUnix','isMac'));
    }

    /**
     * @param string $useragent
     * @return rcube_browser
     */
    private function getBrowser($useragent)
    {
        /** @var $object rcube_browser */
        $_SERVER['HTTP_USER_AGENT'] = $useragent;

        $object = new rcube_browser();

        return $object;
    }
}