LocTest.php 3.1 KB

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