Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | class Calendar_test extends CI_TestCase { |
| 4 | |
Andrey Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 5 | public function set_up() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 6 | { |
Andrey Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 7 | // Required for get_total_days() |
Andrey Andreev | 878e23f | 2016-08-10 15:15:49 +0300 | [diff] [blame] | 8 | $this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock()); |
Andrey Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 9 | |
Andrey Andreev | 878e23f | 2016-08-10 15:15:49 +0300 | [diff] [blame] | 10 | $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock(); |
dchill42 | 1713d32 | 2012-11-24 20:23:21 -0500 | [diff] [blame] | 11 | $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); |
| 12 | $this->ci_instance_var('lang', $lang); |
Andrey Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 13 | |
dchill42 | 1713d32 | 2012-11-24 20:23:21 -0500 | [diff] [blame] | 14 | $this->calendar = new CI_Calendar(); |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 15 | } |
| 16 | |
Andrey Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 17 | // -------------------------------------------------------------------- |
| 18 | |
| 19 | public function test_initialize() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 20 | { |
| 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 Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 29 | // -------------------------------------------------------------------- |
| 30 | |
| 31 | public function test_generate() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 32 | { |
| 33 | $no_events = '<table border="0" cellpadding="4" cellspacing="0"> |
| 34 | |
| 35 | <tr> |
| 36 | <th colspan="7">September 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> </td><td> </td><td> </td><td> </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> </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 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> </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> |
| 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> </td> |
| 104 | </tr> |
| 105 | |
| 106 | </table>'; |
| 107 | |
| 108 | $this->assertEquals($events, $this->calendar->generate(2011, 9, $data)); |
| 109 | } |
| 110 | |
Andrey Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 111 | // -------------------------------------------------------------------- |
| 112 | |
| 113 | public function test_get_month_name() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 114 | { |
| 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 Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 122 | // -------------------------------------------------------------------- |
| 123 | |
| 124 | public function test_get_day_names() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 125 | { |
| 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 Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 159 | // -------------------------------------------------------------------- |
| 160 | |
| 161 | public function test_adjust_date() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 162 | { |
| 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 Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 167 | // -------------------------------------------------------------------- |
| 168 | |
| 169 | public function test_get_total_days() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 170 | { |
| 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 Andreev | f30b14a | 2014-02-20 16:18:37 +0200 | [diff] [blame] | 188 | // -------------------------------------------------------------------- |
| 189 | |
Andrey Andreev | d1755f8 | 2014-01-09 13:54:47 +0200 | [diff] [blame] | 190 | public function test_default_template() |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 191 | { |
| 192 | $array = array( |
Andrey Andreev | d1755f8 | 2014-01-09 13:54:47 +0200 | [diff] [blame] | 193 | 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', |
| 194 | 'heading_row_start' => '<tr>', |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 195 | 'heading_previous_cell' => '<th><a href="{previous_url}"><<</a></th>', |
| 196 | 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>', |
Andrey Andreev | d1755f8 | 2014-01-09 13:54:47 +0200 | [diff] [blame] | 197 | 'heading_next_cell' => '<th><a href="{next_url}">>></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 Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 204 | 'cal_cell_start_today' => '<td>', |
Andrey Andreev | d1755f8 | 2014-01-09 13:54:47 +0200 | [diff] [blame] | 205 | 'cal_cell_content' => '<a href="{content}">{day}</a>', |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 206 | '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 Andreev | d1755f8 | 2014-01-09 13:54:47 +0200 | [diff] [blame] | 209 | 'cal_cell_blank' => ' ', |
| 210 | 'cal_cell_end' => '</td>', |
Alex Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 211 | 'cal_cell_end_today' => '</td>', |
Andrey Andreev | d1755f8 | 2014-01-09 13:54:47 +0200 | [diff] [blame] | 212 | '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 Bilbie | 5e97108 | 2012-09-03 18:57:35 +0100 | [diff] [blame] | 217 | ); |
| 218 | |
| 219 | $this->assertEquals($array, $this->calendar->default_template()); |
| 220 | } |
| 221 | |
Andrey Andreev | 878e23f | 2016-08-10 15:15:49 +0300 | [diff] [blame] | 222 | } |