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