LocTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_Translate
  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. require_once 'PHPUnit/Framework/TestCase.php';
  23. require_once 'Zend/Validate/Sitemap/Loc.php';
  24. /**
  25. * Tests Zend_Validate_Sitemap_Loc
  26. *
  27. * @category Zend
  28. * @package Zend_Validate
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Validate
  33. */
  34. class Zend_Validate_Sitemap_LocTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Validator
  38. *
  39. * @var Zend_Validate_Sitemap_Loc
  40. */
  41. protected $_validator;
  42. /**
  43. * Prepares the environment before running a test
  44. */
  45. protected function setUp()
  46. {
  47. $this->_validator = new Zend_Validate_Sitemap_Loc();
  48. }
  49. /**
  50. * Cleans up the environment after running a test
  51. */
  52. protected function tearDown()
  53. {
  54. $this->_validator = null;
  55. }
  56. /**
  57. * Tests valid locations
  58. *
  59. */
  60. public function testValidLocs()
  61. {
  62. $values = array(
  63. 'http://www.example.com',
  64. 'http://www.example.com/',
  65. 'http://www.exmaple.lan/',
  66. 'https://www.exmaple.com/?foo=bar',
  67. 'http://www.exmaple.com:8080/foo/bar/',
  68. 'https://user:pass@www.exmaple.com:8080/',
  69. 'https://www.exmaple.com/?foo=&quot;bar&apos;&amp;bar=&lt;bat&gt;'
  70. );
  71. foreach ($values as $value) {
  72. $this->assertSame(true, $this->_validator->isValid($value));
  73. }
  74. }
  75. /**
  76. * Tests invalid locations
  77. *
  78. */
  79. public function testInvalidLocs()
  80. {
  81. $values = array(
  82. 'www.example.com',
  83. '/news/',
  84. '#',
  85. new stdClass(),
  86. 42,
  87. 'http:/example.com/',
  88. null,
  89. 'https://www.exmaple.com/?foo="bar\'&bar=<bat>'
  90. );
  91. foreach ($values as $value) {
  92. $this->assertSame(false, $this->_validator->isValid($value));
  93. }
  94. }
  95. }