PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Formagic/Filter/DateTest.php

https://github.com/Weasle/Formagic
PHP | 118 lines | 52 code | 15 blank | 51 comment | 0 complexity | aeef72d6c13eba402fb58bccbd3ba8af MD5 | raw file
  1. <?php
  2. /**
  3. * Formagic
  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
  10. * http://www.formagic-php.net/license-agreement/
  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@formagic-php.net so we can send you a copy immediately.
  14. *
  15. * @author Florian Sonnenburg
  16. * @copyright 2007-2014 Florian Sonnenburg
  17. * @license http://www.formagic-php.net/license-agreement/ New BSD License
  18. */
  19. /**
  20. * Tests Formagic filter public interface
  21. *
  22. * @package Formagic\Tests
  23. * @author Florian Sonnenburg
  24. **/
  25. class Test_Formagic_Filter_Date extends PHPUnit_Framework_TestCase
  26. {
  27. /**
  28. * Filter object
  29. * @var Formagic_Filter_Date
  30. */
  31. private $_filter;
  32. /**
  33. * Setup test case
  34. */
  35. public function setUp()
  36. {
  37. $this->_filter = new Formagic_Filter_Date();
  38. }
  39. /**
  40. * Check if filter instance implements correct interface
  41. */
  42. public function testInterface()
  43. {
  44. $this->assertInstanceOf('Formagic_Filter_Interface', $this->_filter);
  45. }
  46. /**
  47. * Test output for unix timestamp as value
  48. */
  49. public function testFilterUnixTimestamp()
  50. {
  51. $value = time();
  52. $expected = strftime('%x %X', $value);
  53. $actual = $this->_filter->filter($value);
  54. $this->assertEquals($expected, $actual);
  55. }
  56. /**
  57. * Test output for empty date
  58. */
  59. public function testFilterEmptyDate()
  60. {
  61. $value = "0000-00-00";
  62. $filtered = $this->_filter->filter($value);
  63. $this->assertEquals($filtered, 'n/a');
  64. }
  65. /**
  66. * Test output for empty date and time
  67. */
  68. public function testFilterEmptyDateTime()
  69. {
  70. $value = "0000-00-00 00:00:00";
  71. $filtered = $this->_filter->filter($value);
  72. $this->assertEquals($filtered, 'n/a');
  73. }
  74. /**
  75. * Test output for numeric zero date
  76. */
  77. public function testFilterNoDate()
  78. {
  79. $value = "0";
  80. $filtered = $this->_filter->filter($value);
  81. $this->assertEquals($filtered, '');
  82. }
  83. /**
  84. * Test output for correct date
  85. */
  86. public function testFilterDate()
  87. {
  88. $value = "2010-01-01 12:00:00";
  89. $filtered = $this->_filter->filter($value);
  90. $this->assertNotEquals($filtered, $value);
  91. }
  92. /**
  93. * Test date only output
  94. */
  95. public function testFilterOnlyDate()
  96. {
  97. $unixTimestamp = 1299900000;
  98. $value = strftime('%Y-%m-%d', $unixTimestamp);
  99. $expected = strftime('%x', $unixTimestamp);
  100. $actual = $this->_filter->filter($value);
  101. $this->assertEquals($actual, $expected);
  102. }
  103. }