UriTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. if (!defined('PHPUnit_MAIN_METHOD')) {
  22. define('PHPUnit_MAIN_METHOD', 'Zend_UriTest::main');
  23. }
  24. /**
  25. * Test helper
  26. */
  27. require_once dirname(__FILE__) . '/../TestHelper.php';
  28. /**
  29. * Zend_Uri
  30. */
  31. require_once 'Zend/Uri.php';
  32. /**
  33. * @category Zend
  34. * @package Zend_Uri
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_UriTest extends PHPUnit_Framework_TestCase
  40. {
  41. public static function main()
  42. {
  43. $suite = new PHPUnit_Framework_TestSuite("Zend_UriTest");
  44. $result = PHPUnit_TextUI_TestRunner::run($suite);
  45. }
  46. public function setUp()
  47. {
  48. $this->notices = array();
  49. $this->errorReporting = error_reporting();
  50. $this->displayErrors = ini_get('display_errors');
  51. }
  52. public function tearDown()
  53. {
  54. error_reporting($this->errorReporting);
  55. ini_set('display_errors', $this->displayErrors);
  56. }
  57. public function testSchemeEmpty()
  58. {
  59. $this->_testInvalidUri('', '/empty/i');
  60. $this->_testInvalidUri('://www.zend.com', '/empty/i');
  61. }
  62. public function testSchemeUnsupported()
  63. {
  64. $this->_testInvalidUri('unsupported', '/unsupported/i');
  65. $this->_testInvalidUri('unsupported://zend.com', '/unsupported/i');
  66. }
  67. public function testSchemeIllegal()
  68. {
  69. $this->_testInvalidUri('!@#$%^&*()', '/illegal/i');
  70. }
  71. public function testSchemeHttp()
  72. {
  73. $this->_testValidUri('http');
  74. }
  75. public function testSchemeHttps()
  76. {
  77. $this->_testValidUri('https');
  78. }
  79. public function testSchemeMailto()
  80. {
  81. $this->markTestIncomplete('Zend_Uri_Mailto is not implemented yet');
  82. $this->_testValidUri('mailto');
  83. }
  84. /**
  85. * Tests that an invalid $uri throws an exception and that the
  86. * message of that exception matches $regex.
  87. *
  88. * @param string $uri
  89. * @param string $regex
  90. */
  91. protected function _testInvalidUri($uri, $regex)
  92. {
  93. $e = null;
  94. try {
  95. $uri = Zend_Uri::factory($uri);
  96. } catch (Zend_Uri_Exception $e) {
  97. $this->assertRegExp($regex, $e->getMessage());
  98. return;
  99. }
  100. $this->fail('Zend_Uri_Exception was expected but not thrown');
  101. }
  102. /**
  103. * Tests that a valid $uri returns a Zend_Uri object.
  104. *
  105. * @param string $uri
  106. */
  107. protected function _testValidUri($uri)
  108. {
  109. $uri = Zend_Uri::factory($uri);
  110. $this->assertTrue($uri instanceof Zend_Uri, 'Zend_Uri object not returned.');
  111. }
  112. }
  113. // Call Zend_UriTest::main() if this source file is executed directly.
  114. if (PHPUnit_MAIN_METHOD == "Zend_UriTest::main") {
  115. Zend_UriTest::main();
  116. }