Fixing #138
[akelos.git] / test / unit / lib / AkActionView / helpers / date_helper.php
blobbc17dea6d65b397d3d5b9ad8b0cdcca3287f374a
1 <?php
3 require_once('_HelpersUnitTester.php');
4 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'date_helper.php');
6 class DateHelperTests extends HelpersUnitTester
7 {
8 function setUp()
10 $this->Person = &new MockAkActiveRecord($this);
11 $this->Person->setReturnValue('get', '1978-06-16 04:37:00', array('date'));
12 $this->date_helper = new DateHelper(array('person'=>&$this->Person));
13 $this->date = '1978-06-16 12:20:30';
16 function test_distance_of_time_in_words()
18 $this->assertEqual(DateHelper::distance_of_time_in_words('1978-06-16','2006-01-18'), '10078 days');
19 $this->assertEqual(DateHelper::distance_of_time_in_words('1779-12-01','1780-01-01'), '31 days');
20 $this->assertEqual(DateHelper::distance_of_time_in_words('1779-12-01','1780-01-01 17:18:53', true), '32 days');
21 $this->assertEqual(DateHelper::distance_of_time_in_words('1780-01-01 17:18:14', '1780-01-01 17:18:53' , true), 'half a minute');
22 $this->assertEqual(DateHelper::distance_of_time_in_words('1780-01-01 17:18:42', '1780-01-01 17:18:53' , true), 'less than 20 seconds');
23 $this->assertEqual(DateHelper::distance_of_time_in_words('1780-01-01 17:18:14', '1780-01-01 17:18:53'), '1 minute');
25 /**
26 * According to the Gregorian calendar, which is the civil calendar in use today,
27 * years evenly divisible by 4 are leap years, with the exception of centurial years
28 * that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100
29 * are not leap years, but 1600, 2000, and 2400 are leap years.
31 $this->assertEqual(DateHelper::distance_of_time_in_words('2100-02-01', '2100-03-01'), '28 days');
32 $this->assertEqual(DateHelper::distance_of_time_in_words('2096-02-01', '2096-03-01'), '29 days');
33 $this->assertEqual(DateHelper::distance_of_time_in_words('2000-02-01', '2000-03-01'), '29 days');
35 $this->assertEqual(DateHelper::distance_of_time_in_words('2100-02-01 01:00:00', '2100-02-01 02:50:00'), 'about 2 hours');
36 $this->assertEqual(DateHelper::distance_of_time_in_words('2100-02-01 01:00:00', '2100-02-01 02:50:00'), 'about 2 hours');
39 function test_time_ago_in_words()
41 $this->assertEqual(DateHelper::time_ago_in_words('2000-02-01 01:00:00'), DateHelper::distance_of_time_in_words('2000-02-01 01:00:00', Ak::time()));
44 function test_distance_of_time_in_words_to_now()
46 $this->assertEqual(DateHelper::distance_of_time_in_words_to_now('2000-02-01 01:00:00'), DateHelper::distance_of_time_in_words('2000-02-01 01:00:00', Ak::time()));
49 function test_date_select()
51 $this->assertEqual($this->date_helper->date_select('person', 'date'), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_date_select_1.txt'));
52 $this->assertEqual($this->date_helper->date_select('person','date',array('include_blank'=>true,'discard_day'=>true,'order'=>array('month','year'))), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_date_select_2.txt'));
55 function test_datetime_select()
57 $this->assertEqual($this->date_helper->datetime_select('person', 'date'), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_date_select_3.txt'));
60 function test_select_date()
62 $this->assertEqual(DateHelper::select_date($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_date.txt'));
65 function test_select_datetime()
67 $this->assertEqual(DateHelper::select_datetime($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_datetime.txt'));
68 $this->assertEqual(DateHelper::select_datetime($this->date, array('include_seconds' => true)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_datetime_seconds.txt'));
71 function test_select_time()
73 $this->assertEqual(DateHelper::select_time($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_time.txt'));
74 $this->assertEqual(DateHelper::select_time($this->date, array('include_seconds' => true)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_time_seconds.txt'));
77 function test_select_second()
79 $this->assertEqual(DateHelper::select_second($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_second.txt'));
82 function test_select_minute()
84 $this->assertEqual(DateHelper::select_minute($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_minute.txt'));
87 function test_select_hour()
89 $this->assertEqual(DateHelper::select_hour($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_hour.txt'));
92 function test_select_day()
94 $this->assertEqual(DateHelper::select_day($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_day.txt'));
97 function test_select_month()
99 $this->assertEqual(DateHelper::select_month($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_month.txt'));
100 $this->assertEqual(DateHelper::select_month($this->date, array('use_month_numbers' => true)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_month_numbers.txt'));
101 $this->assertEqual(DateHelper::select_month($this->date, array('add_month_numbers' => true)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_month_add_numbers.txt'));
102 $this->assertEqual(DateHelper::select_month($this->date, array('add_month_numbers' => true, 'use_short_month' => true)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_month_add_numbers_short_month.txt'));
103 $this->assertEqual(DateHelper::select_month($this->date, array('use_short_month' => true)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_month_short_month.txt'));
106 function test_select_year()
108 $this->assertEqual(DateHelper::select_year($this->date), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_year.txt'));
109 $this->assertEqual(DateHelper::select_year($this->date, array('start_year' => 1950, 'end_year' => 2010)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_year_options.txt'));
110 $this->assertEqual(DateHelper::select_year($this->date, array('start_year' => 2010, 'end_year' => 1950)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_year_options_reverse.txt'));
111 $this->assertEqual(DateHelper::select_year($this->date, array('start_year' => 1980, 'end_year' => 1990)), file_get_contents(AK_TEST_HELPERS_DIR.DS.'date_helper_select_year_options_out_of_range.txt'));
114 function test_locale_date_time()
116 $this->assertEqual(DateHelper::locale_date_time($this->date), '1978-06-16 12:20:30');
117 $this->assertEqual(DateHelper::locale_date($this->date), '1978-06-16');
121 ak_test('DateHelperTests');