UriTest.php 3.5 KB

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