blog.lib.test.php 16 KB

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