survey.lib.test.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  3. class TestSurvey extends UnitTestCase {
  4. public $smanager;
  5. public $squestion;
  6. public $syesno;
  7. public $multiplechoice;
  8. public $personality;
  9. public $multipleresponse;
  10. public function TestSurvey() {
  11. $this->UnitTestCase('');
  12. }
  13. public function setUp() {
  14. $this->smanager = new SurveyManager();
  15. $this->squestion = new question();
  16. $this->syesno = new yesno();
  17. $this->smultiplechoice = new multiplechoice();
  18. $this->spersonality = new personality();
  19. $this->smultipleresponse = new multipleresponse();
  20. }
  21. public function tearDown() {
  22. $this-> smanager = null;
  23. $this-> squestion = null;
  24. $this-> syesno = null;
  25. $this->smultiplechoice = null;
  26. $this->personality = null;
  27. $this->multipleresponse = null;
  28. }
  29. public function testStoreSurvey() {
  30. global $_user,$cidReq;
  31. $values = array(
  32. 'survey_code' => 'Survey1',
  33. 'survey_title' => '<p>Survey</p>',
  34. 'survey_subtitle' => '',
  35. 'survey_language' => 'spanish',
  36. 'start_date' => '2010-01-19',
  37. 'end_date' => '2010-01-29',
  38. 'survey_introduction' => '',
  39. 'survey_thanks' => '',
  40. 'survey_type' => '0',
  41. 'parent_id' => '0',
  42. 'submit_survey' => ''
  43. );
  44. $res = $this->smanager->store_survey($values);
  45. $this->assertTrue($res);
  46. $this->assertTrue(is_array($res));
  47. }
  48. public function testGetSurvey() {
  49. $course_code = 'COURSETEST';
  50. $survey_id=1;
  51. $res3 = $this->smanager->get_survey($survey_id,0,$course_code);
  52. $this->assertTrue(is_array($res3));
  53. }
  54. public function testStoreSharedSurvey() {
  55. global $_user,$cidReq;
  56. $values = array(
  57. 'survey_code' => 'Survey1',
  58. 'survey_title' => '<p>Survey</p>',
  59. 'survey_subtitle' => 'Survey subtitle',
  60. 'survey_language' => 'spanish',
  61. 'start_date' => '2010-01-19',
  62. 'end_date' => '2010-01-29',
  63. 'survey_introduction' => 'introduction',
  64. 'survey_thanks' => '',
  65. 'survey_type' => '1',
  66. 'parent_id' => '1',
  67. 'submit_survey' => ''
  68. );
  69. $res = $this->smanager->store_shared_survey($values);
  70. $this->assertTrue($res);
  71. //var_dump($res);
  72. }
  73. //Build the form
  74. public function testQuestionCreateForm() {
  75. global $charset;
  76. global $survey_data;
  77. $form_content = array();
  78. $res = $this->squestion->create_form($form_content);
  79. $this->assertTrue(is_string($res));
  80. }
  81. public function testQuestionRenderForm() {
  82. ob_start();
  83. $this->squestion->render_form();
  84. ob_end_clean();
  85. $this->assertNotNull($this->squestion->html);
  86. //var_dump($res);
  87. }
  88. public function testYesNoCreateForm() {
  89. $form_content=array();
  90. $res1 = $this->syesno->create_form($form_content);
  91. $this->assertNull($res1);
  92. }
  93. public function testMultipleChoiceCreateForm() {
  94. $form_content=array();
  95. $res2 = $this->smultiplechoice->create_form($form_content);
  96. $this->assertNull($res2);
  97. }
  98. public function testPersonalityCreateForm() {
  99. $form_content=array();
  100. $this->spersonality->create_form($form_content);
  101. $this->assertNotNull($this->spersonality->html);
  102. $this->assertTrue($this->spersonality->html);
  103. }
  104. public function testMultipleResponseCreateForm() {
  105. $form_content=array();
  106. $this->smultipleresponse->create_form($form_content);
  107. $this->assertNotNull($this->smultipleresponse->html);
  108. $this->assertTrue($this->smultipleresponse->html);
  109. }
  110. public function testQuestionRenderQuestion() {
  111. ob_start();
  112. $form_content=array();
  113. $res = $this->squestion->render_question($form_content);
  114. $this->assertNull($res);
  115. $this->assertTrue(is_null($res));
  116. ob_end_clean();
  117. }
  118. public function testMultipleChoiseRenderQuestion() {
  119. ob_start();
  120. $form_content=array();
  121. $answers=array();
  122. $this->smultiplechoice->render_question($form_content,$answers);
  123. $this->assertNull($this->smultiplechoice->html);
  124. ob_end_clean();
  125. }
  126. public function testYesNoRenderQuestion() {
  127. ob_start();
  128. $form_content=array();
  129. $answers=array();
  130. $this->syesno->render_question($form_content,$answers);
  131. $this->assertNull($this->syesno->html);
  132. ob_end_clean();
  133. }
  134. public function testPersonalityRenderQuestion() {
  135. ob_start();
  136. $form_content=array();
  137. $answers=array();
  138. $this->spersonality->render_question($form_content,$answers);
  139. $this->assertNull($this->spersonality->html);
  140. $this->assertFalse($this->spersonality->html);
  141. ob_end_clean();
  142. }
  143. public function testAddRemoveButtons() {
  144. $form_content = array();
  145. $res = $this->squestion->add_remove_buttons($form_content);
  146. $this->assertTrue($res);
  147. //var_dump($res);
  148. }
  149. //save the survey
  150. public function testCopySurvey() {
  151. $parent_survey = Database::escape_string($parent_survey);
  152. $new_survey_id = '1';
  153. $res = $this->smanager->copy_survey($parent_survey,$new_survey_id);
  154. $this->assertTrue(is_bool($res));
  155. $this->assertTrue($res);
  156. //var_dump($res);
  157. }
  158. public function testIconQuestion() {
  159. $type='open';
  160. $res = $this->smanager->icon_question($type);
  161. if(is_bool($res)) {
  162. $this->assertTrue($res ===false);
  163. $this->assertTrue(is_bool($res));
  164. }else{
  165. $this->assertTrue($res);
  166. $this->assertTrue(is_string($res));
  167. }
  168. //var_dump($res);
  169. }
  170. public function testSaveQuestion() {
  171. $form_content=array();
  172. $res = $this->smanager->save_question($form_content);
  173. $this->assertTrue($res);
  174. $this->assertTrue(is_string($res));
  175. //var_dump($res);
  176. }
  177. public function testSaveSharedQuestion() {
  178. $form_content=array('');
  179. $survey_data=array('survey_share');
  180. $res = $this->smanager->save_shared_question($form_content,$survey_data);
  181. $this->assertTrue($res);
  182. //var_dump($res);
  183. }
  184. public function testSaveQuestionOptions() {
  185. $form_content=array();
  186. $survey_data=array('survey_share');
  187. $res = $this->smanager->save_question_options($form_content,$survey_data);
  188. $this->assertTrue(is_null($res));
  189. //var_dump($res);
  190. }
  191. public function testSaveSharedQuestionOptions() {
  192. $form_content=array();
  193. $survey_data=array();
  194. $res = $this->smanager->save_shared_question_options($form_content,$survey_data);
  195. $this->assertTrue(is_null($res));
  196. $this->assertNull($res);
  197. //var_dump($res);
  198. }
  199. //get the survey
  200. public function testGetPeopleWhoFilledSurvey() {
  201. $survey_id=1;
  202. $all_user_info=false;
  203. $survey_data = SurveyManager::get_survey($survey_id);
  204. $result = $this->smanager->get_people_who_filled_survey($survey_id,false);
  205. $this->assertTrue(is_array($result));
  206. //var_dump($result);
  207. }
  208. public function testGetQuestion() {
  209. $question_id=1;
  210. $res = $this->smanager->get_question($question_id,false);
  211. $this->assertTrue($res);
  212. //var_dump($res);
  213. //var_dump($result);
  214. }
  215. public function testGetQuestions() {
  216. $survey_id =1;
  217. $res= $this->smanager->get_questions($survey_id);
  218. $this->assertNull($res);
  219. //var_dump($res);
  220. }
  221. //move the survey
  222. public function testMoveSurveyQuestion() {
  223. $direction='moveup';
  224. $survey_question_id=1;
  225. $survey_id=1;
  226. $res = $this->smanager->move_survey_question($direction,$survey_question_id,$survey_id);
  227. $this->assertTrue(is_null($res));
  228. //var_dump($res);
  229. }
  230. //epmty the survey
  231. public function testEmpty_survey() {
  232. $survey_id=null;
  233. $res = $this->smanager->empty_survey($survey_id);
  234. $this->assertTrue($res);
  235. //var_dump($res);
  236. }
  237. //functions delete
  238. public function testHandleAction() {
  239. $form_content = array('');
  240. $res = $this->squestion->handle_action($form_content);
  241. $this->assertTrue(is_array($res));
  242. //var_dump($res);
  243. }
  244. public function testDeleteAllSurveyQuestions() {
  245. $survey_id=1;
  246. $shared=false;
  247. $result = $this->smanager->delete_all_survey_questions($survey_id,$shared);
  248. $this->assertTrue(is_null($result));
  249. //var_dump($result);
  250. }
  251. public function testDeleteSurveyQuestion() {
  252. $survey_id =1;
  253. $question_id=01;
  254. $shared=false;
  255. $result = $this->smanager->delete_survey_question($survey_id,$question_id);
  256. $this->assertTrue(is_null($result));
  257. //var_dump($result);
  258. //var_dump($res);
  259. }
  260. public function testDeleteSharedSurveyQuestion() {
  261. $survey_id=1;
  262. $question_id=01;
  263. $res = $this->smanager->delete_shared_survey_question($survey_id,$question_id);
  264. $this->assertTrue(is_null($res));
  265. //var_dump($res);
  266. }
  267. public function testDeleteSurvey() {
  268. $survey_id=1;
  269. $shared=false;
  270. $course_code=001;
  271. $res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
  272. $this->assertTrue($res);
  273. //var_dump($res);
  274. }
  275. public function testDeleteAllSurveyQuestionsOptions() {
  276. $survey_id=1;
  277. $shared=false;
  278. $result = $this->smanager->delete_all_survey_questions_options($survey_id,$shared);
  279. $this->assertTrue($result);
  280. //var_dump($result);
  281. }
  282. public function testDeleteSurveyQuestionOption() {
  283. $survey_id=1;
  284. $question_id=01;
  285. $shared=false;
  286. $result = $this->smanager->delete_survey_question_option($survey_id,$question_id,$shared);
  287. if(is_bool($result))
  288. $this->assertTrue(is_bool($result));
  289. $this->assertTrue($result === true || $result===false);
  290. $this->assertTrue($result);
  291. //var_dump($result);
  292. }
  293. public function testDeleteAllSurveyAnswers() {
  294. $survey_id=1;
  295. $res = $this->smanager->delete_all_survey_answers($survey_id);
  296. $this->assertTrue(is_bool($res));
  297. $this->assertTrue($res);
  298. $this->assertTrue($res === true || $res === false);
  299. //var_dump($res);
  300. }
  301. //Contest the answer
  302. public function testUpdateSurveyAnswered() {
  303. global $user;
  304. $survey_code = 'Survey1';
  305. $survey_id = '1';
  306. $result = $this->smanager->update_survey_answered($survey_id, $user, $survey_code);
  307. $this->assertTrue(is_null($result));
  308. //var_dump($result);
  309. }
  310. /**
  311. * This functon only is added to the end of the test and the end of the files in the all test.
  312. */
  313. /* public function testDeleteCourse() {
  314. global $cidReq;
  315. $resu = CourseManager::delete_course($cidReq);
  316. }*/
  317. }
  318. ?>