Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Dec 14, 2023
1 parent ecc7bf2 commit 5c2ab04
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 183 deletions.
98 changes: 36 additions & 62 deletions tests/mod_learningmap_activitymanager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,77 +27,51 @@
* @group mebis
* @covers \mod_learningmap\activitymanager
*/
class mod_learningmap_activitymanager_test extends \advanced_testcase {
class mod_learningmap_activitymanager_test extends mod_learningmap_testcase {
/**
* The course used for testing
*
* @var \stdClass
* Activitymanager instance for testing.
*
* @var activitymanager $activitymanager
*/
protected $course;
/**
* The activities linked in the learningmap
*
* @var array
*/
protected $activities;
/**
* The user used for testing
*
* @var \stdClass
*/
protected $user1;
/**
* The modinfo of the course
*
* @var \course_modinfo|null
*/
protected $modinfo;
/**
* The completion info of the course
*
* @var \completion_info
*/
protected $completion;
/**
* Prepare testing environment
*/
public function setUp(): void {
global $DB;
$this->course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);

$this->activities = [];
for ($i = 0; $i < 9; $i++) {
$this->activities[] = $this->getDataGenerator()->create_module(
'page',
[
'name' => 'A',
'content' => 'B',
'course' => $this->course,
'completion' => COMPLETION_TRACKING_AUTOMATIC,
'completionview' => COMPLETION_VIEW_REQUIRED
]
);
}

$this->user1 = $this->getDataGenerator()->create_user(
[
'email' => '[email protected]',
'username' => 'user1'
]
);

$this->modinfo = get_fast_modinfo($this->course, $this->user1->id);
$this->completion = new \completion_info($this->modinfo->get_course());
}

protected $activitymanager;
/**
* Test completion checking
* @return void
*/
public function test_is_completed(): void {
$this->resetAfterTest();
$this->setAdminUser();
$this->setUser($this->user1);
$this->prepare(LEARNINGMAP_NOCOMPLETION, false, false);
$this->activitymanager = new activitymanager($this->course, $this->users[0]);
$this->completion->set_module_viewed($this->activities[0], $this->users[0]->id);
$this->assertEmpty($this->activitymanager->is_completed($this->activities[0]), true);

$assign = $this->activities[7];
$grades = [];
$grades[$this->users[0]] = (object)[
'rawgrade' => 1, 'userid' => $this->users[0]
];
$assign['cmidnumber'] = null;
assign_grade_item_update((object)$assign, $grades);
$this->assertEmpty($this->activitymanager->is_completed($this->activities[7]), false);
$this->completion->set_module_viewed($this->activities[7], $this->users[0]->id);
$this->assertEmpty($this->activitymanager->is_completed($this->activities[7]), true);

$assign = $this->activities[8];
$grades = [];
$grades[$this->users[0]] = (object)[
'rawgrade' => 1, 'userid' => $this->users[0]
];
$assign['cmidnumber'] = null;
assign_grade_item_update((object)$assign, $grades);
$this->assertEmpty($this->activitymanager->is_completed($this->activities[8]), false);
$this->completion->set_module_viewed($this->activities[7], $this->users[0]->id);
$this->assertEmpty($this->activitymanager->is_completed($this->activities[8]), false);
$grades[$this->users[0]] = (object)[
'rawgrade' => 10, 'userid' => $this->users[0]
];
assign_grade_item_update((object)$assign, $grades);
$this->assertEmpty($this->activitymanager->is_completed($this->activities[8]), true);
}

}
122 changes: 1 addition & 121 deletions tests/mod_learningmap_completion_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,127 +30,7 @@
* @group mebis
* @covers \mod_learningmap\completion\custom_completion
*/
class mod_learningmap_completion_test extends \advanced_testcase {
/**
* The course used for testing
*
* @var \stdClass
*/
protected $course;
/**
* The learning map used for testing
*
* @var \stdClass
*/
protected $learningmap;
/**
* The activities linked in the learningmap
*
* @var array
*/
protected $activities;
/**
* The users used for testing
*
* @var array
*/
protected $users;
/**
* The group used for testing
*
* @var \stdClass
*/
protected $group;
/**
* Whether group mode is active
*
* @var boolean
*/
protected $groupmode;
/**
* The modinfo of the course
*
* @var \course_modinfo|null
*/
protected $modinfo;
/**
* The completion info of the course
*
* @var \completion_info
*/
protected $completion;
/**
* The cm_info object belonging to the learning map (differs from the learningmap record)
*
* @var \cm_info
*/
protected $cm;
/**
* Prepare testing environment
*/
/**
* Prepare testing environment
* @param int $completiontype Type for automatic completion
* @param bool $groupmode Whether to use group mode (defaults to false)
*/
public function prepare($completiontype, $groupmode = false): void {
global $DB;
$this->groupmode = $groupmode;
$this->course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);
$this->learningmap = $this->getDataGenerator()->create_module('learningmap',
['course' => $this->course, 'completion' => 2, 'completiontype' => $completiontype,
'groupmode' => ($groupmode ? SEPARATEGROUPS : NOGROUPS), ]
);

$this->activities = [];
for ($i = 0; $i < 9; $i++) {
$this->activities[] = $this->getDataGenerator()->create_module(
'page',
['name' => 'A', 'content' => 'B', 'course' => $this->course, 'completion' => 2, 'completionview' => 1]
);
$this->learningmap->placestore = str_replace(99990 + $i, $this->activities[$i]->cmid, $this->learningmap->placestore);
}
$DB->set_field('learningmap', 'placestore', $this->learningmap->placestore, ['id' => $this->learningmap->id]);

$this->users[0] = $this->getDataGenerator()->create_user(
[
'email' => '[email protected]',
'username' => 'user1',
]
);
$studentrole = $DB->get_record('role', ['shortname' => 'student']);
$this->getDataGenerator()->enrol_user($this->users[0]->id, $this->course->id, $studentrole->id);
if ($this->groupmode) {
$this->group = $this->getDataGenerator()->create_group(['courseid' => $this->course->id]);
$this->users[1] = $this->getDataGenerator()->create_user(
[
'email' => '[email protected]',
'username' => 'user2',
]
);
$this->users[2] = $this->getDataGenerator()->create_user(
[
'email' => '[email protected]',
'username' => 'user3',
]
);
$this->getDataGenerator()->enrol_user($this->users[1]->id, $this->course->id, $studentrole->id);
$this->getDataGenerator()->enrol_user($this->users[2]->id, $this->course->id, $studentrole->id);
$this->getDataGenerator()->create_group_member([
'userid' => $this->users[0]->id,
'groupid' => $this->group->id,
]);
$this->getDataGenerator()->create_group_member([
'userid' => $this->users[1]->id,
'groupid' => $this->group->id,
]);
}

$this->modinfo = get_fast_modinfo($this->course, $this->users[0]->id);
$this->completion = new \completion_info($this->modinfo->get_course());
$this->cm = $this->modinfo->get_cm($this->learningmap->cmid);
}

class mod_learningmap_completion_test extends mod_learningmap_testcase {
/**
* Tests completiontype 1 in individual mode
*
Expand Down
Loading

0 comments on commit 5c2ab04

Please sign in to comment.