category.class.test.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <?php
  2. class TestCategoryClass extends UnitTestCase {
  3. public function TestCategoryClass() {
  4. $this->UnitTestCase('Test Category Class');
  5. }
  6. public function __construct() {
  7. $this->UnitTestCase('Gradebook categories library - main/gradebook/lib/be/category.class.test.php');
  8. // The constructor acts like a global setUp for the class
  9. TestManager::create_test_course('COURSECATEGORYCLASS');
  10. $this->category = new Category();
  11. $this->category->set_id(1);
  12. $this->category->set_name('test');
  13. $this->category->set_description('test description');
  14. $this->category->set_user_id(1);
  15. $this->category->set_course_code('COURSECATEGORYCLASS');
  16. $this->category->set_certificate_min_score(20);
  17. $this->category->set_parent_id(0);
  18. $this->category->set_session_id(1);
  19. $this->category->set_weight(1);
  20. $this->category->set_visible(1);
  21. }
  22. /**
  23. * Insert this category into the database
  24. */
  25. public function testadd() {
  26. $_SESSION['id_session'] = 1;
  27. $res = $this->category->add();
  28. $this->assertTrue(is_null($res));
  29. $_SESSION['id_session'] = null;
  30. //var_dump($res);
  31. }
  32. /**
  33. * Apply the same visibility to every subcategory, evaluation and link
  34. */
  35. public function testapply_visibility_to_children() {
  36. $res = $this->category->apply_visibility_to_children();
  37. $this->assertTrue(is_null($res));
  38. //var_dump($res);
  39. }
  40. /**
  41. * Calculate the score of this category
  42. * @param $stud_id student id (default: all students - then the average is returned)
  43. * @return array (score sum, weight sum)
  44. * or null if no scores available
  45. */
  46. public function testcalc_score() {
  47. $res = $this->category->calc_score($stud_id = null);
  48. $this->assertTrue(is_null($res));
  49. //var_dump($res);
  50. }
  51. /**
  52. * Check if a category name (with the same parent category) already exists
  53. * @param $name name to check (if not given, the name property of this object will be checked)
  54. * @param $parent parent category
  55. * @return bool
  56. */
  57. public function testdoes_name_exist() {
  58. $name = 'test';
  59. $parent=1;
  60. $res = $this->category->does_name_exist($name, $parent);
  61. $this->assertTrue(is_bool($res));
  62. //var_dump($res);
  63. }
  64. /**
  65. * Find category by name
  66. * @param string $name_mask search string
  67. * @return array category objects matching the search criterium
  68. */
  69. public function testfind_category() {
  70. $name_mask = 'test';
  71. $allcat=array();
  72. $res = $this->category->find_category($name_mask,$allcat);
  73. $this->assertTrue(is_array($res));
  74. //var_dump($res);
  75. }
  76. /**
  77. * Generate an array of all courses that a teacher is admin of.
  78. * @return array 2-dimensional array - every element contains 2 subelements (code, title)
  79. */
  80. public function testget_all_courses() {
  81. $user_id = 1;
  82. $res = $this->category->get_all_courses($user_id);
  83. $this->assertTrue(is_array($res));
  84. //var_dump($res);
  85. }
  86. public function testget_certificate_min_score() {
  87. $res = $this->category->get_certificate_min_score();
  88. $this->assertTrue(is_numeric($res));
  89. //var_dump($res);
  90. }
  91. public function testget_course_code() {
  92. $res = $this->category->get_course_code();
  93. $this->assertTrue(is_string($res));
  94. //var_dump($res);
  95. }
  96. public function testget_description() {
  97. $res = $this->category->get_description();
  98. $this->assertTrue(is_string($res));
  99. //var_dump($res);
  100. }
  101. /**
  102. * Get appropriate evaluations visible for the user
  103. * @param int $stud_id student id (default: all students)
  104. * @param boolean $recursive process subcategories (default: no recursion)
  105. */
  106. public function testget_evaluations() {
  107. $res = $this->category->get_evaluations($stud_id = null, $recursive = false);
  108. $this->assertTrue(is_array($res));
  109. //var_dump($res);
  110. }
  111. public function testget_icon_name() {
  112. $res = $this->category->get_icon_name();
  113. $this->assertTrue(is_string($res));
  114. //var_dump($res);
  115. }
  116. public function testget_id() {
  117. $res = $this->category->get_id();
  118. $this->assertTrue(is_numeric($res));
  119. //var_dump($res);
  120. }
  121. public function testget_independent_categories_with_result_for_student() {
  122. $cat_id=1;
  123. $stud_id=1;
  124. $res = $this->category->get_independent_categories_with_result_for_student($cat_id, $stud_id, $cats = array());
  125. $this->assertTrue(is_array($res));
  126. //var_dump($res);
  127. }
  128. public function testget_item_type() {
  129. $res = $this->category->get_item_type();
  130. $this->assertTrue(is_string($res));
  131. //var_dump($res);
  132. }
  133. public function testget_links() {
  134. $res = $this->category->get_links($stud_id = null, $recursive = false);
  135. $this->assertTrue(is_array($res));
  136. //var_dump($res);
  137. }
  138. public function testget_name() {
  139. $res = $this->category->get_name();
  140. $this->assertTrue(is_string($res));
  141. //var_dump($res);
  142. }
  143. public function testget_not_created_course_categories() {
  144. $user_id = 1;
  145. $res = $this->category->get_not_created_course_categories($user_id);
  146. $this->assertTrue(is_array($res));
  147. //var_dump($res);
  148. }
  149. public function testget_parent_id() {
  150. $res = $this->category->get_parent_id();
  151. $this->assertTrue(is_numeric($res));
  152. //var_dump($res);
  153. }
  154. /**
  155. * Return array of Category objects where a student is subscribed to.
  156. * @param int student id
  157. * @param string Course code
  158. * @param int Session id
  159. */
  160. public function testget_root_categories_for_student() {
  161. $stud_id=1;
  162. $res = $this->category->get_root_categories_for_student($stud_id, $course_code = null, $session_id = null);
  163. $this->assertTrue(is_array($res));
  164. //var_dump($res);
  165. }
  166. /**
  167. * Return array of Category objects where a teacher is admin for.
  168. * @param int user id (to return everything, use 'null' here)
  169. * @param string course code (optional)
  170. * @param int session id (optional)
  171. */
  172. public function testget_root_categories_for_teacher() {
  173. $user_id=1;
  174. $res = $this->category->get_root_categories_for_teacher($user_id, $course_code = null, $session_id = null);
  175. $this->assertTrue(is_array($res));
  176. //var_dump($res);
  177. }
  178. public function testget_session_id() {
  179. $user_id=1;
  180. $res = $this->category->get_session_id($user_id, $course_code = null, $session_id = null);
  181. $this->assertTrue(is_numeric($res));
  182. //var_dump($res);
  183. }
  184. /**
  185. * Get appropriate subcategories visible for the user (and optionally the course and session)
  186. * @param int $stud_id student id (default: all students)
  187. * @param string Course code (optional)
  188. * @param int Session ID (optional)
  189. * @return array Array of subcategories
  190. */
  191. public function testget_subcategories() {
  192. $res = $this->category->get_subcategories($stud_id = null, $course_code = null, $session_id = null);
  193. $this->assertTrue(is_array($res));
  194. //var_dump($res);
  195. }
  196. /**
  197. * Generate an array of possible categories where this category can be moved to.
  198. * Notice: its own parent will be included in the list: it's up to the frontend
  199. * to disable this element.
  200. * @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
  201. */
  202. public function testget_target_categories() {
  203. $res = $this->category->get_target_categories();
  204. if(is_array($res)) {
  205. $this->assertTrue(is_array($res));
  206. } else {
  207. $this->assertTrue(is_null($res));
  208. }
  209. var_dump($res);
  210. }
  211. /**
  212. * Generate an array of all categories the user can navigate to
  213. */
  214. public function testget_tree() {
  215. $res = $this->category->get_tree();
  216. $this->assertTrue(is_array($res));
  217. //var_dump($res);
  218. }
  219. public function testget_user_id() {
  220. $res = $this->category->get_user_id();
  221. $this->assertTrue(is_numeric($res));
  222. //var_dump($res);
  223. }
  224. public function testget_weight() {
  225. $res = $this->category->get_weight();
  226. $this->assertTrue(is_numeric($res));
  227. //var_dump($res);
  228. }
  229. /**
  230. * Check if a category contains evaluations with a result for a given student
  231. */
  232. public function testhas_evaluations_with_results_for_student() {
  233. $stud_id = 1;
  234. $res = $this->category->has_evaluations_with_results_for_student($stud_id);
  235. $this->assertTrue(is_bool($res));
  236. //var_dump($res);
  237. }
  238. /**
  239. * Checks if the certificate is available for the given user in this category
  240. * @param integer User ID
  241. * @return boolean True if conditions match, false if fails
  242. */
  243. public function testis_certificate_available() {
  244. $user_id = 1;
  245. $res = $this->category->is_certificate_available($user_id);
  246. $this->assertTrue(is_bool($res));
  247. //var_dump($res);
  248. }
  249. /**
  250. * Is this category a course ?
  251. * A category is a course if it has a course code and no parent category.
  252. */
  253. public function testis_course() {
  254. $res = $this->category->is_course();
  255. $this->assertTrue(is_bool($res));
  256. //var_dump($res);
  257. }
  258. /**
  259. * Can this category be moved to somewhere else ?
  260. * The root and courses cannot be moved.
  261. */
  262. public function testis_movable() {
  263. $res = $this->category->is_movable();
  264. $this->assertTrue(is_bool($res));
  265. //var_dump($res);
  266. }
  267. public function testis_visible() {
  268. $res = $this->category->is_visible();
  269. $this->assertTrue(is_numeric($res));
  270. //var_dump($res);
  271. }
  272. /**
  273. * Retrieve categories and return them as an array of Category objects
  274. * @param int category id
  275. * @param int user id (category owner)
  276. * @param string course code
  277. * @param int parent category
  278. * @param bool visible
  279. * @param int session id (in case we are in a session)
  280. * @param bool Whether to show all "session" categories (true) or hide them (false) in case there is no session id
  281. */
  282. public function testload() {
  283. $res = $this->category->load($id = null, $user_id = null, $course_code = null, $parent_id = null, $visible = null, $session = null, $show_session_categories = true);
  284. $this->assertTrue(is_array($res));
  285. //var_dump($res);
  286. }
  287. /**
  288. * Move this category to the given category.
  289. * If this category moves from inside a course to outside,
  290. * its course code must be changed, as well as the course code
  291. * of all underlying categories and evaluations. All links will
  292. * be deleted as well !
  293. */
  294. public function testmove_to_cat() {
  295. $res = $this->category->move_to_cat($this->category);
  296. $this->assertTrue(is_null($res));
  297. //var_dump($res);
  298. }
  299. /**
  300. * Update the properties of this category in the database
  301. */
  302. public function testsave() {
  303. $res = $this->category->save();
  304. $this->assertTrue(is_null($res));
  305. //var_dump($res);
  306. }
  307. /**
  308. * Show message resource delete
  309. */
  310. public function testshow_message_resource_delete() {
  311. $course_id = 1;
  312. $res = $this->category->show_message_resource_delete($course_id);
  313. $this->assertTrue(is_bool($res));
  314. //var_dump($res);
  315. }
  316. /**
  317. * Shows all information of an category
  318. */
  319. public function testshows_all_information_an_category() {
  320. $res = $this->category->shows_all_information_an_category($selectcat='');
  321. $this->assertTrue(is_null($res));
  322. //var_dump($res);
  323. }
  324. /**
  325. * Not delete this category from the database,when visible=3 is category eliminated
  326. */
  327. public function testupdate_category_delete() {
  328. $course_id = 1;
  329. $res = $this->category->update_category_delete($course_id);
  330. $this->assertTrue(is_null($res));
  331. //var_dump($res);
  332. }
  333. /**
  334. * Delete this evaluation from the database
  335. */
  336. public function testdelete() {
  337. $res = $this->category->delete();
  338. $this->assertTrue(is_null($res));
  339. //var_dump($res);
  340. }
  341. /**
  342. * Delete this category and every subcategory, evaluation and result inside
  343. */
  344. public function testdelete_all() {
  345. $res = $this->category->delete_all();
  346. $this->assertTrue(is_null($res));
  347. //var_dump($res);
  348. }
  349. public function __destruct() {
  350. // The destructor acts like a global tearDown for the class
  351. TestManager::delete_test_course('COURSECATEGORYCLASS');
  352. }
  353. }
  354. ?>