survey.lib.test.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 testGetCompleteSurveyStructure() {
  159. $survey_id='';
  160. $shared=0;
  161. $res = $this->smanager->get_complete_survey_structure($survey_id, $shared);
  162. $this->assertNull($res);
  163. $this->assertTrue($res=== null);
  164. //var_dump($res);
  165. }
  166. public function testIconQuestion() {
  167. $type='open';
  168. $res = $this->smanager->icon_question($type);
  169. if(is_bool($res)) {
  170. $this->assertTrue($res ===false);
  171. $this->assertTrue(is_bool($res));
  172. }else{
  173. $this->assertTrue($res);
  174. $this->assertTrue(is_string($res));
  175. }
  176. //var_dump($res);
  177. }
  178. public function testSaveQuestion() {
  179. $form_content=array();
  180. $res = $this->smanager->save_question($form_content);
  181. $this->assertTrue($res);
  182. $this->assertTrue(is_string($res));
  183. //var_dump($res);
  184. }
  185. public function testSaveSharedQuestion() {
  186. $form_content=array('');
  187. $survey_data=array('survey_share');
  188. $res = $this->smanager->save_shared_question($form_content,$survey_data);
  189. $this->assertTrue($res);
  190. //var_dump($res);
  191. }
  192. public function testSaveQuestionOptions() {
  193. $form_content=array();
  194. $survey_data=array('survey_share');
  195. $res = $this->smanager->save_question_options($form_content,$survey_data);
  196. $this->assertTrue(is_null($res));
  197. //var_dump($res);
  198. }
  199. public function testSaveSharedQuestionOptions() {
  200. $form_content=array();
  201. $survey_data=array();
  202. $res = $this->smanager->save_shared_question_options($form_content,$survey_data);
  203. $this->assertTrue(is_null($res));
  204. $this->assertNull($res);
  205. //var_dump($res);
  206. }
  207. //get the survey
  208. public function testGetPeopleWhoFilledSurvey() {
  209. $survey_id=1;
  210. $all_user_info=false;
  211. $survey_data = SurveyManager::get_survey($survey_id);
  212. $result = $this->smanager->get_people_who_filled_survey($survey_id,false);
  213. $this->assertTrue(is_array($result));
  214. //var_dump($result);
  215. }
  216. public function testGetQuestion() {
  217. $question_id=1;
  218. $res = $this->smanager->get_question($question_id,false);
  219. $this->assertTrue($res);
  220. //var_dump($res);
  221. //var_dump($result);
  222. }
  223. public function testGetQuestions() {
  224. $survey_id =1;
  225. $res= $this->smanager->get_questions($survey_id);
  226. $this->assertNull($res);
  227. //var_dump($res);
  228. }
  229. //move the survey
  230. public function testMoveSurveyQuestion() {
  231. $direction='moveup';
  232. $survey_question_id=1;
  233. $survey_id=1;
  234. $res = $this->smanager->move_survey_question($direction,$survey_question_id,$survey_id);
  235. $this->assertTrue(is_null($res));
  236. //var_dump($res);
  237. }
  238. //epmty the survey
  239. public function testEmpty_survey() {
  240. $survey_id=null;
  241. $res = $this->smanager->empty_survey($survey_id);
  242. $this->assertTrue($res);
  243. //var_dump($res);
  244. }
  245. //functions delete
  246. public function testHandleAction() {
  247. $form_content = array('');
  248. $res = $this->squestion->handle_action($form_content);
  249. $this->assertTrue(is_array($res));
  250. //var_dump($res);
  251. }
  252. public function testDeleteAllSurveyQuestions() {
  253. $survey_id=1;
  254. $shared=false;
  255. $result = $this->smanager->delete_all_survey_questions($survey_id,$shared);
  256. $this->assertTrue(is_null($result));
  257. //var_dump($result);
  258. }
  259. public function testDeleteSurveyQuestion() {
  260. $survey_id =1;
  261. $question_id=01;
  262. $shared=false;
  263. $result = $this->smanager->delete_survey_question($survey_id,$question_id);
  264. $this->assertTrue(is_null($result));
  265. //var_dump($result);
  266. //var_dump($res);
  267. }
  268. public function testDeleteSharedSurveyQuestion() {
  269. $survey_id=1;
  270. $question_id=01;
  271. $res = $this->smanager->delete_shared_survey_question($survey_id,$question_id);
  272. $this->assertTrue(is_null($res));
  273. //var_dump($res);
  274. }
  275. public function testDeleteSurvey() {
  276. $survey_id=1;
  277. $shared=false;
  278. $course_code=001;
  279. $res = $this->smanager->delete_survey($survey_id, $shared, $course_code);
  280. $this->assertTrue($res);
  281. //var_dump($res);
  282. }
  283. public function testDeleteAllSurveyQuestionsOptions() {
  284. $survey_id=1;
  285. $shared=false;
  286. $result = $this->smanager->delete_all_survey_questions_options($survey_id,$shared);
  287. $this->assertTrue($result);
  288. //var_dump($result);
  289. }
  290. public function testDeleteSurveyQuestionOption() {
  291. $survey_id=1;
  292. $question_id=01;
  293. $shared=false;
  294. $result = $this->smanager->delete_survey_question_option($survey_id,$question_id,$shared);
  295. if(is_bool($result))
  296. $this->assertTrue(is_bool($result));
  297. $this->assertTrue($result === true || $result===false);
  298. $this->assertTrue($result);
  299. //var_dump($result);
  300. }
  301. public function testDeleteAllSurveyAnswers() {
  302. $survey_id=1;
  303. $res = $this->smanager->delete_all_survey_answers($survey_id);
  304. $this->assertTrue(is_bool($res));
  305. $this->assertTrue($res);
  306. $this->assertTrue($res === true || $res === false);
  307. //var_dump($res);
  308. }
  309. //Contest the answer
  310. public function testUpdateSurveyAnswered() {
  311. global $user;
  312. $survey_code = 'Survey1';
  313. $survey_id = '1';
  314. $result = $this->smanager->update_survey_answered($survey_id, $user, $survey_code);
  315. $this->assertTrue(is_null($result));
  316. //var_dump($result);
  317. }
  318. /**
  319. * This functon only is added to the end of the test and the end of the files in the all test.
  320. */
  321. /* public function testDeleteCourse() {
  322. global $cidReq;
  323. $resu = CourseManager::delete_course($cidReq);
  324. }*/
  325. }
  326. ?>