1 changed files with 107 additions and 0 deletions
@ -0,0 +1,107 @@ |
|||||
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
|
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation, either version 3 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
// GNU General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
/** |
||||
|
* Base class for unit tests for mod_assign. |
||||
|
* |
||||
|
* @package blocks_completion_progress |
||||
|
* @category phpunit |
||||
|
* @copyright 2017 onwards Nelson Moller {@link http://moodle.com} |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
|
||||
|
global $CFG; |
||||
|
require_once($CFG->dirroot . '/mod/assign/locallib.php'); |
||||
|
|
||||
|
class mod_assign_base_testcase extends advanced_testcase { |
||||
|
|
||||
|
/** @const Default number of students to create */ |
||||
|
const DEFAULT_STUDENT_COUNT = 3; |
||||
|
/** @const Default number of teachers to create */ |
||||
|
const DEFAULT_TEACHER_COUNT = 1; |
||||
|
|
||||
|
/** |
||||
|
* Setup function - we will create a course and add an assign instance to it. |
||||
|
*/ |
||||
|
protected function setUp() { |
||||
|
global $DB; |
||||
|
|
||||
|
$this->resetAfterTest(true); |
||||
|
|
||||
|
set_config('enablecompletion', 1); |
||||
|
|
||||
|
$this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); |
||||
|
$this->teachers = array(); |
||||
|
for ($i = 0; $i < self::DEFAULT_TEACHER_COUNT; $i++) { |
||||
|
array_push($this->teachers, $this->getDataGenerator()->create_user()); |
||||
|
} |
||||
|
|
||||
|
$this->students = array(); |
||||
|
for ($i = 0; $i < self::DEFAULT_STUDENT_COUNT; $i++) { |
||||
|
array_push($this->students, $this->getDataGenerator()->create_user()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$teacherrole = $DB->get_record('role', array('shortname'=>'teacher')); |
||||
|
foreach ($this->teachers as $i => $teacher) { |
||||
|
$this->getDataGenerator()->enrol_user($teacher->id, |
||||
|
$this->course->id, |
||||
|
$teacherrole->id); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$studentrole = $DB->get_record('role', array('shortname'=>'student')); |
||||
|
foreach ($this->students as $i => $student) { |
||||
|
$this->getDataGenerator()->enrol_user($student->id, |
||||
|
$this->course->id, |
||||
|
$studentrole->id); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Convenience function to create a testable instance of an assignment. |
||||
|
* |
||||
|
* @param array $params Array of parameters to pass to the generator |
||||
|
* @return testable_assign Testable wrapper around the assign class. |
||||
|
*/ |
||||
|
protected function create_instance($params=array()) { |
||||
|
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); |
||||
|
$params['course'] = $this->course->id; |
||||
|
$instance = $generator->create_instance($params); |
||||
|
$cm = get_coursemodule_from_instance('assign', $instance->id); |
||||
|
$context = context_module::instance($cm->id); |
||||
|
return new assign($context, $cm, $this->course); |
||||
|
} |
||||
|
|
||||
|
public function test_assign_get_completion_state() { |
||||
|
global $DB; |
||||
|
$assign = $this->create_instance(array('submissiondrafts' => 0, 'completionsubmit' => 1)); |
||||
|
|
||||
|
$this->setUser($this->students[0]); |
||||
|
$result = assign_get_completion_state($this->course, $assign->get_course_module(), $this->students[0]->id, false); |
||||
|
$this->assertFalse($result); |
||||
|
$submission = $assign->get_user_submission($this->students[0]->id, true); |
||||
|
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED; |
||||
|
$DB->update_record('assign_submission', $submission); |
||||
|
|
||||
|
$result = assign_get_completion_state($this->course, $assign->get_course_module(), $this->students[0]->id, false); |
||||
|
|
||||
|
$this->assertTrue($result); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue