blob: ad1f45e8c774ecf546d50b93cc22e20b2f917387 [file] [log] [blame]
Alex Bilbie5e971082012-09-03 18:57:35 +01001<?php
2
3class Calendar_test extends CI_TestCase {
4
Andrey Andreevf30b14a2014-02-20 16:18:37 +02005 public function set_up()
Alex Bilbie5e971082012-09-03 18:57:35 +01006 {
Andrey Andreevf30b14a2014-02-20 16:18:37 +02007 // Required for get_total_days()
Andrey Andreev878e23f2016-08-10 15:15:49 +03008 $this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock());
Andrey Andreevf30b14a2014-02-20 16:18:37 +02009
Andrey Andreev878e23f2016-08-10 15:15:49 +030010 $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock();
dchill421713d322012-11-24 20:23:21 -050011 $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE));
12 $this->ci_instance_var('lang', $lang);
Andrey Andreevf30b14a2014-02-20 16:18:37 +020013
dchill421713d322012-11-24 20:23:21 -050014 $this->calendar = new CI_Calendar();
Alex Bilbie5e971082012-09-03 18:57:35 +010015 }
16
Andrey Andreevf30b14a2014-02-20 16:18:37 +020017 // --------------------------------------------------------------------
18
19 public function test_initialize()
Alex Bilbie5e971082012-09-03 18:57:35 +010020 {
21 $this->calendar->initialize(array(
22 'month_type' => 'short',
23 'start_day' => 'monday'
24 ));
25 $this->assertEquals('short', $this->calendar->month_type);
26 $this->assertEquals('monday', $this->calendar->start_day);
27 }
28
Andrey Andreevf30b14a2014-02-20 16:18:37 +020029 // --------------------------------------------------------------------
30
31 public function test_generate()
Alex Bilbie5e971082012-09-03 18:57:35 +010032 {
33 $no_events = '<table border="0" cellpadding="4" cellspacing="0">
34
35<tr>
36<th colspan="7">September&nbsp;2011</th>
37
38</tr>
39
40<tr>
41<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
42</tr>
43
44<tr>
45<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1</td><td>2</td><td>3</td>
46</tr>
47
48<tr>
49<td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td>
50</tr>
51
52<tr>
53<td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td>
54</tr>
55
56<tr>
57<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
58</tr>
59
60<tr>
61<td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td>&nbsp;</td>
62</tr>
63
64</table>';
65
66 $this->assertEquals($no_events, $this->calendar->generate(2011, 9));
67
68 $data = array(
69 3 => 'http://example.com/news/article/2006/03/',
70 7 => 'http://example.com/news/article/2006/07/',
71 13 => 'http://example.com/news/article/2006/13/',
72 26 => 'http://example.com/news/article/2006/26/'
73 );
74
75 $events = '<table border="0" cellpadding="4" cellspacing="0">
76
77<tr>
78<th colspan="7">September&nbsp;2011</th>
79
80</tr>
81
82<tr>
83<td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td>
84</tr>
85
86<tr>
87<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>
88</tr>
89
90<tr>
91<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>
92</tr>
93
94<tr>
95<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>
96</tr>
97
98<tr>
99<td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td>
100</tr>
101
102<tr>
103<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>
104</tr>
105
106</table>';
107
108 $this->assertEquals($events, $this->calendar->generate(2011, 9, $data));
109 }
110
Andrey Andreevf30b14a2014-02-20 16:18:37 +0200111 // --------------------------------------------------------------------
112
113 public function test_get_month_name()
Alex Bilbie5e971082012-09-03 18:57:35 +0100114 {
115 $this->calendar->month_type = NULL;
116 $this->assertEquals('January', $this->calendar->get_month_name('01'));
117
118 $this->calendar->month_type = 'short';
119 $this->assertEquals('Jan', $this->calendar->get_month_name('01'));
120 }
121
Andrey Andreevf30b14a2014-02-20 16:18:37 +0200122 // --------------------------------------------------------------------
123
124 public function test_get_day_names()
Alex Bilbie5e971082012-09-03 18:57:35 +0100125 {
126 $this->assertEquals(array(
127 'Sunday',
128 'Monday',
129 'Tuesday',
130 'Wednesday',
131 'Thursday',
132 'Friday',
133 'Saturday'
134 ), $this->calendar->get_day_names('long'));
135
136 $this->assertEquals(array(
137 'Sun',
138 'Mon',
139 'Tue',
140 'Wed',
141 'Thu',
142 'Fri',
143 'Sat'
144 ), $this->calendar->get_day_names('short'));
145
146 $this->calendar->day_type = NULL;
147
148 $this->assertEquals(array(
149 'Su',
150 'Mo',
151 'Tu',
152 'We',
153 'Th',
154 'Fr',
155 'Sa'
156 ), $this->calendar->get_day_names());
157 }
158
Andrey Andreevf30b14a2014-02-20 16:18:37 +0200159 // --------------------------------------------------------------------
160
161 public function test_adjust_date()
Alex Bilbie5e971082012-09-03 18:57:35 +0100162 {
163 $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012));
164 $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012));
165 }
166
Andrey Andreevf30b14a2014-02-20 16:18:37 +0200167 // --------------------------------------------------------------------
168
169 public function test_get_total_days()
Alex Bilbie5e971082012-09-03 18:57:35 +0100170 {
171 $this->assertEquals(0, $this->calendar->get_total_days(13, 2012));
172
173 $this->assertEquals(31, $this->calendar->get_total_days(1, 2012));
174 $this->assertEquals(28, $this->calendar->get_total_days(2, 2011));
175 $this->assertEquals(29, $this->calendar->get_total_days(2, 2012));
176 $this->assertEquals(31, $this->calendar->get_total_days(3, 2012));
177 $this->assertEquals(30, $this->calendar->get_total_days(4, 2012));
178 $this->assertEquals(31, $this->calendar->get_total_days(5, 2012));
179 $this->assertEquals(30, $this->calendar->get_total_days(6, 2012));
180 $this->assertEquals(31, $this->calendar->get_total_days(7, 2012));
181 $this->assertEquals(31, $this->calendar->get_total_days(8, 2012));
182 $this->assertEquals(30, $this->calendar->get_total_days(9, 2012));
183 $this->assertEquals(31, $this->calendar->get_total_days(10, 2012));
184 $this->assertEquals(30, $this->calendar->get_total_days(11, 2012));
185 $this->assertEquals(31, $this->calendar->get_total_days(12, 2012));
186 }
187
Andrey Andreevf30b14a2014-02-20 16:18:37 +0200188 // --------------------------------------------------------------------
189
Andrey Andreevd1755f82014-01-09 13:54:47 +0200190 public function test_default_template()
Alex Bilbie5e971082012-09-03 18:57:35 +0100191 {
192 $array = array(
Andrey Andreevd1755f82014-01-09 13:54:47 +0200193 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
194 'heading_row_start' => '<tr>',
Alex Bilbie5e971082012-09-03 18:57:35 +0100195 'heading_previous_cell' => '<th><a href="{previous_url}">&lt;&lt;</a></th>',
196 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
Andrey Andreevd1755f82014-01-09 13:54:47 +0200197 'heading_next_cell' => '<th><a href="{next_url}">&gt;&gt;</a></th>',
198 'heading_row_end' => '</tr>',
199 'week_row_start' => '<tr>',
200 'week_day_cell' => '<td>{week_day}</td>',
201 'week_row_end' => '</tr>',
202 'cal_row_start' => '<tr>',
203 'cal_cell_start' => '<td>',
Alex Bilbie5e971082012-09-03 18:57:35 +0100204 'cal_cell_start_today' => '<td>',
Andrey Andreevd1755f82014-01-09 13:54:47 +0200205 'cal_cell_content' => '<a href="{content}">{day}</a>',
Alex Bilbie5e971082012-09-03 18:57:35 +0100206 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
207 'cal_cell_no_content' => '{day}',
208 'cal_cell_no_content_today' => '<strong>{day}</strong>',
Andrey Andreevd1755f82014-01-09 13:54:47 +0200209 'cal_cell_blank' => '&nbsp;',
210 'cal_cell_end' => '</td>',
Alex Bilbie5e971082012-09-03 18:57:35 +0100211 'cal_cell_end_today' => '</td>',
Andrey Andreevd1755f82014-01-09 13:54:47 +0200212 'cal_row_end' => '</tr>',
213 'table_close' => '</table>',
214 'cal_cell_start_other' => '<td style="color: #666;">',
215 'cal_cell_other' => '{day}',
216 'cal_cell_end_other' => '</td>'
Alex Bilbie5e971082012-09-03 18:57:35 +0100217 );
218
219 $this->assertEquals($array, $this->calendar->default_template());
220 }
221
Andrey Andreev878e23f2016-08-10 15:15:49 +0300222}