7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
17
* @subpackage UnitTests
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
22
if (!defined('PHPUnit_MAIN_METHOD')) {
23
define('PHPUnit_MAIN_METHOD', 'Zend_UriTest::main');
29
require_once dirname(__FILE__) . '/../TestHelper.php';
34
require_once 'Zend/Uri.php';
39
* @subpackage UnitTests
40
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
41
* @license http://framework.zend.com/license/new-bsd New BSD License
43
class Zend_UriTest extends PHPUnit_Framework_TestCase
45
public static function main()
47
$suite = new PHPUnit_Framework_TestSuite("Zend_UriTest");
48
$result = PHPUnit_TextUI_TestRunner::run($suite);
51
public function setUp()
53
$this->notices = array();
54
$this->errorReporting = error_reporting();
55
$this->displayErrors = ini_get('display_errors');
58
public function tearDown()
60
error_reporting($this->errorReporting);
61
ini_set('display_errors', $this->displayErrors);
64
public function testSchemeEmpty()
66
$this->_testInvalidUri('', '/empty/i');
67
$this->_testInvalidUri('://www.zend.com', '/empty/i');
70
public function testSchemeUnsupported()
72
$this->_testInvalidUri('unsupported', '/unsupported/i');
73
$this->_testInvalidUri('unsupported://zend.com', '/unsupported/i');
76
public function testSchemeIllegal()
78
$this->_testInvalidUri('!@#$%^&*()', '/illegal/i');
81
public function testSchemeHttp()
83
$this->_testValidUri('http');
86
public function testSchemeHttps()
88
$this->_testValidUri('https');
91
public function testSchemeMailto()
93
$this->markTestIncomplete('Zend_Uri_Mailto is not implemented yet');
94
$this->_testValidUri('mailto');
98
* Tests that an invalid $uri throws an exception and that the
99
* message of that exception matches $regex.
102
* @param string $regex
104
protected function _testInvalidUri($uri, $regex)
108
$uri = Zend_Uri::factory($uri);
109
} catch (Zend_Uri_Exception $e) {
110
$this->assertRegExp($regex, $e->getMessage());
113
$this->fail('Zend_Uri_Exception was expected but not thrown');
117
* Tests that a valid $uri returns a Zend_Uri object.
121
protected function _testValidUri($uri)
123
$uri = Zend_Uri::factory($uri);
124
$this->assertTrue($uri instanceof Zend_Uri, 'Zend_Uri object not returned.');
129
// Call Zend_UriTest::main() if this source file is executed directly.
130
if (PHPUnit_MAIN_METHOD == "Zend_UriTest::main") {
131
Zend_UriTest::main();