-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUriTest.php
More file actions
executable file
·236 lines (207 loc) · 6.45 KB
/
UriTest.php
File metadata and controls
executable file
·236 lines (207 loc) · 6.45 KB
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
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Uri
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id $
*/
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'Zend_UriTest::main');
}
/**
* Zend_Uri
*/
require_once 'Zend/Uri.php';
/**
* Zend_Config
*/
require_once 'Zend/Config.php';
/**
* @category Zend
* @package Zend_Uri
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Uri
*/
class Zend_UriTest extends PHPUnit_Framework_TestCase
{
public static function main()
{
$suite = new PHPUnit_Framework_TestSuite("Zend_UriTest");
$result = PHPUnit_TextUI_TestRunner::run($suite);
}
public function setUp()
{
$this->notices = array();
$this->errorReporting = error_reporting();
$this->displayErrors = ini_get('display_errors');
}
public function tearDown()
{
error_reporting($this->errorReporting);
ini_set('display_errors', $this->displayErrors);
}
public function testSchemeEmpty()
{
$this->_testInvalidUri('', '/empty/i');
$this->_testInvalidUri('://www.zend.com', '/empty/i');
}
public function testSchemeUnsupported()
{
$this->_testInvalidUri('unsupported', '/unsupported/i');
$this->_testInvalidUri('unsupported://zend.com', '/unsupported/i');
}
public function testSchemeIllegal()
{
$this->_testInvalidUri('!@#$%^&*()', '/illegal/i');
}
public function testSchemeHttp()
{
$this->_testValidUri('http');
}
public function testSchemeHttps()
{
$this->_testValidUri('https');
}
public function testSchemeMailto()
{
$this->markTestIncomplete('Zend_Uri_Mailto is not implemented yet');
$this->_testValidUri('mailto');
}
/**
* Tests that Zend_Uri::setConfig() allows Zend_Config
*
* @group ZF-5578
*/
public function testSetConfigWithArray()
{
Zend_Uri::setConfig(array('allow_unwise' => true));
}
/**
* Tests that Zend_Uri::setConfig() allows Array
*
* @group ZF-5578
*/
public function testSetConfigWithZendConfig()
{
Zend_Uri::setConfig(new Zend_Config(array('allow_unwise' => true)));
}
/**
* Tests that Zend_Uri::setConfig() throws Zend_Uri_Exception if no array
* nor Zend_Config is given as first parameter
*
* @group ZF-5578
* @expectedException Zend_Uri_Exception
*/
public function testSetConfigInvalid()
{
Zend_Uri::setConfig('This should cause an exception');
}
/**
* Tests that if an exception is thrown when calling the __toString()
* method an empty string is returned and a Warning is triggered, instead
* of a Fatal Error being triggered.
*
* @group ZF-10405
*/
public function testToStringRaisesWarningWhenExceptionCaught()
{
$uri = Zend_Uri::factory('http://example.com', 'Zend_Uri_ExceptionCausing');
set_error_handler(array($this, 'handleErrors'), E_USER_WARNING);
$text = sprintf('%s', $uri);
restore_error_handler();
$this->assertTrue(empty($text));
$this->assertTrue(isset($this->error));
$this->assertContains('Exception in getUri()', $this->error);
}
/**
* Error handler for testExceptionThrownInToString()
*
* @group ZF-10405
*/
public function handleErrors($errno, $errstr, $errfile = '', $errline = 0, array $errcontext = array())
{
$this->error = $errstr;
}
/**
* Tests that an invalid $uri throws an exception and that the
* message of that exception matches $regex.
*
* @param string $uri
* @param string $regex
*/
protected function _testInvalidUri($uri, $regex)
{
$e = null;
try {
$uri = Zend_Uri::factory($uri);
} catch (Zend_Uri_Exception $e) {
$this->assertRegExp($regex, $e->getMessage());
return;
}
$this->fail('Zend_Uri_Exception was expected but not thrown');
}
/**
* Tests that a valid $uri returns a Zend_Uri object.
*
* @param string $uri
*/
protected function _testValidUri($uri, $className = null)
{
$uri = Zend_Uri::factory($uri, $className);
$this->assertTrue($uri instanceof Zend_Uri, 'Zend_Uri object not returned.');
return $uri;
}
public function testFactoryWithUnExistingClassThrowException()
{
$this->setExpectedException('Zend_Uri_Exception', '"This_Is_An_Unknown_Class" not found');
Zend_Uri::factory('http://example.net', 'This_Is_An_Unknown_Class');
}
public function testFactoryWithExistingClassButNotImplementingZendUriThrowException()
{
$this->setExpectedException('Zend_Uri_Exception', '"Fake_Zend_Uri" is not an instance of Zend_Uri');
Zend_Uri::factory('http://example.net', 'Fake_Zend_Uri');
}
public function testFactoryWithExistingClassReturnObject()
{
$uri = $this->_testValidUri('http://example.net', 'Zend_Uri_Mock');
$this->assertTrue($uri instanceof Zend_Uri_Mock, 'Zend_Uri_Mock object not returned.');
}
}
class Zend_Uri_Mock extends Zend_Uri
{
protected function __construct($scheme, $schemeSpecific = '') { }
public function getUri() { }
public function valid() { }
}
class Zend_Uri_ExceptionCausing extends Zend_Uri
{
protected function __construct($scheme, $schemeSpecific = '') { }
public function valid() { }
public function getUri()
{
throw new Exception('Exception in getUri()');
}
}
class Fake_Zend_Uri
{
}
// Call Zend_UriTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_UriTest::main") {
Zend_UriTest::main();
}