blog.lib.test.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'blog.lib.php');
  3. ob_start();
  4. //require_once(api_get_path(SYS_CODE_PATH).'permissions/blog_permissions.inc.php');
  5. ob_end_clean();
  6. class TestBlog extends UnitTestCase
  7. {
  8. public $oblog;
  9. public function TestBlog()
  10. {
  11. $this->UnitTestCase('Blog Manipulation tests');
  12. }
  13. public function setUp()
  14. {
  15. $this-> oblog = new Blog();
  16. }
  17. public function tearDown()
  18. {
  19. $this->oblog = null;
  20. }
  21. /*
  22. * todo public function testGetBlobTitle()
  23. * todo public function testGetBlogSubtitle()
  24. * todo public function testGetBlogUsers()
  25. * todo public function testCreateBlog()
  26. * todo public function testEditBlog()
  27. * todo public function testDeleteBlog()
  28. * todo public function testCreatePost()
  29. * todo public function testEditPost()
  30. * todo public function testDeletePost()
  31. * todo public function testCreateComment()
  32. * todo public function testDeleteComment()
  33. * todo public function testCreateTask()
  34. * todo public function testEditTask()
  35. * todo public function testDeleteTask()
  36. * todo public function testDeleteAssignedTask()
  37. * todo public function testGetPersonalTaskList()
  38. * todo public function testChangeBlogVisibility()
  39. * todo public function testDisplayBlogPosts()
  40. * todo public function testDisplaySearchResults()
  41. * todo public function testDisplayDayResults()
  42. * todo public function testDisplayPost()
  43. * todo public function testAddRating()
  44. * todo public function testDisplayRating()
  45. * todo public function testDisplayRatingForm()
  46. * todo public function testGetThreadedComments()
  47. * todo public function testDisplayformNewPost()
  48. * todo public function testDisplayFormEditPost()
  49. * todo public function testDisplayTaskList()
  50. * todo public function testDisplayAssignedTaskList()
  51. * todo public function testDisplayNewTaskForm()
  52. * todo public function testDisplayEditTaskForm()
  53. * todo public function testDisplayAssignTaskForm()
  54. * todo public function testDisplayEditAssignedTaskForm()
  55. * todo public function testAssignTask()
  56. * todo public function testEditAssignedTask()
  57. * todo public function testDisplaySelectTaskPost()
  58. * todo public function testSetUserSubscribed()
  59. * todo public function testSetUserUnsubscribed()
  60. * todo public function testDisplayFormUserSubscribe()
  61. * todo public function testDisplayFormUserUnsubscribe()
  62. * todo public function testDisplayNewCommentForm()
  63. * todo public function testDisplayMinimonthcalendar()
  64. * todo public function testDisplayNewBlogForm()
  65. * todo public function testDisplayEditBlogForm()
  66. * todo public function testDisplayBlogList()
  67. * todo public function testDisplayBlogList()
  68. */
  69. /**
  70. * Test about get Title to a Blog
  71. */
  72. public function testGetBlogTitle(){
  73. global $_course;
  74. $res = $this->oblog->get_Blog_title(11);
  75. $this->assertFalse($this->oblog->get_Blog_title(11)===String);
  76. $this->assertTrue(is_String($res));
  77. }
  78. public function testGetBlogSubtitle(){
  79. $res = $this->oblog->get_Blog_subtitle(0);
  80. $this->assertFalse($this->oblog->get_Blog_subtitle(0)=== null);
  81. $this->assertTrue(is_String($res));
  82. $this->assertNotNull($res);
  83. }
  84. public function testGetBlogUsers(){
  85. $res = $this->oblog->get_Blog_users(11);
  86. $this->assertTrue($this->oblog->get_Blog_users(1110)===array());
  87. $this->assertTrue(is_array($res));
  88. }
  89. public function testCreateBlog(){
  90. global $_user;
  91. $res = $this->oblog->create_Blog('testingBlog','pass');
  92. $this->assertTrue(is_null($res));
  93. $this->assertNull($res);
  94. $this->assertFalse($res);
  95. }
  96. public function testEditBlog(){
  97. global $_user;
  98. $blog_id = 1;
  99. $title = 'titulo1';
  100. $subtitle = 'subtitulo1';
  101. $res = $this->oblog->edit_Blog($blog_id, $title, $subtitle);
  102. $this->assertNull($res);
  103. $this->assertTrue($this->oblog->edit_Blog($blog_id, $title, $subtitle)=== $res);
  104. $this->assertFalse($res);
  105. }
  106. public function testDeleteBlog(){
  107. $blog_id = 1;
  108. $res = $this->oblog->delete_Blog($blog_id);
  109. $this->assertTrue(is_null($res));
  110. $this->assertFalse(is_array($res));
  111. }
  112. public function testCreatePost(){
  113. global $_user, $_course;
  114. $title = 'xxxxtestxxxx';
  115. $full_text = 'xxxxx';
  116. $file_comment = 'xxxxx';
  117. $blog_id = 1;
  118. $res = $this->oblog->create_post($title, $full_text, $file_comment, $blog_id);
  119. $this->assertTrue($this->oblog->create_post($title, $full_text, $file_comment, $blog_id)=== null);
  120. $this->assertNotNull(is_null,$res);
  121. $this->assertFalse($res);
  122. }
  123. public function testEditPost(){
  124. ob_start();
  125. $post_id =3;
  126. $title = 'xxTestxx';
  127. $full_text = 'testing public function';
  128. $Blog_id = 11;
  129. $res = $this->oblog->edit_post(3,'xtestx','test',11);
  130. ob_end_clean();
  131. $this->assertNotNull($this->oblog->edit_post(3, 'xtestx','test',11)===null);
  132. $this->assertFalse($res);
  133. $this->assertTrue(is_null($res));
  134. //var_dump($res);
  135. }
  136. public function testDeletePost(){
  137. $Blog_id = 11;
  138. $post_id = 21;
  139. $res = $this->oblog->delete_post(11,21);
  140. $this->assertTrue($this->oblog->delete_post(11,21)===null);
  141. $this->assertNull(null,$res);
  142. $this->assertTrue(is_null($res));
  143. //var_dump($res);
  144. }
  145. public function testCreateComment(){
  146. global $_user, $_course, $Blog_table_attachment;
  147. $res = $this->oblog->create_comment('tesingBlog','xxxxxxx','xxx',12,1,null);
  148. $this->assertNotNull($this->oblog->create_comment('tesingBlog','xxxxxxx','xxx',12,1,null)===null);
  149. $this->assertTrue(is_null($res));
  150. $this->assertFalse($res);
  151. }
  152. public function testDeleteComment(){
  153. $res = $this->oblog->delete_comment(11,12,2);
  154. $this->assertNotNull($this->oblog->delete_comment(11,12,2)===null);
  155. $this->assertNull(null,$res);
  156. }
  157. public function testCreateTask(){
  158. $res = $this->oblog->create_task(1,'xxx','xxxxxxx','xxxx','zzzzz','xxzz','blue');
  159. $this->assertNotNull($this->oblog->create_task(1,'xxx','xxxxxxx','xxxx','zzzzz','xxzz','blue')=== null);
  160. $this->assertTrue(is_null($res));
  161. $this->assertFalse($res);
  162. $this->assertFalse(null,$res);
  163. }
  164. public function testEditTask() {
  165. $blog_id = 1;
  166. $task_id = 2;
  167. $title = 'xxxxxx';
  168. $description = 'xx';
  169. $articleDelete = 'aaa';
  170. $articleEdit = 'axa';
  171. $commentsDelete = 'xax';
  172. $color = 'red';
  173. $res = $this->oblog->edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color);
  174. //$res = Blog::edit_task();
  175. $this->assertTrue($this->oblog->edit_task($blog_id, $task_id, $title, $description, $articleDelete, $articleEdit, $commentsDelete, $color)===null);
  176. $this->assertTrue(is_null($res));
  177. $this->assertFalse(is_string($res));
  178. $this->assertNull($res);
  179. }
  180. public function testDeleteTask(){
  181. $blog_id = 1;
  182. $task_id = 2;
  183. $res = $this->oblog->delete_task($blog_id, $task_id);
  184. $this->assertTrue($this->oblog->delete_task($blog_id, $task_id)===null);
  185. $this->assertTrue(is_null($res));
  186. }
  187. public function testDeleteAssignedTask(){
  188. $blog_id = 1;
  189. $task_id = 2;
  190. $user_id = 1;
  191. $res = $this->oblog->delete_assigned_task($blog_id, $task_id,$user_id);
  192. $this->assertTrue($this->oblog->delete_assigned_task($blog_id, $task_id,$user_id)===null);
  193. $this->assertNotNull(is_null($res));
  194. $this->assertFalse($res);
  195. }
  196. public function testGetPersonalTaskList(){
  197. global $_user;
  198. ob_start();
  199. $res = Blog::get_personal_task_list('a');
  200. $this->assertFalse($res);
  201. ob_end_clean();
  202. }
  203. public function testChangeBlogVisibility(){
  204. $blog_id = 1;
  205. $res = $this->oblog->change_blog_visibility($blog_id);
  206. $this->assertTrue($this->oblog->change_blog_visibility($blog_id)=== null);
  207. $this->assertTrue(is_null($res));
  208. }
  209. public function testDisplayBlogPosts(){
  210. ob_start();
  211. $blog_id = 1;
  212. $filter = '1=1';
  213. $max_number_of_posts = 20;
  214. $res = BLog::display_blog_posts($blog_id, $filter, $max_number_of_posts);
  215. $this->assertTrue($this->oblog->display_blog_posts($blog_id, $filter, $max_number_of_posts)=== null);
  216. ob_end_clean();
  217. $this->assertNull($res);
  218. $this->assertTrue(is_null($res));
  219. $this->assertFalse(null, $res);
  220. }
  221. public function testDisplaySearchResults(){
  222. ob_start();
  223. $blog_id = 1;
  224. $query_string = '"SELECT post.*, user.lastname, user.firstname FROM $tbl_blogs_posts"';
  225. $res = $this->oblog->display_search_results($blog_id, $query_string);
  226. ob_end_clean();
  227. $this->assertTrue(is_null($res));
  228. $this->assertNull($res);
  229. }
  230. public function testDisplayDayResults(){
  231. ob_start();
  232. $blog_id = 1;
  233. $query_string = '01-01-2010';
  234. $res = $this->oblog->display_day_results($blog_id, $query_string);
  235. ob_end_clean();
  236. $this->assertTrue(is_null($res));
  237. $this->assertFalse($res);
  238. $this->assertNull(null,$res);
  239. }
  240. public function testDisplayPost(){
  241. ob_start();
  242. $blog_id = 1;
  243. $post_id = 2;
  244. $res = $this->oblog->display_post($blog_id, $post_id);
  245. ob_end_clean();
  246. $this->assertTrue(is_null($res));
  247. $this->assertFalse($res);
  248. }
  249. public function testAddRating(){
  250. global $_user;
  251. $res = $this->oblog->add_rating(null,11,2,5);
  252. $this->assertFalse($this->oblog->add_rating(null,11,2,5)=== bool);
  253. $this->assertTrue(is_bool($res));
  254. $this->assertFalse(null,$res);
  255. }
  256. public function testDisplayRating(){
  257. ob_start();
  258. $res = $this->oblog->display_rating('xxx',11,1);
  259. $this->assertFalse($this->oblog->display_rating('xxx',11,1)===null);
  260. $this->assertTrue(is_numeric($res));
  261. $this->assertFalse($res);
  262. ob_end_clean();
  263. }
  264. public function testDisplayRatingForm(){
  265. global $_user;
  266. $res = $this->oblog->display_rating_form('xxx',11,1,null);
  267. $this->assertFalse($this->oblog->display_rating_form('xxx',11,1,null)===null);
  268. $this->assertTrue(is_string($res));
  269. $this->assertNotNull($res,null);
  270. }
  271. public function testGetThreadedComments(){
  272. ob_start();
  273. $current = 0;
  274. $current_level = 0;
  275. $blog_id = 1;
  276. $post_id = 2;
  277. $task_id = 0;
  278. global $charset, $dataFormatLong;
  279. $res = $this->oblog->get_threaded_comments($current, $current_level, $blog_id, $post_id, $task_id);
  280. ob_end_clean();
  281. $this->assertFalse($res);
  282. $this->assertTrue(is_null($res));
  283. }
  284. public function testDisplayFormNewPost(){
  285. ob_start();
  286. $blog_id = 1;
  287. $res = Blog::display_form_new_post($blog_id);
  288. $this->assertTrue(is_null($res));
  289. $this->assertNull($res);
  290. ob_end_clean();
  291. }
  292. public function testDisplayFormEditPost(){
  293. ob_start();
  294. $blog_id = 1;
  295. $post_id = 2;
  296. $res = $this->oblog->display_form_edit_post($blog_id, $post_id);
  297. $this->assertNotNull(is_null($res));
  298. $this->assertFalse($res);
  299. ob_end_clean();
  300. //var_dump($res);
  301. }
  302. public function testDisplayTaskList(){
  303. ob_start();
  304. $res = $this->oblog->display_task_list(11);
  305. $this->assertTrue($this->oblog->display_task_list(11)===null);
  306. ob_end_clean();
  307. }
  308. public function testDisplayAssignedTaskList(){
  309. ob_start();
  310. global $charset, $color2;
  311. $res = $this->oblog->display_assigned_task_list(11);
  312. $this->assertTrue($this->oblog->display_assigned_task_list(11)===null);
  313. ob_end_clean();
  314. $this->assertFalse($res);
  315. }
  316. public function testDisplayNewTaskForm(){
  317. ob_start();
  318. $res = $this->oblog->display_new_task_form(11);
  319. $this->assertTrue($this->oblog->display_new_task_form(11)===null);
  320. ob_end_clean();
  321. $this->assertFalse($res);
  322. }
  323. public function testDisplayEditTaskForm(){
  324. ob_start();
  325. $res = $this->oblog->display_edit_task_form(11,12);
  326. $this->assertTrue($this->oblog->display_edit_task_form(11,12)===null);
  327. ob_end_clean();
  328. $this->assertTrue(is_null($res));
  329. $this->assertFalse($res);
  330. }
  331. public function testDisplayAssignTaskForm(){
  332. ob_start();
  333. $res = $this->oblog->display_assign_task_form(11);
  334. $this->assertTrue($this->oblog->display_assign_task_form(11)===null);
  335. ob_end_clean();
  336. $this->assertFalse($res);
  337. $this->assertTrue(is_null($res));
  338. }
  339. public function testDisplayEditAssignedTaskForm(){
  340. global $MonthsLong;
  341. ob_start();
  342. $res = $this-> oblog->display_edit_assigned_task_form(11,12,1);
  343. $this->assertTrue($this->oblog->display_edit_assigned_task_form(11,12,1)===null);
  344. ob_end_clean();
  345. $this->assertFalse($res);
  346. }
  347. public function testAssignTask(){
  348. ob_start();
  349. $res = $this->oblog->assign_task(11,1,12,null);
  350. $this->assertTrue($this->oblog->assign_task(11,1,12,null)===null);
  351. ob_end_clean();
  352. $this->assertFalse(is_numeric($res));
  353. $this->assertNull(null,$res);
  354. }
  355. public function testEditAssignedTask(){
  356. $task = array('blog_id'=>11,
  357. 'user_id'=>1,
  358. 'task_id'=>12,
  359. 'target_date'=>'xxxxxxx',
  360. 'old_user_id'=>10,
  361. 'old_task_id'=>11,
  362. 'old_target_date'=>'xxxzxxx'
  363. );
  364. $res = $this->oblog->edit_assigned_task($task['blog_id'],$task['user_id'], $task['task_id'], $task['target_date'], $task['old_user_id'], $task['old_task_id'], $task['old_target_date']);
  365. $this->assertNull($res);
  366. $this->assertTrue(is_null($res));
  367. }
  368. public function testDisplaySelectTaskPost(){
  369. ob_start();
  370. $res = $this->oblog->display_select_task_post(11,12);
  371. $this->assertTrue($this->oblog->display_select_task_post(11,12)===null);
  372. ob_end_clean();
  373. $this->assertTrue(is_null($res));
  374. $this->assertFalse($res);
  375. }
  376. public function testSetUserSubscribed(){
  377. $res = $this->oblog->set_user_subscribed(11,12);
  378. $this->assertTrue($this->oblog->set_user_subscribed(11,12)===null);
  379. $this->assertFalse($res);
  380. $this->assertTrue(is_null($res));
  381. }
  382. public function testUserUnsubscribed(){
  383. $res = $this->oblog->set_user_unsubscribed(11,12);
  384. $this->assertTrue($this->oblog->set_user_unsubscribed(11,12)===null);
  385. $this->assertFalse($res);
  386. $this->assertTrue(is_null($res));
  387. }
  388. public function testDisplayFormUserSubscribe(){
  389. ob_start();
  390. $res = $this->oblog->display_form_user_subscribe(12);
  391. $this->assertTrue($this->oblog->display_form_user_subscribe(12)===null);
  392. ob_end_clean();
  393. $this->assertNotNull(is_null($res));
  394. $this->assertFalse($res);
  395. }
  396. /**
  397. * this function have been tested modified the function
  398. * display_form_user_unsubscribe in the blog.lib.php
  399. * main_table and course_table.
  400. *
  401. */
  402. public function testDisplayFormUserUnsubscribe(){
  403. global $_user;
  404. ob_start();
  405. $blog_id = '1';
  406. $res = Blog::display_form_user_unsubscribe($blog_id);
  407. ob_end_clean();
  408. $this->assertTrue(is_null($res));
  409. $this->assertNull($res);
  410. }
  411. public function testDisplayFormUserRights(){
  412. ob_start();
  413. $res = $this->oblog->display_form_user_rights(12);
  414. $this->assertTrue($this->oblog->display_form_user_rights(12)===null);
  415. ob_end_clean();
  416. $this->assertFalse($res);
  417. }
  418. public function testDisplayNewCommentForm(){
  419. $blog_id = '12';
  420. $post_id='1';
  421. $title='test';
  422. ob_start();
  423. $res =$this->oblog->display_new_comment_form($blog_id,$post_id,$title);
  424. ob_end_clean();
  425. $this->assertFalse($res);
  426. $this->assertNotNull(is_null($res));
  427. }
  428. public function testDisplayMinimonthcalendar(){
  429. global $_user,$DaysShort, $MonthsLong;
  430. ob_start();
  431. $month = 12;
  432. $year = 2010;
  433. $blog_id = 1;
  434. $res = $this->oblog->display_minimonthcalendar($month, $year, $blog_id);
  435. $this->assertTrue($this->oblog->display_minimonthcalendar($month, $year, $blog_id)=== null);
  436. ob_end_clean();
  437. $this->assertTrue(is_null($res));
  438. }
  439. public function testDisplayNewBlogForm(){
  440. ob_start();
  441. $res = $this->oblog->display_new_blog_form();
  442. $this->assertFalse($res);
  443. $this->assertTrue(is_null($res));
  444. $this->assertTrue($this->oblog->display_new_blog_form()===null);
  445. ob_end_clean();
  446. }
  447. public function testDisplayEditBlogForm(){
  448. ob_start();
  449. $res = $this->oblog->display_edit_blog_form(12);
  450. $this->assertTrue($this->oblog->display_edit_blog_form(12)===null);
  451. ob_end_clean();
  452. $this->assertTrue(is_null($res));
  453. }
  454. public function testDisplayBlogList(){
  455. ob_start();
  456. $res = $this->oblog->display_blog_list();
  457. $this->assertTrue($this->oblog->display_blog_list()===null);
  458. ob_end_clean();
  459. $this->assertTrue(is_null($res));
  460. }
  461. public function testGetBlogAttachment(){
  462. ob_start();
  463. ob_end_clean();
  464. global $_configuration;
  465. $blog_id = '0';
  466. $post_id = null;
  467. $comment_id = null;
  468. $res = get_blog_attachment($blog_id, $post_id,$comment_id);
  469. $this->assertFalse($res);
  470. $this->assertTrue(is_array($res));
  471. }
  472. public function testDeleteAllBlogAttachment(){
  473. global $_course,$_configuration;
  474. $blog_id = 1;
  475. $post_id=null;
  476. $comment_id=null;
  477. $res = delete_all_blog_attachment($blog_id,$post_id,$comment_id);
  478. $this->assertFalse($res);
  479. $this->assertNull($res);
  480. }
  481. public function testGetBlogPostFromUser(){
  482. global $_configuration;
  483. $res = get_blog_post_from_user('chamilo_COURSETEST',1);
  484. $this->assertFalse($res);
  485. $this->assertTrue(is_string($res));
  486. //var_dump($res);
  487. }
  488. public function testGetBlogCommentFromUser(){
  489. global $_configuration;
  490. $course_datos['wanted_code'] = 'chamilo_COURSETEST';
  491. $user_id = 1;
  492. $res = get_blog_comment_from_user($course_datos['wanted_code'],1);
  493. $this->assertFalse($res);
  494. $this->assertTrue(is_string($res));
  495. $path = api_get_path(SYS_PATH).'archive';
  496. if ($handle = opendir($path)) {
  497. while (false !== ($file = readdir($handle))) {
  498. if (strpos($file,'COURSETEST')!==false) {
  499. if (is_dir($path.'/'.$file)) {
  500. rmdirr($path.'/'.$file);
  501. }
  502. }
  503. }
  504. closedir($handle);
  505. }
  506. }
  507. /*
  508. public function testDeleteCourse() {
  509. global $cidReq;
  510. $resu = CourseManager::delete_course($cidReq);
  511. }
  512. */
  513. }
  514. ?>