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