exerciselink.class.test.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. class TestExerciseLink extends UnitTestCase {
  3. public function TestExerciseLink() {
  4. $this->UnitTestCase('Test Exercise Link');
  5. }
  6. public function __construct() {
  7. $this->UnitTestCase('Gradebook exercises library - main/gradebook/lib/be/exerciselink.class.test.php');
  8. global $date;
  9. // The constructor acts like a global setUp for the class
  10. TestManager::create_test_course('COURSEEXERCISELINK');
  11. $this->exerciselink = new ExerciseLink();
  12. $this->exerciselink-> set_id (1);
  13. $this->exerciselink-> set_name ('test');
  14. $this->exerciselink-> set_description ('test description');
  15. $this->exerciselink-> set_user_id (1);
  16. $this->exerciselink-> set_course_code ('COURSEEXERCISELINK');
  17. $this->exerciselink-> set_category_id (1);
  18. $this->exerciselink-> set_date ($date);
  19. $this->exerciselink-> set_weight (1);
  20. $this->exerciselink-> set_max (1);
  21. $this->exerciselink-> set_visible (1);
  22. }
  23. /**
  24. * Generate an array of all exercises available.
  25. * @return array 2-dimensional array - every element contains 2 subelements (id, name)
  26. */
  27. public function testget_all_links() {
  28. $res = $this->exerciselink->get_all_links();
  29. $this->assertTrue(is_array($res));
  30. //var_dump($res);
  31. }
  32. /**
  33. * Get the score of this exercise. Only the first attempts are taken into account.
  34. * @param $stud_id student id (default: all students who have results - then the average is returned)
  35. * @return array (score, max) if student is given
  36. * array (sum of scores, number of scores) otherwise
  37. * or null if no scores available
  38. */
  39. public function testcalc_score() {
  40. $res = $this->exerciselink->calc_score($stud_id = null);
  41. $this->assertTrue(is_null($res));
  42. //var_dump($res);
  43. }
  44. /**
  45. * Get description to display: same as exercise description
  46. */
  47. public function testget_description() {
  48. $res = $this->exerciselink->get_description();
  49. $this->assertTrue(is_null($res));
  50. //var_dump($res);
  51. }
  52. /**
  53. * Get URL where to go to if the user clicks on the link.
  54. * First we go to exercise_jump.php and then to the result page.
  55. * Check this php file for more info.
  56. */
  57. public function testget_link() {
  58. $res = $this->exerciselink->get_link();
  59. $this->assertTrue(is_string($res));
  60. //var_dump($res);
  61. }
  62. /**
  63. * Get name to display: same as exercise title
  64. */
  65. public function testget_name() {
  66. $res = $this->exerciselink->get_name();
  67. $this->assertTrue(is_null($res));
  68. //var_dump($res);
  69. }
  70. /**
  71. * Generate an array of exercises that a teacher hasn't created a link for.
  72. * @return array 2-dimensional array - every element contains 2 subelements (id, name)
  73. */
  74. public function testget_not_created_links() {
  75. $_SESSION['id_session'] = 1;
  76. $res = $this->exerciselink->get_not_created_links();
  77. $this->assertTrue(is_array($res));
  78. $_SESSION['id_session'] = null;
  79. //var_dump($res);
  80. }
  81. public function testget_type_name() {
  82. $res = $this->exerciselink->get_type_name();
  83. $this->assertTrue(is_string($res));
  84. //var_dump($res);
  85. }
  86. /**
  87. * Has anyone done this exercise yet ?
  88. */
  89. public function testhas_results() {
  90. $res = $this->exerciselink->has_results();
  91. $this->assertTrue(is_bool($res));
  92. //var_dump($res);
  93. }
  94. public function testis_allowed_to_change_name() {
  95. $res = $this->exerciselink->is_allowed_to_change_name();
  96. $this->assertTrue(is_bool($res));
  97. //var_dump($res);
  98. }
  99. /**
  100. * Check if this still links to an exercise
  101. */
  102. public function testis_valid_link() {
  103. $res = $this->exerciselink->is_valid_link();
  104. $this->assertTrue(is_bool($res));
  105. //var_dump($res);
  106. }
  107. public function testneeds_max() {
  108. $res = $this->exerciselink->needs_max();
  109. $this->assertTrue(is_bool($res));
  110. //var_dump($res);
  111. }
  112. public function testneeds_name_and_description() {
  113. $res = $this->exerciselink->needs_name_and_description();
  114. $this->assertTrue(is_bool($res));
  115. //var_dump($res);
  116. }
  117. public function testneeds_results() {
  118. $res = $this->exerciselink->needs_results();
  119. $this->assertTrue(is_bool($res));
  120. //var_dump($res);
  121. }
  122. public function __destruct() {
  123. // The destructor acts like a global tearDown for the class
  124. TestManager::delete_test_course('COURSEEXERCISELINK');
  125. }
  126. }
  127. ?>