LastmodTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-2010 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/Lastmod.php';
  24. /**
  25. * Tests Zym_Validate_Sitemap_Lastmod
  26. *
  27. * @category Zend
  28. * @package Zend_Validate
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2010 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_LastmodTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Validator
  38. *
  39. * @var Zend_Validate_Sitemap_Lastmod
  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_Lastmod();
  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 change frequencies
  58. *
  59. */
  60. public function testValidChangefreqs()
  61. {
  62. $values = array(
  63. '1994-05-11T18:00:09-08:45',
  64. '1997-05-11T18:50:09+00:00',
  65. '1998-06-11T01:00:09-02:00',
  66. '1999-11-11T22:23:52+02:00',
  67. '1999-11-11T22:23+02:00',
  68. '2000-06-11',
  69. '2001-04-14',
  70. '2003-01-13',
  71. '2005-01-01',
  72. '2006-03-19',
  73. '2007-08-31',
  74. '2007-08-25'
  75. );
  76. foreach ($values as $value) {
  77. $this->assertSame(true, $this->_validator->isValid($value));
  78. }
  79. }
  80. /**
  81. * Tests strings that should be invalid
  82. *
  83. */
  84. public function testInvalidStrings()
  85. {
  86. $values = array(
  87. '1995-05-11T18:60:09-08:45',
  88. '1996-05-11T18:50:09+25:00',
  89. '2002-13-11',
  90. '2004-00-01',
  91. '2006-01-01\n'
  92. );
  93. foreach ($values as $value) {
  94. $this->assertSame(false, $this->_validator->isValid($value));
  95. $messages = $this->_validator->getMessages();
  96. $this->assertContains('is not a valid', current($messages));
  97. }
  98. }
  99. /**
  100. * Tests values that are not strings
  101. *
  102. */
  103. public function testNotString()
  104. {
  105. $values = array(
  106. 1, 1.4, null, new stdClass(), true, false
  107. );
  108. foreach ($values as $value) {
  109. $this->assertSame(false, $this->_validator->isValid($value));
  110. $messages = $this->_validator->getMessages();
  111. $this->assertContains('String expected', current($messages));
  112. }
  113. }
  114. }