calendar.lib.test.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  3. require_once(api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php');
  4. class TestCalendar extends UnitTestCase {
  5. public function TestCalendar(){
  6. $this->UnitTestCase('Admin calendar library - main/admin/calendar.inc.test.php');
  7. }
  8. public function testToJavascript(){
  9. $res = to_javascript();
  10. $this->assertTrue($res);
  11. $this->assertTrue(is_string($res));
  12. //var_dump($res);
  13. }
  14. /**
  15. * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
  16. * @param array Course info
  17. * @param string Event title
  18. * @param string Event content/description
  19. * @param string Start date
  20. * @param string End date
  21. * @param array List of groups to which this event is added
  22. * @param int Parent id (optional)
  23. * @return int The new item's DB ID
  24. */
  25. public function testAgendaAddItem(){
  26. global $_course;
  27. $course_code=$_course;
  28. $course_info = '';
  29. $title='test';
  30. $content='test function';
  31. $db_start_date='07/11/2009';
  32. $db_end_date='07/20/2009';
  33. $res = agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to=array(), $parent_id=null);
  34. $this->assertTrue($res>0,'Global agenda item could not be inserted');
  35. delete_agenda_item($res);
  36. //var_dump($res);
  37. }
  38. public function testStoreNewAgendaItem(){
  39. global $_user;
  40. $res_store = store_new_agenda_item();
  41. $this->assertTrue(is_numeric($res_store));
  42. //delete the new agenda item in the database
  43. if (is_numeric($res_store)) {
  44. $res_delete = delete_agenda_item($res_store);
  45. $this->assertTrue(is_numeric($res_store));
  46. }
  47. }
  48. public function testShowAddForm(){
  49. ob_start();
  50. global $MonthsLong;
  51. $id='';
  52. $res= show_add_form($id);
  53. ob_end_clean();
  54. $this->assertTrue(is_null($res));
  55. //var_dump($res);
  56. }
  57. public function testAddWeek(){
  58. $timestamp=12;
  59. $num=1;
  60. $res = add_week($timestamp,$num);
  61. $this->assertTrue(is_numeric($res));
  62. //var_dump($res);
  63. }
  64. public function testAddMonth(){
  65. $timestamp=5;
  66. $num=1;
  67. $res = add_month($timestamp,$num);
  68. $this->assertTrue(is_numeric($res));
  69. //var_dump($res);
  70. }
  71. public function testAddYear(){
  72. $timestamp=9999;
  73. $num=1;
  74. $res = add_year($timestamp,$num);
  75. $this->assertTrue(is_numeric($res));
  76. //var_dump($res);
  77. }
  78. /**
  79. * Adds a repetitive item to the database
  80. * @param array Course info
  81. * @param int The original event's id
  82. * @param string Type of repetition
  83. * @param int Timestamp of end of repetition (repeating until that date)
  84. * @param array Original event's destination
  85. * @return boolean False if error, True otherwise
  86. */
  87. public function testAgendaAddRepeatItem(){
  88. //this function is not used or deprecated
  89. }
  90. public function testGetCalendarItems(){
  91. global $_course;
  92. $month=01;
  93. $year=2010;
  94. $res = get_calendar_items($month, $year);
  95. $this->assertTrue(is_array($res));
  96. //var_dump($res);
  97. }
  98. //This funtion need a path where will copy to the other folder.
  99. /*
  100. public function testAgendaImportIcal() {
  101. global $_course;
  102. $course_info = $_course;
  103. $file = api_get_path(SYS_PATH).'tests/main/admin/icals/test.ics';
  104. $res = agenda_import_ical($course_info, $file);
  105. if(is_bool($res)){
  106. $this->assertTrue(is_bool($res));
  107. $this->assertTrue($res===false || $res === true);
  108. }else{
  109. $this->assertTrue($res);
  110. }
  111. }
  112. */
  113. public function testStoreEditedAgendaItem(){
  114. ob_start();
  115. $id=1;
  116. $title='';
  117. $content='';
  118. $start_date= 21;
  119. $end_date=25;
  120. $res = store_edited_agenda_item();
  121. $edit_result=save_edit_agenda_item($id,$title,$content,$start_date,$end_date);
  122. ob_end_clean();
  123. $this->assertTrue($edit_result);
  124. //var_dump($edit_result);
  125. }
  126. public function testSaveEditAgendaItem(){
  127. $id=Database::escape_string($id);
  128. $title=Database::escape_string($title);
  129. $content=Database::escape_string($content);
  130. $start_date=Database::escape_string($start_date);
  131. $end_date=Database::escape_string($end_date);
  132. $res = save_edit_agenda_item($id,$title,$content,$start_date,$end_date);
  133. $this->assertTrue($res);
  134. $this->assertTrue(is_bool($res));
  135. //var_dump($res);
  136. }
  137. public function testCalculateStartEndOfWeek(){
  138. $week_number=4;
  139. $year=2011;
  140. $res = calculate_start_end_of_week($week_number, $year);
  141. $this->assertTrue(is_array($res));
  142. $this->assertTrue($res);
  143. //var_dump($res);
  144. }
  145. /**
  146. * Displays all the agenda items
  147. */
  148. public function testDisplayAgendaItems() {
  149. global $is_courseAdmin;
  150. ob_start();
  151. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  152. $res = display_agenda_items();
  153. ob_end_clean();
  154. $this->assertTrue(is_null($res));
  155. }
  156. public function testDisplayDaycalendar(){
  157. ob_start();
  158. $agendaitems='';
  159. $day='';
  160. $month='';
  161. $year='';
  162. $weekdaynames='';
  163. $monthName='';
  164. $res = display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName);
  165. ob_end_clean();
  166. $this->assertTrue(is_null($res));
  167. //var_dump($res);
  168. }
  169. public function testDisplayWeekcalendar() {
  170. ob_start();
  171. $agendaitems='';
  172. $month=10;
  173. $year=2011;
  174. $weekdaynames='';
  175. $monthName='';
  176. $res = display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName);
  177. ob_end_clean();
  178. $this->assertTrue(is_null($res));
  179. //var_dump($res);
  180. }
  181. public function testGetDayAgendaitems() {
  182. $courses_dbs=array();
  183. $month=01;
  184. $year=2010;
  185. $day='1';
  186. $res = get_day_agendaitems($courses_dbs, $month, $year, $day);
  187. $this->assertTrue(is_array($res));
  188. //var_dump($res);
  189. }
  190. public function testGetWeekAgendaitems() {
  191. $courses_dbs=array();
  192. $month=01;
  193. $year=2010;
  194. $res = get_week_agendaitems($courses_dbs, $month, $year);
  195. $this->assertTrue(is_array($res));
  196. }
  197. /* public function testGetRepeatedEventsDayView(){
  198. global $_course;
  199. $start = 0;
  200. $end = 0;
  201. $params = array();
  202. $course_code = 'COURSETEST';
  203. $course_info = api_get_course_info($course_code);
  204. $resul = get_repeated_events_day_view($course_info,$start,$end,$params);
  205. $this->assertTrue(is_array($resul));
  206. }
  207. */
  208. public function testGetRepeatedEventsWeekView(){
  209. $course_info = 'COURSETEST';
  210. $resul = get_repeated_events_week_view($course_info, 0, 0, '');
  211. $this->assertTrue(is_array($resul));
  212. }
  213. /*
  214. public function testGetRepeatedEventsMonthView(){
  215. $course_code='COURSETEST';
  216. $course_info = api_get_course_info($course_code);
  217. $resul= get_repeated_events_month_view($course_info,0,0,'');
  218. $this->assertTrue(is_array($resul));
  219. //var_dump($resul);
  220. }
  221. public function testGetRepeatedEventsListView(){
  222. $course_code='COURSETEST';
  223. $course_info = api_get_course_info($course_code);
  224. $resul = get_repeated_events_list_view($course_info,0,0,'');
  225. $this->assertTrue(is_array($resul));
  226. //var_dump($resul);
  227. }
  228. */
  229. public function testDeleteAgendaItem(){
  230. $id=1;
  231. $res = delete_agenda_item($id);
  232. $this->assertTrue(is_bool($res));
  233. }
  234. public function testDisplayMinimonthcalendar(){
  235. ob_start();
  236. global $DaysShort;
  237. $agendaitems=array('test','test2');
  238. $month=01;
  239. $year=2010;
  240. $monthName='';
  241. $res = display_minimonthcalendar($agendaitems, $month, $year, $monthName);
  242. ob_end_clean();
  243. $this->assertTrue(is_null($res));
  244. //var_dump($res);
  245. }
  246. public function testUserGroupFilterJavascript(){
  247. $res = user_group_filter_javascript();
  248. $this->assertTrue($res);
  249. $this->assertTrue(is_string($res));
  250. //var_dump($res);
  251. }
  252. public function testDisplayMonthcalendar(){
  253. ob_start();
  254. global $MonthsLong;
  255. global $DaysShort;
  256. global $origin;
  257. $month=05;
  258. $year=2010;
  259. $res = display_monthcalendar($month, $year);
  260. ob_end_clean();
  261. $this->assertTrue(is_null($res));
  262. $this->assertNull($res);
  263. //var_dump($res);
  264. }
  265. public function testGetAgendaItem(){
  266. $id=4;
  267. $res = get_agenda_item($id);
  268. if(is_array($res)) {
  269. $this->assertTrue(is_array($res));
  270. }
  271. }
  272. /**
  273. * Makes an agenda item visible or invisible for a student
  274. * @param integer id the id of the agenda item we are changing the visibility of
  275. */
  276. public function testShowhideAgendaItem(){
  277. ob_start();
  278. $id=1;
  279. global $nameTools;
  280. $res = showhide_agenda_item($id);
  281. //Show the message when the visibility was changed
  282. $real_show = Display::display_normal_message(get_lang("VisibilityChanged"));
  283. ob_end_clean();
  284. if(!empty($res)){
  285. $this->assertTrue($res);
  286. $this->assertTrue($real_show);
  287. } else {
  288. $this->assertNull($res);
  289. }
  290. //var_dump($res);
  291. }
  292. /**
  293. * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
  294. */
  295. public function testDisplayOneAgendaItem(){
  296. ob_start();
  297. $agenda_id=1;
  298. $res = display_one_agenda_item($agenda_id);
  299. ob_end_clean();
  300. $this->assertTrue(is_null($res));
  301. }
  302. /**
  303. * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
  304. * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
  305. * we have to retrieve the information that is in the database and use this information in the forms.
  306. */
  307. public function testShowGroupFilterForm(){
  308. ob_start();
  309. $res = show_group_filter_form();
  310. ob_end_clean();
  311. $this->assertTrue(is_null($res));
  312. }
  313. public function testShowUserFilterForm(){
  314. ob_start();
  315. $res = show_user_filter_form();
  316. ob_end_clean();
  317. $this->assertTrue(is_null($res));
  318. }
  319. public function testGetAgendaitems(){
  320. global $_user;
  321. global $_configuration;
  322. $month=01;
  323. $year=2010;
  324. $res = get_agendaitems($month, $year);
  325. if(is_array($res)) {
  326. $this->assertTrue(is_array($res));
  327. }
  328. }
  329. public function testDisplayUpcomingEvents(){
  330. ob_start();
  331. $res = display_upcoming_events();
  332. ob_end_clean();
  333. $this->assertNull($res);
  334. }
  335. public function testIsRepeatedEvent() {
  336. //This is deprecated or not used
  337. }
  338. }
  339. ?>