evaluation.class.test.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. class TestEvaluation extends UnitTestCase {
  3. public function TestEvaluation() {
  4. $this->UnitTestCase('Test Evaluation');
  5. }
  6. public function __construct() {
  7. $this->UnitTestCase('Gradebook evaluation library - main/gradebook/lib/be/evaluation.class.test.php');
  8. // The constructor acts like a global setUp for the class
  9. global $date;
  10. TestManager::create_test_course('COURSEEVALUATION');
  11. $this->evaluation = new Evaluation();
  12. $this->evaluation-> set_id (1);
  13. $this->evaluation-> set_name ('test');
  14. $this->evaluation-> set_description ('test description');
  15. $this->evaluation-> set_user_id (1);
  16. $this->evaluation-> set_course_code ('COURSEEVALUATION');
  17. $this->evaluation-> set_category_id (1);
  18. $this->evaluation-> set_date ($date);
  19. $this->evaluation-> set_weight (1);
  20. $this->evaluation-> set_max (1);
  21. $this->evaluation-> set_visible (1);
  22. }
  23. /**
  24. * Insert this evaluation into the database
  25. */
  26. public function testadd() {
  27. $res = $this->evaluation->add();
  28. $this->assertTrue(is_null($res));
  29. //var_dump($res);
  30. }
  31. public function testadd_evaluation_log() {
  32. $idevaluation = 1;
  33. $res = $this->evaluation->add_evaluation_log($idevaluation);
  34. $this->assertTrue(is_null($res));
  35. //var_dump($res);
  36. }
  37. /**
  38. * Calculate the score of this evaluation
  39. * @param $stud_id student id (default: all students who have results for this eval - then the average is returned)
  40. * @return array (score, max) if student is given
  41. * array (sum of scores, number of scores) otherwise
  42. * or null if no scores available
  43. */
  44. public function testcalc_score() {
  45. $res = $this->evaluation->calc_score($stud_id = null);
  46. $this->assertTrue(is_null($res));
  47. //var_dump($res);
  48. }
  49. /**
  50. * Delete this evaluation from the database
  51. */
  52. public function testdelete() {
  53. $res = $this->evaluation->delete();
  54. $this->assertTrue(is_null($res));
  55. //var_dump($res);
  56. }
  57. /**
  58. * Delete all results for this evaluation
  59. */
  60. public function testdelete_results() {
  61. $res = $this->evaluation->delete_results();
  62. $this->assertTrue(is_null($res));
  63. //var_dump($res);
  64. }
  65. /**
  66. * Delete this evaluation and all underlying results.
  67. */
  68. public function testdelete_with_results() {
  69. $res = $this->evaluation->delete_with_results();
  70. $this->assertTrue(is_null($res));
  71. //var_dump($res);
  72. }
  73. /**
  74. * Check if an evaluation name (with the same parent category) already exists
  75. * @param $name name to check (if not given, the name property of this object will be checked)
  76. * @param $parent parent category
  77. */
  78. public function testdoes_name_exist() {
  79. $name = 'test name';
  80. $parent = 1;
  81. $res = $this->evaluation->does_name_exist($name, $parent);
  82. $this->assertTrue(is_bool($res));
  83. //var_dump($res);
  84. }
  85. /**
  86. * Find evaluations by name
  87. * @param string $name_mask search string
  88. * @return array evaluation objects matching the search criterium
  89. * @todo can be written more efficiently using a new (but very complex) sql query
  90. */
  91. //problem with the call get_evaluations(): Call to a member function get_evaluations() on a non-object
  92. /*public function testfind_evaluations() {
  93. $name_mask = 'test name mask';
  94. $selectcat = 1;
  95. $res = Evaluation::find_evaluations($name_mask,$selectcat);
  96. $this->assertTrue(is_array($res));
  97. //var_dump($res);
  98. }*/
  99. public function testget_category_id() {
  100. $res = $this->evaluation->get_category_id();
  101. $this->assertTrue(is_numeric($res));
  102. //var_dump($res);
  103. }
  104. public function testget_course_code() {
  105. $res = $this->evaluation->get_course_code();
  106. $this->assertTrue(is_string($res));
  107. //var_dump($res);
  108. }
  109. public function testget_date() {
  110. $res = $this->evaluation->get_date();
  111. $this->assertTrue(is_null($res));
  112. //var_dump($res);
  113. }
  114. public function testget_description() {
  115. $res = $this->evaluation->get_description();
  116. $this->assertTrue(is_string($res));
  117. //var_dump($res);
  118. }
  119. /**
  120. * Retrieve evaluations where a student has results for
  121. * and return them as an array of Evaluation objects
  122. * @param $cat_id parent category (use 'null' to retrieve them in all categories)
  123. * @param $stud_id student id
  124. */
  125. public function testget_evaluations_with_result_for_student() {
  126. $stud_id = 1;
  127. $res = $this->evaluation->get_evaluations_with_result_for_student($cat_id = null, $stud_id);
  128. $this->assertTrue(is_array($res));
  129. //var_dump($res);
  130. }
  131. public function testget_icon_name() {
  132. $res = $this->evaluation->get_icon_name();
  133. $this->assertTrue(is_string($res));
  134. //var_dump($res);
  135. }
  136. public function testget_id() {
  137. $res = $this->evaluation->get_id();
  138. $this->assertTrue(is_numeric($res));
  139. //var_dump($res);
  140. }
  141. public function testget_item_type() {
  142. $res = $this->evaluation->get_item_type();
  143. $this->assertTrue(is_string($res));
  144. //var_dump($res);
  145. }
  146. public function testget_max() {
  147. $res = $this->evaluation->get_max();
  148. $this->assertTrue(is_numeric($res));
  149. //var_dump($res);
  150. }
  151. public function testget_name() {
  152. $res = $this->evaluation->get_name();
  153. $this->assertTrue(is_string($res));
  154. //var_dump($res);
  155. }
  156. /**
  157. * Get a list of students that do not have a result record for this evaluation
  158. */
  159. public function testget_not_subscribed_students() {
  160. $res = $this->evaluation->get_not_subscribed_students($first_letter_user = '');
  161. $this->assertTrue(is_array($res));
  162. //var_dump($res);
  163. }
  164. /**
  165. * Generate an array of possible categories where this evaluation can be moved to.
  166. * Notice: its own parent will be included in the list: it's up to the frontend
  167. * to disable this element.
  168. * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
  169. */
  170. public function testget_target_categories() {
  171. $res = $this->evaluation->get_target_categories();
  172. $this->assertTrue(is_array($res));
  173. //var_dump($res);
  174. }
  175. public function testget_user_id() {
  176. $res = $this->evaluation->get_user_id();
  177. $this->assertTrue(is_numeric($res));
  178. //var_dump($res);
  179. }
  180. public function testget_weight() {
  181. $res = $this->evaluation->get_weight();
  182. $this->assertTrue(is_numeric($res));
  183. //var_dump($res);
  184. }
  185. /**
  186. * Are there any results for this evaluation yet ?
  187. * The 'max' property should not be changed then.
  188. */
  189. public function testhas_results() {
  190. $res = $this->evaluation->has_results();
  191. $this->assertTrue(is_bool($res));
  192. //var_dump($res);
  193. }
  194. public function testis_valid_score() {
  195. $score = 1;
  196. $res = $this->evaluation->is_valid_score($score);
  197. $this->assertTrue(is_bool($res));
  198. //var_dump($res);
  199. }
  200. public function testis_visible() {
  201. $res = $this->evaluation->is_visible();
  202. $this->assertTrue(is_numeric($res));
  203. //var_dump($res);
  204. }
  205. /**
  206. * Retrieve evaluations and return them as an array of Evaluation objects
  207. * @param $id evaluation id
  208. * @param $user_id user id (evaluation owner)
  209. * @param $course_code course code
  210. * @param $category_id parent category
  211. * @param $visible visible
  212. */
  213. public function testload() {
  214. $res = $this->evaluation->load($id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null);
  215. $this->assertTrue(is_array($res));
  216. //var_dump($res);
  217. }
  218. /**
  219. * Move this evaluation to the given category.
  220. * If this evaluation moves from inside a course to outside,
  221. * its course code is also changed.
  222. */
  223. public function testmove_to_cat() {
  224. $cat = $this->evaluation;
  225. $res = $this->evaluation->move_to_cat($cat);
  226. $this->assertTrue(is_null($res));
  227. //var_dump($res);
  228. }
  229. /**
  230. * Update the properties of this evaluation in the database
  231. */
  232. public function testsave() {
  233. $res = $this->evaluation->save();
  234. $this->assertTrue(is_null($res));
  235. //var_dump($res);
  236. }
  237. public function testset_category_id() {
  238. $res = $this->evaluation->set_category_id(1);
  239. $this->assertTrue(is_null($res));
  240. //var_dump($res);
  241. }
  242. public function testset_course_code() {
  243. $res = $this->evaluation->set_course_code('COURSEEVALUATION');
  244. $this->assertTrue(is_null($res));
  245. //var_dump($res);
  246. }
  247. public function testset_date() {
  248. global $date;
  249. $res = $this->evaluation->set_date('02/02/2010');
  250. $this->assertTrue(is_null($res));
  251. //var_dump($res);
  252. }
  253. public function testset_description() {
  254. $res = $this->evaluation->set_description('test description');
  255. $this->assertTrue(is_null($res));
  256. //var_dump($res);
  257. }
  258. public function testset_id() {
  259. $res = $this->evaluation->set_id(1);
  260. $this->assertTrue(is_null($res));
  261. //var_dump($res);
  262. }
  263. public function testset_max() {
  264. $res = $this->evaluation->set_max(1);
  265. $this->assertTrue(is_null($res));
  266. //var_dump($res);
  267. }
  268. public function testset_name() {
  269. $res = $this->evaluation->set_name('test name');
  270. $this->assertTrue(is_null($res));
  271. //var_dump($res);
  272. }
  273. public function testset_user_id() {
  274. $res = $this->evaluation->set_user_id(1);
  275. $this->assertTrue(is_null($res));
  276. //var_dump($res);
  277. }
  278. public function testset_visible() {
  279. $res = $this->evaluation->set_visible(1);
  280. $this->assertTrue(is_null($res));
  281. //var_dump($res);
  282. }
  283. public function testset_weight() {
  284. $res = $this->evaluation->set_weight(1);
  285. $this->assertTrue(is_null($res));
  286. //var_dump($res);
  287. }
  288. public function __destruct() {
  289. // The destructor acts like a global tearDown for the class
  290. TestManager::delete_test_course('COURSEEVALUATION');
  291. }
  292. }
  293. ?>