1
+ <?php
2
+
3
+ namespace phpbrowscap ;
4
+
5
+ use phpbrowscap \Browscap ;
6
+
7
+ /**
8
+ * Browscap.ini parsing class with caching and update capabilities
9
+ *
10
+ * PHP version 5
11
+ *
12
+ * Copyright (c) 2006-2012 Jonathan Stoppani
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a
15
+ * copy of this software and associated documentation files (the "Software"),
16
+ * to deal in the Software without restriction, including without limitation
17
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18
+ * and/or sell copies of the Software, and to permit persons to whom the
19
+ * Software is furnished to do so, subject to the following conditions:
20
+ *
21
+ * The above copyright notice and this permission notice shall be included
22
+ * in all copies or substantial portions of the Software.
23
+ *
24
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
+ * THE SOFTWARE.
31
+ *
32
+ * @package Browscap
33
+ * @author Vítor Brandão <[email protected] >
34
+ * @copyright Copyright (c) 2006-2012 Jonathan Stoppani
35
+ * @version 1.0
36
+ * @license http://www.opensource.org/licenses/MIT MIT License
37
+ * @link https://github.com/GaretJax/phpbrowscap/
38
+ */
39
+ class BrowscapTest extends TestCase
40
+ {
41
+ public function testProxyAutoDetection ()
42
+ {
43
+ $ browscap = $ this ->createBrowscap ();
44
+
45
+ putenv ('http_proxy=http://proxy.example.com:3128 ' );
46
+ putenv ('https_proxy=http://proxy.example.com:3128 ' );
47
+ putenv ('ftp_proxy=http://proxy.example.com:3128 ' );
48
+
49
+ $ browscap ->autodetectProxySettings ();
50
+ $ options = $ browscap ->getStreamContextOptions ();
51
+
52
+ $ this ->assertEquals ($ options ['http ' ]['proxy ' ], 'tcp://proxy.example.com:3128 ' );
53
+ $ this ->assertTrue ($ options ['http ' ]['request_fulluri ' ]);
54
+
55
+ $ this ->assertEquals ($ options ['https ' ]['proxy ' ], 'tcp://proxy.example.com:3128 ' );
56
+ $ this ->assertTrue ($ options ['https ' ]['request_fulluri ' ]);
57
+
58
+ $ this ->assertEquals ($ options ['ftp ' ]['proxy ' ], 'tcp://proxy.example.com:3128 ' );
59
+ $ this ->assertTrue ($ options ['ftp ' ]['request_fulluri ' ]);
60
+ }
61
+
62
+ public function testAddProxySettings ()
63
+ {
64
+ $ browscap = $ this ->createBrowscap ();
65
+
66
+ $ browscap ->addProxySettings ('proxy.example.com ' , 3128 , 'http ' );
67
+ $ options = $ browscap ->getStreamContextOptions ();
68
+
69
+ $ this ->assertEquals ($ options ['http ' ]['proxy ' ], 'tcp://proxy.example.com:3128 ' );
70
+ $ this ->assertTrue ($ options ['http ' ]['request_fulluri ' ]);
71
+ }
72
+
73
+ public function testClearProxySettings ()
74
+ {
75
+ $ browscap = $ this ->createBrowscap ();
76
+
77
+ $ browscap ->addProxySettings ('proxy.example.com ' , 3128 , 'http ' );
78
+ $ options = $ browscap ->getStreamContextOptions ();
79
+
80
+ $ this ->assertEquals ($ options ['http ' ]['proxy ' ], 'tcp://proxy.example.com:3128 ' );
81
+ $ this ->assertTrue ($ options ['http ' ]['request_fulluri ' ]);
82
+
83
+ $ clearedWrappers = $ browscap ->clearProxySettings ();
84
+ $ options = $ browscap ->getStreamContextOptions ();
85
+
86
+ $ this ->assertEmpty ($ options );
87
+ $ this ->assertEquals ($ clearedWrappers , array ('http ' ));
88
+ }
89
+
90
+ public function testGetStreamContext ()
91
+ {
92
+ $ cacheDir = $ this ->createCacheDir ();
93
+ $ browscap = new BrowscapForTest ($ cacheDir );
94
+
95
+ $ browscap ->addProxySettings ('proxy.example.com ' , 3128 , 'http ' );
96
+
97
+ $ resource = $ browscap ->getStreamContext ();
98
+
99
+ $ this ->assertTrue (is_resource ($ resource ));
100
+ }
101
+ }
102
+
103
+ class BrowscapForTest extends Browscap
104
+ {
105
+ public function getStreamContext ($ recreate = false )
106
+ {
107
+ return $ this ->_getStreamContext ($ recreate );
108
+ }
109
+ }
0 commit comments