LocTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Validate/Sitemap/Loc.php';
  4. /**
  5. * Tests Zend_Validate_Sitemap_Loc
  6. *
  7. */
  8. class Zend_Validate_Sitemap_LocTest extends PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * Validator
  12. *
  13. * @var Zend_Validate_Sitemap_Loc
  14. */
  15. protected $_validator;
  16. /**
  17. * Prepares the environment before running a test
  18. */
  19. protected function setUp()
  20. {
  21. $this->_validator = new Zend_Validate_Sitemap_Loc();
  22. }
  23. /**
  24. * Cleans up the environment after running a test
  25. */
  26. protected function tearDown()
  27. {
  28. $this->_validator = null;
  29. }
  30. /**
  31. * Tests valid locations
  32. *
  33. */
  34. public function testValidLocs()
  35. {
  36. $values = array(
  37. 'http://www.example.com',
  38. 'http://www.example.com/',
  39. 'http://www.exmaple.lan/',
  40. 'https://www.exmaple.com/?foo=bar',
  41. 'http://www.exmaple.com:8080/foo/bar/',
  42. 'https://user:pass@www.exmaple.com:8080/',
  43. 'https://www.exmaple.com/?foo=&quot;bar&apos;&amp;bar=&lt;bat&gt;'
  44. );
  45. foreach ($values as $value) {
  46. $this->assertSame(true, $this->_validator->isValid($value));
  47. }
  48. }
  49. /**
  50. * Tests invalid locations
  51. *
  52. */
  53. public function testInvalidLocs()
  54. {
  55. $values = array(
  56. 'www.example.com',
  57. '/news/',
  58. '#',
  59. new stdClass(),
  60. 42,
  61. 'http:/example.com/',
  62. null,
  63. 'https://www.exmaple.com/?foo="bar\'&bar=<bat>'
  64. );
  65. foreach ($values as $value) {
  66. $this->assertSame(false, $this->_validator->isValid($value));
  67. }
  68. }
  69. }