answer.class.test.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. class TestAnswer extends UnitTestCase {
  3. public $aAnswer;
  4. public function TestAnswer() {
  5. $this->UnitTestCase('');
  6. }
  7. public function setUp() {
  8. /*
  9. //Create a new exercise
  10. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  11. require_once api_get_path(SYS_CODE_PATH).'inc/lib/pear/HTML/QuickForm.php';
  12. $this->aAnswer = new Answer(2);
  13. $this->aAnswer->read();
  14. $this->aAnswer = new Exercise();
  15. $form = array(
  16. 'exerciseTitle'=>'testtitle',
  17. 'exerciseDescription'=>'testdescription',
  18. 'exerciseAttempts'=>'0',
  19. 'exerciseFeedbackType'=>'0',
  20. 'exerciseType'=>'1',
  21. 'randomQuestions'=>'0',
  22. 'randomAnswers'=>'0',
  23. 'results_disabled'=>'0',
  24. 'enabletimercontroltotalminutes'=>'0');
  25. $res = Exercise::processCreation($form,$type='1');
  26. */
  27. $this->aAnswer = new Answer(2);
  28. }
  29. public function tearDown() {
  30. $this->aAnswer = null;
  31. }
  32. /**
  33. * constructor of the class
  34. *
  35. * @author Olivier Brouckaert
  36. * @param integer Question ID that answers belong to
  37. */
  38. /*
  39. function testAnswerConstructor() {
  40. $questionId = 1;
  41. $res = $this->aAnswer->Answer($questionId);
  42. $this->assertTrue(is_null($res));
  43. //var_dump($res);
  44. }
  45. */
  46. /**
  47. * creates a new answer
  48. *
  49. * @author Olivier Brouckaert
  50. * @param string answer title
  51. * @param integer 0 if bad answer, not 0 if good answer
  52. * @param string answer comment
  53. * @param integer answer weighting
  54. * @param integer answer position
  55. * @param coordinates Coordinates for hotspot exercises (optional)
  56. * @param integer Type for hotspot exercises (optional)
  57. */
  58. function testcreateAnswer() {
  59. $answer = 'test';
  60. $correct = 1;
  61. $comment ='test';
  62. $weighting = 2;
  63. $position = 1;
  64. $res = $this->aAnswer->createAnswer($answer,$correct,$comment,$weighting,$position,$new_hotspot_coordinates = 1, $new_hotspot_type = 1,$destination='');
  65. $this->assertTrue(is_null($res));
  66. //var_dump($res);
  67. }
  68. /**
  69. * duplicates answers by copying them into another question
  70. * @param - integer $newQuestionId - ID of the new question
  71. */
  72. function testduplicate() {
  73. $newQuestionId = 1;
  74. $res = $this->aAnswer->duplicate($newQuestionId);
  75. $this->assertTrue(is_null($res));
  76. //var_dump($res);
  77. }
  78. /**
  79. * Returns a list of answers
  80. * @return array List of answers where each answer is an array of (id, answer, comment, grade) and grade=weighting
  81. */
  82. function testgetAnswersList() {
  83. $res = $this->aAnswer->getAnswersList();
  84. $this->assertTrue(is_array($res));
  85. //var_dump($res);
  86. }
  87. /**
  88. * Returns a list of grades
  89. * @return array List of grades where grade=weighting (?)
  90. */
  91. function testgetGradesList() {
  92. $res = $this->aAnswer->getGradesList();
  93. $this->assertTrue(is_array($res));
  94. //var_dump($res);
  95. }
  96. /**
  97. * Returns the question type
  98. * @return integer The type of the question this answer is bound to
  99. */
  100. function testgetQuestionType() {
  101. $res = $this->aAnswer->getQuestionType();
  102. if(!is_null($res)){
  103. $this->assertTrue(is_numeric($res));
  104. }
  105. //var_dump($res);
  106. }
  107. /**
  108. * tells if answer is correct or not
  109. * @param - integer $id - answer ID
  110. * @return - integer - 0 if bad answer, not 0 if good answer
  111. */
  112. function testisCorrect() {
  113. $id = 1;
  114. $res = $this->aAnswer->isCorrect($id);
  115. if(!is_null($res)){
  116. $this->assertTrue(is_numeric($res));
  117. }
  118. //var_dump($res);
  119. }
  120. /**
  121. * reads answer informations from the data base
  122. */
  123. function testread() {
  124. $res = $this->aAnswer->read();
  125. $this->assertTrue(is_null($res));
  126. //var_dump($res);
  127. }
  128. /**
  129. * reads answer informations from the data base ordered by parameter
  130. * @param string Field we want to order by
  131. * @param string DESC or ASC
  132. */
  133. function testreadOrderedBy() {
  134. global $_course;
  135. $field = 'position';
  136. $res = $this->aAnswer->readOrderedBy($field,$order=ASC);
  137. $this->assertTrue(is_null($res));
  138. //var_dump($res);
  139. }
  140. /**
  141. * records answers into the data base
  142. */
  143. function testsave() {
  144. $res = $this->aAnswer->save();
  145. $this->assertTrue(is_null($res));
  146. //var_dump($res);
  147. }
  148. /**
  149. * returns the answer title
  150. * @param - integer $id - answer ID
  151. * @return - string - answer title
  152. */
  153. function testselectAnswer() {
  154. $id = 1;
  155. $res = $this->aAnswer->selectAnswer($id);
  156. if(!is_null($res)){
  157. $this->assertTrue(is_string($res));
  158. }
  159. //var_dump($res);
  160. }
  161. /**
  162. * @param - integer $id - answer ID
  163. * @return - bool - answer by id
  164. */
  165. function testselectAnswerByAutoId() {
  166. $auto_id = 1;
  167. $res = $this->aAnswer->selectAnswerByAutoId($auto_id);
  168. if(!is_null($res)){
  169. $this->assertTrue(is_array($res));
  170. } else {
  171. $this->assertTrue(is_bool($res));
  172. }
  173. //var_dump($res);
  174. }
  175. /**
  176. * returns the answer title from an answer's position
  177. * @param - integer $id - answer ID
  178. * @return - bool - answer title
  179. */
  180. function testselectAnswerIdByPosition() {
  181. $pos = 1;
  182. $res = $this->aAnswer->selectAnswerIdByPosition($pos);
  183. if(!is_null($res)){
  184. $this->assertTrue(is_bool($res));
  185. }
  186. //var_dump($res);
  187. }
  188. /**
  189. * returns the autoincrement id identificator
  190. * @return - integer - answer num
  191. */
  192. function testselectAutoId() {
  193. $id = 1;
  194. $res = $this->aAnswer->selectAutoId($id);
  195. if(!is_null($res)){
  196. $this->assertTrue(is_numeric($res));
  197. }
  198. //var_dump($res);
  199. }
  200. /**
  201. * returns answer comment
  202. * @param - integer $id - answer ID
  203. * @return - string - answer comment
  204. */
  205. function testselectComment() {
  206. $id = 1;
  207. $res = $this->aAnswer->selectComment($id);
  208. if(!is_null($res)){
  209. $this->assertTrue(is_string($res));
  210. }
  211. //var_dump($res);
  212. }
  213. /**
  214. * returns the question ID of the destination question
  215. * @return - integer - the question ID
  216. */
  217. function testselectDestination() {
  218. $id = 1;
  219. $res = $this->aAnswer->selectDestination($id);
  220. if(!is_null($res)){
  221. $this->assertTrue(is_string($res));
  222. }
  223. //var_dump($res);
  224. }
  225. /**
  226. * returns answer hotspot coordinates
  227. * @param integer Answer ID
  228. * @return integer Answer position
  229. */
  230. function testselectHotspotCoordinates() {
  231. $id = 1;
  232. $res = $this->aAnswer->selectHotspotCoordinates($id);
  233. if(!is_null($res)){
  234. $this->assertTrue(is_string($res));
  235. }
  236. }
  237. /**
  238. * returns answer hotspot type
  239. *
  240. * @author Toon Keppens
  241. * @param integer Answer ID
  242. * @return integer Answer position
  243. */
  244. function testselectHotspotType() {
  245. $id = 1;
  246. $res = $this->aAnswer->selectHotspotType($id);
  247. if(!is_null($res)){
  248. $this->assertTrue(is_string($res));
  249. }
  250. }
  251. /**
  252. * returns the number of answers in this question
  253. *
  254. * @author - Olivier Brouckaert
  255. * @return - integer - number of answers
  256. */
  257. function testselectNbrAnswers() {
  258. $res = $this->aAnswer->selectNbrAnswers();
  259. if(!is_null($res)){
  260. $this->assertTrue(is_numeric($res));
  261. }
  262. }
  263. /**
  264. * returns answer position
  265. *
  266. * @author - Olivier Brouckaert
  267. * @param - integer $id - answer ID
  268. * @return - integer - answer position
  269. */
  270. function testselectPosition() {
  271. $id = 1;
  272. $res = $this->aAnswer->selectPosition($id);
  273. if(!is_null($res)){
  274. $this->assertTrue(is_numeric($res));
  275. }
  276. }
  277. /**
  278. * returns the question ID which the answers belong to
  279. *
  280. * @author - Olivier Brouckaert
  281. * @return - integer - the question ID
  282. */
  283. function testselectQuestionId() {
  284. $res = $this->aAnswer->selectQuestionId();
  285. if(!is_null($res)){
  286. $this->assertTrue(is_numeric($res));
  287. }
  288. }
  289. /**
  290. * returns answer weighting
  291. *
  292. * @author - Olivier Brouckaert
  293. * @param - integer $id - answer ID
  294. * @return - integer - answer weighting
  295. */
  296. function testselectWeighting() {
  297. $id = 1;
  298. $res = $this->aAnswer->selectWeighting($id);
  299. if(!is_null($res)){
  300. $this->assertTrue(is_numeric($res));
  301. }
  302. }
  303. /**
  304. * updates an answer
  305. *
  306. * @author Toon Keppens
  307. * @param string Answer title
  308. * @param string Answer comment
  309. * @param integer Answer weighting
  310. * @param integer Answer position
  311. */
  312. function testupdateAnswers() {
  313. $answer = '';
  314. $comment = '';
  315. $weighting=2;
  316. $position=1;
  317. $destination='0@@0@@0@@0';
  318. $res = $this->aAnswer->updateAnswers($answer,$comment,$weighting,$position,$destination);
  319. if(!is_null($res)){
  320. $this->assertTrue(is_numeric($res));
  321. }
  322. }
  323. /**
  324. * clears $new_* arrays
  325. */
  326. function testcancel() {
  327. $res = $this->aAnswer->cancel();
  328. $this->assertTrue(is_null($res));
  329. //var_dump($res);
  330. }
  331. }
  332. ?>