blog.lib.test.php 17 KB

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