exercise.class.test.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <?php
  2. class TestExercise extends UnitTestCase {
  3. public $eExercise;
  4. public function TestExercise() {
  5. $this->UnitTestCase('');
  6. }
  7. public function setUp() {
  8. $this->eExercise = new Exercise();
  9. }
  10. public function tearDown() {
  11. $this->eExercise = null;
  12. }
  13. /**
  14. * adds a question into the question list
  15. * @param - integer $questionId - question ID
  16. * @return - boolean - true if the question has been added, otherwise false
  17. */
  18. function testaddToList() {
  19. $questionId = 1;
  20. $res = $this->eExercise->addToList($questionId);
  21. $this->assertTrue(is_bool($res));
  22. //var_dump($res);
  23. }
  24. /**
  25. * Creates the form to create / edit an exercise
  26. * @param FormValidator $form the formvalidator instance (by reference)
  27. */
  28. function testcreateForm() {
  29. global $id;
  30. $form = new FormValidator('introduction_text');
  31. $res = $this->eExercise->createForm($form, $type='full');
  32. $this->assertTrue(is_null($res));
  33. //var_dump($res);
  34. }
  35. /**
  36. * disables the exercise
  37. */
  38. function testdisable() {
  39. $res = $this->eExercise->disable();
  40. $this->assertTrue(is_null($res));
  41. //var_dump($res);
  42. }
  43. function testdisable_results() {
  44. $res = $this->eExercise->disable_results();
  45. $this->assertTrue(is_null($res));
  46. //var_dump($res);
  47. }
  48. /**
  49. * enables the exercise
  50. */
  51. function testenable() {
  52. $res = $this->eExercise->enable();
  53. $this->assertTrue(is_null($res));
  54. //var_dump($res);
  55. }
  56. function testenable_results() {
  57. $res = $this->eExercise->enable_results();
  58. $this->assertTrue(is_null($res));
  59. //var_dump($res);
  60. }
  61. /**
  62. * Same as isRandom() but has a name applied to values different than 0 or 1
  63. */
  64. function testgetShuffle() {
  65. $res = $this->eExercise->getShuffle();
  66. $this->assertTrue(is_numeric($res));
  67. //var_dump($res);
  68. }
  69. /**
  70. * returns 'true' if the question ID is in the question list
  71. *
  72. * @author - Olivier Brouckaert
  73. * @param - integer $questionId - question ID
  74. * @return - boolean - true if in the list, otherwise false
  75. */
  76. function testisInList() {
  77. $questionId = 1;
  78. $res = $this->eExercise->isInList($questionId);
  79. $this->assertTrue(is_bool($res));
  80. //var_dump($res);
  81. }
  82. /**
  83. * tells if questions are selected randomly, and if so returns the draws
  84. *
  85. * @author - Olivier Brouckaert
  86. * @return - integer - 0 if not random, otherwise the draws
  87. */
  88. function testisRandom() {
  89. $res = $this->eExercise->isRandom();
  90. $this->assertTrue(is_bool($res));
  91. //var_dump($res);
  92. }
  93. /**
  94. * moves a question down in the list
  95. * @param - integer $id - question ID to move down
  96. */
  97. function testmoveDown() {
  98. $id=1;
  99. $res = $this->eExercise->moveDown($id);
  100. if(!is_null($res)){
  101. $this->assertTrue(is_numeric($res));
  102. }
  103. //var_dump($res);
  104. }
  105. /**
  106. * moves a question up in the list
  107. * @param - integer $id - question ID to move up
  108. */
  109. function testmoveUp() {
  110. $id=1;
  111. $res = $this->eExercise->moveUp($id);
  112. if(!is_null($res)){
  113. $this->assertTrue(is_numeric($res));
  114. }
  115. //var_dump($res);
  116. }
  117. /**
  118. * function which process the creation of exercises
  119. * @param FormValidator $form the formvalidator instance
  120. */
  121. /*
  122. function testprocessCreation() {
  123. $form = new FormValidator('exerciseTitle');
  124. $res = $this->eExercise->processCreation($form,$type='');
  125. if(!is_null($res)){
  126. $this->assertTrue(is_numeric($res));
  127. }
  128. //var_dump($res);
  129. }*/
  130. /**
  131. * reads exercise informations from the data base
  132. * @param - integer $id - exercise ID
  133. * @return - boolean - true if exercise exists, otherwise false
  134. */
  135. function testread() {
  136. global $_course;
  137. global $_configuration;
  138. global $questionList;
  139. $id=1;
  140. $res = $this->eExercise->read($id);
  141. if(!is_null($res)){
  142. $this->assertTrue(is_bool($res));
  143. }
  144. //var_dump($res);
  145. }
  146. /**
  147. * removes a question from the question list
  148. * @param - integer $questionId - question ID
  149. * @return - boolean - true if the question has been removed, otherwise false
  150. */
  151. function testremoveFromList() {
  152. global $_course;
  153. global $_configuration;
  154. global $questionList;
  155. $questionId=1;
  156. $res = $this->eExercise-> removeFromList($questionId);
  157. if(!is_null($res)){
  158. $this->assertTrue(is_bool($res));
  159. }
  160. //var_dump($res);
  161. }
  162. /**
  163. * updates the exercise in the data base
  164. */
  165. function testsave() {
  166. global $_course,$_user;
  167. $res = $this->eExercise-> save($type_e='');
  168. $this->assertTrue(is_null($res));
  169. //var_dump($res);
  170. }
  171. function testsearch_engine_delete() {
  172. $res = $this->eExercise-> search_engine_delete();
  173. $this->assertTrue(is_null($res));
  174. //var_dump($res);
  175. }
  176. function testsearch_engine_save() {
  177. $res = $this->eExercise-> search_engine_save();
  178. $this->assertTrue(is_null($res));
  179. //var_dump($res);
  180. }
  181. /**
  182. * returns the number of attempts setted
  183. * @return - numeric - exercise attempts
  184. */
  185. function testselectAttempts() {
  186. $res = $this->eExercise-> selectAttempts();
  187. $this->assertTrue(is_null($res));
  188. //var_dump($res);
  189. }
  190. /**
  191. * returns the exercise description
  192. * @return - string - exercise description
  193. */
  194. function testselectDescription() {
  195. $res = $this->eExercise-> selectDescription();
  196. $this->assertTrue(is_string($res));
  197. //var_dump($res);
  198. }
  199. /**
  200. * returns the expired time
  201. * @return - string - expired time
  202. */
  203. function testselectExpiredTime() {
  204. $res = $this->eExercise-> selectExpiredTime();
  205. $this->assertTrue(is_string($res));
  206. //var_dump($res);
  207. }
  208. /** returns the number of FeedbackType *
  209. * 0=>Feedback , 1=>DirectFeedback, 2=>NoFeedback
  210. * @return - numeric - exercise attempts
  211. */
  212. function testselectFeedbackType() {
  213. $res = $this->eExercise-> selectFeedbackType();
  214. $this->assertTrue(is_null($res));
  215. //var_dump($res);
  216. }
  217. /**
  218. * returns the exercise ID
  219. * @return - integer - exercise ID
  220. */
  221. function testselectId() {
  222. $res = $this->eExercise-> selectId();
  223. $this->assertTrue(is_numeric($res));
  224. //var_dump($res);
  225. }
  226. /**
  227. * returns the number of questions in this exercise
  228. * @return - integer - number of questions
  229. */
  230. function testselectNbrQuestions() {
  231. $res = $this->eExercise-> selectNbrQuestions();
  232. $this->assertTrue(is_numeric($res));
  233. //var_dump($res);
  234. }
  235. /**
  236. * returns the array with the question ID list
  237. * @return - array - question ID list
  238. */
  239. function testselectQuestionList() {
  240. $res = $this->eExercise-> selectQuestionList();
  241. $this->assertTrue(is_array($res));
  242. //var_dump($res);
  243. }
  244. /**
  245. * returns random answers status.
  246. */
  247. function testselectRandomAnswers() {
  248. $res = $this->eExercise-> selectRandomAnswers();
  249. $this->assertTrue(is_numeric($res));
  250. //var_dump($res);
  251. }
  252. /**
  253. * selects questions randomly in the question list
  254. *
  255. * @author - Olivier Brouckaert
  256. * @return - array - if the exercise is not set to take questions randomly, returns the question list
  257. * without randomizing, otherwise, returns the list with questions selected randomly
  258. */
  259. function testselectRandomList() {
  260. $res = $this->eExercise-> selectRandomList();
  261. $this->assertTrue(is_array($res));
  262. //var_dump($res);
  263. }
  264. /**
  265. * tells if questions are selected randomly, and if so returns the draws
  266. * @return - integer - results disabled exercise
  267. */
  268. function testselectResultsDisabled() {
  269. $res = $this->eExercise-> selectResultsDisabled();
  270. $this->assertTrue(is_numeric($res));
  271. //var_dump($res);
  272. }
  273. /**
  274. * returns the exercise sound file
  275. * @return - string - exercise description
  276. */
  277. function testselectSound() {
  278. $res = $this->eExercise-> selectSound();
  279. $this->assertTrue(is_string($res));
  280. //var_dump($res);
  281. }
  282. /**
  283. * returns the exercise status (1 = enabled ; 0 = disabled)
  284. * @return - int - true if enabled, otherwise false
  285. */
  286. function testselectStatus() {
  287. $res = $this->eExercise-> selectStatus();
  288. $this->assertTrue(is_numeric($res));
  289. //var_dump($res);
  290. }
  291. /**
  292. * returns the time limit
  293. * @return int
  294. */
  295. function testselectTimeLimit() {
  296. $res = $this->eExercise-> selectTimeLimit();
  297. $this->assertTrue(is_numeric($res));
  298. //var_dump($res);
  299. }
  300. /**
  301. * returns the exercise title
  302. * @return - string - exercise title
  303. */
  304. function testselectTitle() {
  305. $res = $this->eExercise-> selectTitle();
  306. $this->assertTrue(is_string($res));
  307. //var_dump($res);
  308. }
  309. /**
  310. * returns the exercise type
  311. * @return - integer - exercise type
  312. */
  313. function testselectType() {
  314. $res = $this->eExercise-> selectType();
  315. $this->assertTrue(is_numeric($res));
  316. //var_dump($res);
  317. }
  318. /**
  319. * sets to 0 if questions are not selected randomly
  320. * if questions are selected randomly, sets the draws
  321. * @param - integer $random - 0 if not random, otherwise the draws
  322. * @return void
  323. */
  324. function testsetRandom() {
  325. $random = 1;
  326. $res = $this->eExercise-> setRandom($random);
  327. $this->assertTrue(is_null($res));
  328. //var_dump($res);
  329. }
  330. /**
  331. * update the table question
  332. * @return void
  333. */
  334. function testupdate_question_positions() {
  335. $res = $this->eExercise-> update_question_positions();
  336. $this->assertTrue(is_null($res));
  337. //var_dump($res);
  338. }
  339. /**
  340. * changes the exercise max attempts
  341. * @param - numeric $attempts - exercise max attempts
  342. * @return void
  343. */
  344. function testupdateAttempts() {
  345. $attempts = 1;
  346. $res = $this->eExercise-> updateAttempts($attempts);
  347. $this->assertTrue(is_null($res));
  348. //var_dump($res);
  349. }
  350. /**
  351. * changes the exercise description
  352. * @param - string $description - exercise description
  353. * @return void
  354. */
  355. function testupdateDescription() {
  356. $description = 'testdescription';
  357. $res = $this->eExercise-> updateDescription($description);
  358. $this->assertTrue(is_null($res));
  359. //var_dump($res);
  360. }
  361. /**
  362. * changes the exercise expired_time
  363. * @param - int The expired time of the quiz
  364. * @return void
  365. */
  366. function testupdateExpiredTime() {
  367. $expired_time = 1;
  368. $res = $this->eExercise-> updateExpiredTime($expired_time);
  369. $this->assertTrue(is_null($res));
  370. //var_dump($res);
  371. }
  372. /**
  373. * changes the exercise feedback type
  374. * @param - numeric $attempts - exercise max attempts
  375. * @return void
  376. */
  377. function testupdateFeedbackType() {
  378. $feedback_type = 1;
  379. $res = $this->eExercise-> updateFeedbackType($feedback_type);
  380. $this->assertTrue(is_null($res));
  381. //var_dump($res);
  382. }
  383. /**
  384. * sets to 0 if answers are not selected randomly
  385. * if answers are selected randomly
  386. * @param - integer $random_answers - random answers
  387. * @return void
  388. */
  389. function testupdateRandomAnswers() {
  390. $random_answers = 0;
  391. $res = $this->eExercise-> updateRandomAnswers($random_answers);
  392. $this->assertTrue(is_null($res));
  393. //var_dump($res);
  394. }
  395. /**
  396. * update the results
  397. * @return void
  398. */
  399. function testupdateResultsDisabled() {
  400. $results_disabled = 1;
  401. $res = $this->eExercise->updateResultsDisabled($results_disabled);
  402. $this->assertTrue(is_null($res));
  403. //var_dump($res);
  404. }
  405. /**
  406. * changes the exercise sound file
  407. * @param - string $sound - exercise sound file
  408. * @param - string $delete - ask to delete the file
  409. * @return void
  410. */
  411. function testupdateSound() {
  412. global $audioPath, $documentPath,$_course, $_user;
  413. $sound = 'test';
  414. $delete = 'test';
  415. $res = $this->eExercise->updateSound($sound,$delete);
  416. $this->assertTrue(is_null($res));
  417. //var_dump($res);
  418. }
  419. /**
  420. * changes the exercise title
  421. * @param - string $title - exercise title
  422. * @return void
  423. */
  424. function testupdateTitle() {
  425. $title = 'test';
  426. $res = $this->eExercise->updateTitle($title);
  427. $this->assertTrue(is_null($res));
  428. //var_dump($res);
  429. }
  430. /**
  431. * changes the exercise type
  432. * @param - integer $type - exercise type
  433. */
  434. function testupdateType() {
  435. $type = 1;
  436. $res = $this->eExercise->updateType($type);
  437. $this->assertTrue(is_null($res));
  438. //var_dump($res);
  439. }
  440. /**
  441. * deletes the exercise from the database
  442. * Notice : leaves the question in the data base
  443. */
  444. function testdelete() {
  445. global $_course,$_user;
  446. $res = $this->eExercise->delete();
  447. $this->assertTrue(is_null($res));
  448. //var_dump($res);
  449. }
  450. }
  451. ?>