2
0

UriTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Uri
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_UriTest::main');
  24. }
  25. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../TestHelper.php';
  29. /**
  30. * Zend_Uri
  31. */
  32. require_once 'Zend/Uri.php';
  33. /**
  34. * Zend_Config
  35. */
  36. require_once 'Zend/Config.php';
  37. /**
  38. * @category Zend
  39. * @package Zend_Uri
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. * @group Zend_Uri
  44. */
  45. class Zend_UriTest extends PHPUnit_Framework_TestCase
  46. {
  47. public static function main()
  48. {
  49. $suite = new PHPUnit_Framework_TestSuite("Zend_UriTest");
  50. $result = PHPUnit_TextUI_TestRunner::run($suite);
  51. }
  52. public function setUp()
  53. {
  54. $this->notices = array();
  55. $this->errorReporting = error_reporting();
  56. $this->displayErrors = ini_get('display_errors');
  57. }
  58. public function tearDown()
  59. {
  60. error_reporting($this->errorReporting);
  61. ini_set('display_errors', $this->displayErrors);
  62. }
  63. public function testSchemeEmpty()
  64. {
  65. $this->_testInvalidUri('', '/empty/i');
  66. $this->_testInvalidUri('://www.zend.com', '/empty/i');
  67. }
  68. public function testSchemeUnsupported()
  69. {
  70. $this->_testInvalidUri('unsupported', '/unsupported/i');
  71. $this->_testInvalidUri('unsupported://zend.com', '/unsupported/i');
  72. }
  73. public function testSchemeIllegal()
  74. {
  75. $this->_testInvalidUri('!@#$%^&*()', '/illegal/i');
  76. }
  77. public function testSchemeHttp()
  78. {
  79. $this->_testValidUri('http');
  80. }
  81. public function testSchemeHttps()
  82. {
  83. $this->_testValidUri('https');
  84. }
  85. public function testSchemeMailto()
  86. {
  87. $this->markTestIncomplete('Zend_Uri_Mailto is not implemented yet');
  88. $this->_testValidUri('mailto');
  89. }
  90. /**
  91. * Tests that Zend_Uri::setConfig() allows Zend_Config
  92. *
  93. * @group ZF-5578
  94. */
  95. public function testSetConfigWithArray()
  96. {
  97. Zend_Uri::setConfig(array('allow_unwise' => true));
  98. }
  99. /**
  100. * Tests that Zend_Uri::setConfig() allows Array
  101. *
  102. * @group ZF-5578
  103. */
  104. public function testSetConfigWithZendConfig()
  105. {
  106. Zend_Uri::setConfig(new Zend_Config(array('allow_unwise' => true)));
  107. }
  108. /**
  109. * Tests that Zend_Uri::setConfig() throws Zend_Uri_Exception if no array
  110. * nor Zend_Config is given as first parameter
  111. *
  112. * @group ZF-5578
  113. * @expectedException Zend_Uri_Exception
  114. */
  115. public function testSetConfigInvalid()
  116. {
  117. Zend_Uri::setConfig('This should cause an exception');
  118. }
  119. /**
  120. * Tests that an invalid $uri throws an exception and that the
  121. * message of that exception matches $regex.
  122. *
  123. * @param string $uri
  124. * @param string $regex
  125. */
  126. protected function _testInvalidUri($uri, $regex)
  127. {
  128. $e = null;
  129. try {
  130. $uri = Zend_Uri::factory($uri);
  131. } catch (Zend_Uri_Exception $e) {
  132. $this->assertRegExp($regex, $e->getMessage());
  133. return;
  134. }
  135. $this->fail('Zend_Uri_Exception was expected but not thrown');
  136. }
  137. /**
  138. * Tests that a valid $uri returns a Zend_Uri object.
  139. *
  140. * @param string $uri
  141. */
  142. protected function _testValidUri($uri)
  143. {
  144. $uri = Zend_Uri::factory($uri);
  145. $this->assertTrue($uri instanceof Zend_Uri, 'Zend_Uri object not returned.');
  146. }
  147. }
  148. // Call Zend_UriTest::main() if this source file is executed directly.
  149. if (PHPUnit_MAIN_METHOD == "Zend_UriTest::main") {
  150. Zend_UriTest::main();
  151. }