calendar.lib.test.php 9.7 KB

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