date.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * Date class tests
  15. *
  16. * @group Core
  17. * @group Date
  18. */
  19. class Test_Date extends TestCase
  20. {
  21. /**
  22. * Test for Date::days_in_month()
  23. *
  24. * @test
  25. */
  26. public function test_days_in_month()
  27. {
  28. $output = Date::days_in_month(8);
  29. $expected = 31;
  30. $this->assertEquals($expected, $output);
  31. $output = Date::days_in_month(2,2001);
  32. $expected = 28;
  33. $this->assertEquals($expected, $output);
  34. $output = Date::days_in_month(2,2000);
  35. $expected = 29;
  36. $this->assertEquals($expected, $output);
  37. }
  38. /**
  39. * Test for Date::days_in_month(0)
  40. * @expectedException UnexpectedValueException
  41. * @test
  42. */
  43. public function test_days_in_month_0_exception()
  44. {
  45. $output = Date::days_in_month(0);
  46. }
  47. /**
  48. * Test for Date::days_in_month(13)
  49. * @expectedException UnexpectedValueException
  50. * @test
  51. */
  52. public function test_days_in_month_13_exception()
  53. {
  54. $output = Date::days_in_month(13);
  55. }
  56. /**
  57. * Test for Date::format()
  58. *
  59. * @test
  60. */
  61. public function test_format()
  62. {
  63. date_default_timezone_set('UTC');
  64. $output = Date::forge( 1294176140 )->format("%m/%d/%Y");
  65. $expected = "01/04/2011";
  66. $this->assertEquals($expected, $output);
  67. }
  68. /**
  69. * Test for Date::get_timestamp()
  70. *
  71. * @test
  72. */
  73. public function test_get_timestamp()
  74. {
  75. $output = Date::forge( 1294176140 )->get_timestamp();
  76. $expected = 1294176140;
  77. $this->assertEquals($expected, $output);
  78. }
  79. /**
  80. * Test for Date::get_timezone()
  81. *
  82. * @test
  83. */
  84. public function test_get_timezone()
  85. {
  86. $output = Date::forge( 1294176140, "Europe/London" )->get_timezone();
  87. $expected = "Europe/London";
  88. $this->assertEquals($expected, $output);
  89. }
  90. /**
  91. * Test for Date::set_timezone()
  92. *
  93. * @test
  94. */
  95. public function test_set_timezone()
  96. {
  97. $output = Date::forge( 1294176140 )->set_timezone("America/Chicago")->get_timezone();
  98. $expected = "America/Chicago";
  99. $this->assertEquals($expected, $output);
  100. }
  101. /**
  102. * Test for Date::time_ago()
  103. *
  104. * @test
  105. */
  106. public function test_time_ago_null_timestamp()
  107. {
  108. $output = Date::time_ago(null);
  109. $this->assertEquals(null, $output);
  110. }
  111. /**
  112. * Test for Date::time_ago()
  113. *
  114. * @test
  115. */
  116. public function test_time_ago_one_month()
  117. {
  118. $march_30_2011 = 1301461200;
  119. $april_30_2011 = 1304139600;
  120. $output = Date::time_ago($march_30_2011, $april_30_2011);
  121. $this->assertEquals('1 month ago', $output);
  122. }
  123. /**
  124. * Test for Date::time_ago()
  125. *
  126. * @test
  127. */
  128. public function test_time_ago_two_months()
  129. {
  130. $march_30_2011 = 1301461200;
  131. $may_30_2011 = 1306731600;
  132. $output = Date::time_ago($march_30_2011, $may_30_2011);
  133. $this->assertEquals('2 months ago', $output);
  134. }
  135. }