calendar.lib.test.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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=Database::escape_string($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. public function testGetRepeatedEventsWeekView(){
  210. $course_info = 'COURSETEST';
  211. $resul = get_repeated_events_week_view($course_info, 0, 0, '');
  212. $this->assertTrue(is_array($resul));
  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. public function testDeleteAgendaItem(){
  229. $id=1;
  230. $res = delete_agenda_item($id);
  231. $this->assertTrue(is_bool($res));
  232. }
  233. public function testDisplayMinimonthcalendar(){
  234. ob_start();
  235. global $DaysShort;
  236. $agendaitems=array('test','test2');
  237. $month=01;
  238. $year=2010;
  239. $monthName='';
  240. $res = display_minimonthcalendar($agendaitems, $month, $year, $monthName);
  241. ob_end_clean();
  242. $this->assertTrue(is_null($res));
  243. //var_dump($res);
  244. }
  245. public function testUserGroupFilterJavascript(){
  246. $res = user_group_filter_javascript();
  247. $this->assertTrue($res);
  248. $this->assertTrue(is_string($res));
  249. //var_dump($res);
  250. }
  251. public function testDisplayMonthcalendar(){
  252. ob_start();
  253. global $MonthsLong;
  254. global $DaysShort;
  255. global $origin;
  256. $month=05;
  257. $year=2010;
  258. $res = display_monthcalendar($month, $year);
  259. ob_end_clean();
  260. $this->assertTrue(is_null($res));
  261. $this->assertNull($res);
  262. //var_dump($res);
  263. }
  264. public function testDisplayCourseadminLinks(){
  265. ob_start();
  266. $res = display_courseadmin_links();
  267. ob_end_clean();
  268. $this->assertTrue(is_null($res));
  269. //var_dump($res);
  270. }
  271. public function testDisplayStudentLinks(){
  272. ob_start();
  273. global $show;
  274. $res = display_student_links();
  275. ob_end_clean();
  276. $this->assertTrue(is_null($res));
  277. //var_dump($res);
  278. }
  279. public function testGetAgendaItem(){
  280. $id=4;
  281. $res = get_agenda_item($id);
  282. if(is_array($res)) {
  283. $this->assertTrue(is_array($res));
  284. }
  285. }
  286. /**
  287. * Makes an agenda item visible or invisible for a student
  288. * @param integer id the id of the agenda item we are changing the visibility of
  289. */
  290. public function testShowhideAgendaItem(){
  291. ob_start();
  292. $id=1;
  293. global $nameTools;
  294. $res = showhide_agenda_item($id);
  295. //Show the message when the visibility was changed
  296. $real_show = Display::display_normal_message(get_lang("VisibilityChanged"));
  297. ob_end_clean();
  298. if(!empty($res)){
  299. $this->assertTrue($res);
  300. $this->assertTrue($real_show);
  301. } else {
  302. $this->assertNull($res);
  303. }
  304. //var_dump($res);
  305. }
  306. /**
  307. * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
  308. */
  309. public function testDisplayOneAgendaItem(){
  310. ob_start();
  311. $agenda_id=1;
  312. $res = display_one_agenda_item($agenda_id);
  313. ob_end_clean();
  314. $this->assertTrue(is_null($res));
  315. }
  316. /**
  317. * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
  318. * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
  319. * we have to retrieve the information that is in the database and use this information in the forms.
  320. */
  321. public function testShowGroupFilterForm(){
  322. ob_start();
  323. $res = show_group_filter_form();
  324. ob_end_clean();
  325. $this->assertTrue(is_null($res));
  326. }
  327. public function testShowUserFilterForm(){
  328. ob_start();
  329. $res = show_user_filter_form();
  330. ob_end_clean();
  331. $this->assertTrue(is_null($res));
  332. }
  333. public function testGetAgendaitems(){
  334. global $_user;
  335. global $_configuration;
  336. $month=01;
  337. $year=2010;
  338. $res = get_agendaitems($month, $year);
  339. if(is_array($res)) {
  340. $this->assertTrue(is_array($res));
  341. }
  342. }
  343. public function testDisplayUpcomingEvents(){
  344. ob_start();
  345. $res = display_upcoming_events();
  346. ob_end_clean();
  347. $this->assertNull($res);
  348. }
  349. public function testIsRepeatedEvent() {
  350. //This is deprecated or not used
  351. }
  352. }
  353. ?>