/mod/assign/tests/lib_test.php

https://bitbucket.org/kudutest1/moodlegit · PHP · 139 lines · 80 code · 31 blank · 28 comment · 1 complexity · e939b5f86062f1bbc108c5b78a0f985e MD5 · raw file

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Unit tests for (some of) mod/assign/lib.php.
  18. *
  19. * @package mod_assign
  20. * @category phpunit
  21. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. global $CFG;
  26. require_once($CFG->dirroot . '/mod/assign/lib.php');
  27. require_once($CFG->dirroot . '/mod/assign/locallib.php');
  28. require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
  29. /**
  30. * Unit tests for (some of) mod/assign/lib.php.
  31. *
  32. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  33. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34. */
  35. class mod_assign_lib_testcase extends mod_assign_base_testcase {
  36. public function test_assign_print_overview() {
  37. $this->setUser($this->editingteachers[0]);
  38. $this->create_instance();
  39. $this->create_instance(array('duedate'=>time()));
  40. $this->setUser($this->students[0]);
  41. $overview = array();
  42. assign_print_overview(array($this->course->id => $this->course), $overview);
  43. $this->assertEquals(count($overview), 1);
  44. $this->setUser($this->teachers[0]);
  45. $overview = array();
  46. assign_print_overview(array($this->course->id => $this->course), $overview);
  47. $this->assertEquals(count($overview), 1);
  48. $this->setUser($this->editingteachers[0]);
  49. $overview = array();
  50. assign_print_overview(array($this->course->id => $this->course), $overview);
  51. $this->assertEquals(1, count($overview));
  52. }
  53. public function test_print_recent_activity() {
  54. $this->setUser($this->editingteachers[0]);
  55. $assign = $this->create_instance();
  56. $submission = $assign->get_user_submission($this->students[0]->id, true);
  57. $this->expectOutputRegex('/submitted:/');
  58. assign_print_recent_activity($this->course, true, time() - 3600);
  59. }
  60. public function test_assign_get_recent_mod_activity() {
  61. $this->setUser($this->editingteachers[0]);
  62. $assign = $this->create_instance();
  63. $submission = $assign->get_user_submission($this->students[0]->id, true);
  64. $activities = array();
  65. $index = 0;
  66. $activity = new stdClass();
  67. $activity->type = 'activity';
  68. $activity->cmid = $assign->get_course_module()->id;
  69. $activities[$index++] = $activity;
  70. assign_get_recent_mod_activity( $activities,
  71. $index,
  72. time() - 3600,
  73. $this->course->id,
  74. $assign->get_course_module()->id);
  75. $this->assertEquals("assign", $activities[1]->type);
  76. }
  77. public function test_assign_user_complete() {
  78. global $PAGE;
  79. $this->setUser($this->editingteachers[0]);
  80. $assign = $this->create_instance(array('submissiondrafts' => 1));
  81. $PAGE->set_url(new moodle_url('/mod/assign/view.php', array('id'=>$assign->get_course_module()->id)));
  82. $submission = $assign->get_user_submission($this->students[0]->id, true);
  83. $this->expectOutputRegex('/Draft/');
  84. assign_user_complete($this->course, $this->students[0], $assign->get_course_module(), $assign->get_instance());
  85. }
  86. public function test_assign_user_outline() {
  87. $this->setUser($this->editingteachers[0]);
  88. $assign = $this->create_instance();
  89. $this->setUser($this->teachers[0]);
  90. $data = $assign->get_user_grade($this->students[0]->id, true);
  91. $data->grade = '50.5';
  92. $assign->update_grade($data);
  93. $result = assign_user_outline($this->course, $this->students[0], $assign->get_course_module(), $assign->get_instance());
  94. $this->assertRegExp('/50.5/', $result->info);
  95. }
  96. public function test_assign_get_completion_state() {
  97. global $DB;
  98. $assign = $this->create_instance(array('submissiondrafts'=>0, 'completionsubmit'=>1));
  99. $this->setUser($this->students[0]);
  100. $result = assign_get_completion_state($this->course, $assign->get_course_module(), $this->students[0]->id, false);
  101. $this->assertFalse($result);
  102. $submission = $assign->get_user_submission($this->students[0]->id, true);
  103. $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
  104. $DB->update_record('assign_submission', $submission);
  105. $result = assign_get_completion_state($this->course, $assign->get_course_module(), $this->students[0]->id, false);
  106. $this->assertTrue($result);
  107. }
  108. }