blob: 952e8a8d2ce2814af2103bbc4f4f2326b8536e88 [file] [log] [blame]
Alex Bilbie5e971082012-09-03 18:57:35 +01001<?php
2
3class Calendar_test extends CI_TestCase {
4
dchill421713d322012-11-24 20:23:21 -05005 function set_up()
Alex Bilbie5e971082012-09-03 18:57:35 +01006 {
dchill421713d322012-11-24 20:23:21 -05007 $lang = $this->getMock('CI_Lang', array('load', 'line'));
8 $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE));
9 $this->ci_instance_var('lang', $lang);
10 $this->calendar = new CI_Calendar();
Alex Bilbie5e971082012-09-03 18:57:35 +010011 }
12
13 function test_initialize()
14 {
15 $this->calendar->initialize(array(
16 'month_type' => 'short',
17 'start_day' => 'monday'
18 ));
19 $this->assertEquals('short', $this->calendar->month_type);
20 $this->assertEquals('monday', $this->calendar->start_day);
21 }
22
Alex Bilbie5e971082012-09-03 18:57:35 +010023 function test_generate()
24 {
25 $no_events = '<table border="0" cellpadding="4" cellspacing="0">
26
27<tr>
28<th colspan="7">September&nbsp;2011</th>
29
30</tr>
31
32<tr>
33<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
34</tr>
35
36<tr>
37<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td>3</td>
38</tr>
39
40<tr>
41<td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
42</tr>
43
44<tr>
45<td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td>
46</tr>
47
48<tr>
49<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
50</tr>
51
52<tr>
53<td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
54</tr>
55
56</table>';
57
58 $this->assertEquals($no_events, $this->calendar->generate(2011, 9));
59
60 $data = array(
61 3 => 'http://example.com/news/article/2006/03/',
62 7 => 'http://example.com/news/article/2006/07/',
63 13 => 'http://example.com/news/article/2006/13/',
64 26 => 'http://example.com/news/article/2006/26/'
65 );
66
67 $events = '<table border="0" cellpadding="4" cellspacing="0">
68
69<tr>
70<th colspan="7">September&nbsp;2011</th>
71
72</tr>
73
74<tr>
75<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
76</tr>
77
78<tr>
79<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td><a href="http://example.com/news/article/2006/03/">3</a></td>
80</tr>
81
82<tr>
83<td>4</td><td>5</td><td>6</td><td><a href="http://example.com/news/article/2006/07/">7</a></td><td>8</td><td>9</td><td>10</td>
84</tr>
85
86<tr>
87<td>11</td><td>12</td><td><a href="http://example.com/news/article/2006/13/">13</a></td><td>14</td><td>15</td><td>16</td><td>17</td>
88</tr>
89
90<tr>
91<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
92</tr>
93
94<tr>
95<td>25</td><td><a href="http://example.com/news/article/2006/26/">26</a></td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
96</tr>
97
98</table>';
99
100 $this->assertEquals($events, $this->calendar->generate(2011, 9, $data));
101 }
102
103 function test_get_month_name()
104 {
105 $this->calendar->month_type = NULL;
106 $this->assertEquals('January', $this->calendar->get_month_name('01'));
107
108 $this->calendar->month_type = 'short';
109 $this->assertEquals('Jan', $this->calendar->get_month_name('01'));
110 }
111
112 function test_get_day_names()
113 {
114 $this->assertEquals(array(
115 'Sunday',
116 'Monday',
117 'Tuesday',
118 'Wednesday',
119 'Thursday',
120 'Friday',
121 'Saturday'
122 ), $this->calendar->get_day_names('long'));
123
124 $this->assertEquals(array(
125 'Sun',
126 'Mon',
127 'Tue',
128 'Wed',
129 'Thu',
130 'Fri',
131 'Sat'
132 ), $this->calendar->get_day_names('short'));
133
134 $this->calendar->day_type = NULL;
135
136 $this->assertEquals(array(
137 'Su',
138 'Mo',
139 'Tu',
140 'We',
141 'Th',
142 'Fr',
143 'Sa'
144 ), $this->calendar->get_day_names());
145 }
146
147 function test_adjust_date()
148 {
149 $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012));
150 $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012));
151 }
152
153 function test_get_total_days()
154 {
155 $this->assertEquals(0, $this->calendar->get_total_days(13, 2012));
156
157 $this->assertEquals(31, $this->calendar->get_total_days(1, 2012));
158 $this->assertEquals(28, $this->calendar->get_total_days(2, 2011));
159 $this->assertEquals(29, $this->calendar->get_total_days(2, 2012));
160 $this->assertEquals(31, $this->calendar->get_total_days(3, 2012));
161 $this->assertEquals(30, $this->calendar->get_total_days(4, 2012));
162 $this->assertEquals(31, $this->calendar->get_total_days(5, 2012));
163 $this->assertEquals(30, $this->calendar->get_total_days(6, 2012));
164 $this->assertEquals(31, $this->calendar->get_total_days(7, 2012));
165 $this->assertEquals(31, $this->calendar->get_total_days(8, 2012));
166 $this->assertEquals(30, $this->calendar->get_total_days(9, 2012));
167 $this->assertEquals(31, $this->calendar->get_total_days(10, 2012));
168 $this->assertEquals(30, $this->calendar->get_total_days(11, 2012));
169 $this->assertEquals(31, $this->calendar->get_total_days(12, 2012));
170 }
171
172 function test_default_template()
173 {
174 $array = array(
175 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
176 'heading_row_start' => '<tr>',
177 'heading_previous_cell' => '<th><a href="{previous_url}">&lt;&lt;</a></th>',
178 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
179 'heading_next_cell' => '<th><a href="{next_url}">&gt;&gt;</a></th>',
180 'heading_row_end' => '</tr>',
181 'week_row_start' => '<tr>',
182 'week_day_cell' => '<td>{week_day}</td>',
183 'week_row_end' => '</tr>',
184 'cal_row_start' => '<tr>',
185 'cal_cell_start' => '<td>',
186 'cal_cell_start_today' => '<td>',
187 'cal_cell_content' => '<a href="{content}">{day}</a>',
188 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
189 'cal_cell_no_content' => '{day}',
190 'cal_cell_no_content_today' => '<strong>{day}</strong>',
191 'cal_cell_blank' => '&nbsp;',
192 'cal_cell_end' => '</td>',
193 'cal_cell_end_today' => '</td>',
194 'cal_row_end' => '</tr>',
195 'table_close' => '</table>'
196 );
197
198 $this->assertEquals($array, $this->calendar->default_template());
199 }
200
201}