Skip to content

Commit

Permalink
put logging output from sync under test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Oct 2, 2024
1 parent c07d8ec commit decfeaf
Showing 1 changed file with 119 additions and 14 deletions.
133 changes: 119 additions & 14 deletions tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use null_progress_trace;
use progress_trace_buffer;
use Psr\Http\Message\RequestInterface;
use text_progress_trace;

/**
* Ilios enrolment tests.
Expand All @@ -46,7 +48,6 @@
*/
final class lib_test extends \advanced_testcase {


/**
* Tests the enrolment of Ilios cohort members into a Moodle course.
*/
Expand Down Expand Up @@ -94,7 +95,7 @@ function (RequestInterface $request) {
[
'id' => 4,
'campusId' => 'xx1000004',
'enabled' => false, // Disabled user account - should result in user unenrolment.
'enabled' => false, // Disabled user account - should result in user enrolment suspension.
],
[
'id' => 5,
Expand Down Expand Up @@ -138,10 +139,12 @@ function (RequestInterface $request) {
$this->assertEquals(0, $DB->count_records('user_enrolments'));

// Instantiate an enrolment instance that targets cohort members in Ilios.
$ilioscohortid = 1; // Ilios cohort ID.
$synctype = 'cohort'; // Enrol from cohort.
$plugin->add_instance($course, [
'customint1' => 1, // Ilios cohort ID.
'customint2' => 0, // Ilios learners enrolment.
'customchar1' => 'cohort', // Enrol from cohort.
'customint1' => $ilioscohortid,
'customint2' => 0,
'customchar1' => $synctype,
'roleid' => $studentrole->id,
]
);
Expand Down Expand Up @@ -223,8 +226,44 @@ function (RequestInterface $request) {
);

// Run enrolment sync.
$trace = new null_progress_trace();
$trace = new progress_trace_buffer(new text_progress_trace(), false);
$plugin->sync($trace, null);
$output = $trace->get_buffer();
$trace->finished();
$trace->reset_buffer();

// Check the logging output.
$this->assertStringContainsString(
"Enrolling students to Course ID {$course->id} with Role ID "
. "{$studentrole->id} through Ilios Sync ID {$instance->id}.",
$output
);
$this->assertStringContainsString('4 Ilios users found.', $output);
$this->assertStringContainsString(
'enrolling with ' . ENROL_USER_ACTIVE . " status: userid {$user5->id} ==> courseid {$course->id}",
$output
);
$this->assertEquals(1, substr_count($output, 'enrolling with ' . ENROL_USER_ACTIVE . ' status:'));
$this->assertStringContainsString(
"Suspending enrollment for disabled Ilios user: userid {$user4->id} ==> courseid {$course->id}.",
$output
);
$this->assertEquals(1, substr_count($output, 'Suspending enrollment for disabled Ilios user:'));
$this->assertStringContainsString(
"Unenrolling users from Course ID {$course->id} with Role ID {$studentrole->id} " .
"that no longer associate with Ilios Sync ID {$instance->id}.",
$output
);
$this->assertStringContainsString(
"unenrolling: {$user1->id} ==> {$course->id} via Ilios {$synctype} {$ilioscohortid}",
$output
);
$this->assertEquals(1, substr_count($output, 'unenrolling:'));
$this->assertStringContainsString(
"unassigning role: {$user4->id} ==> {$course->id} as {$studentrole->shortname}",
$output
);
$this->assertEquals(1, substr_count($output, 'unassigning role:'));

// Check user enrolments post-sync.
$this->assertEquals(
Expand Down Expand Up @@ -399,11 +438,13 @@ function (RequestInterface $request) {
);
$this->assertEquals(0, $DB->count_records('user_enrolments'));

// Instantiate an enrolment instance that targets cohort members in Ilios.
// Instantiate an enrolment instance that targets learner-group members in Ilios.
$ilioslearnergroupid = 1; // Ilios cohort ID.
$synctype = 'learnerGroup'; // Enrol from cohort.
$plugin->add_instance($course, [
'customint1' => 1, // Ilios learner-group ID.
'customint2' => 0, // Ilios learners enrolment.
'customchar1' => 'learnerGroup', // Enrol from learner-group.
'customint1' => $ilioslearnergroupid,
'customint2' => 0,
'customchar1' => $synctype,
'roleid' => $studentrole->id,
]
);
Expand Down Expand Up @@ -485,8 +526,44 @@ function (RequestInterface $request) {
);

// Run enrolment sync.
$trace = new null_progress_trace();
$trace = new progress_trace_buffer(new text_progress_trace(), false);
$plugin->sync($trace, null);
$output = $trace->get_buffer();
$trace->finished();
$trace->reset_buffer();

// Check the logging output.
$this->assertStringContainsString(
"Enrolling students to Course ID {$course->id} with Role ID "
. "{$studentrole->id} through Ilios Sync ID {$instance->id}.",
$output
);
$this->assertStringContainsString('4 Ilios users found.', $output);
$this->assertStringContainsString(
'enrolling with ' . ENROL_USER_ACTIVE . " status: userid {$user5->id} ==> courseid {$course->id}",
$output
);
$this->assertEquals(1, substr_count($output, 'enrolling with ' . ENROL_USER_ACTIVE . ' status:'));
$this->assertStringContainsString(
"Suspending enrollment for disabled Ilios user: userid {$user4->id} ==> courseid {$course->id}.",
$output
);
$this->assertEquals(1, substr_count($output, 'Suspending enrollment for disabled Ilios user:'));
$this->assertStringContainsString(
"Unenrolling users from Course ID {$course->id} with Role ID {$studentrole->id} " .
"that no longer associate with Ilios Sync ID {$instance->id}.",
$output
);
$this->assertStringContainsString(
"unenrolling: {$user1->id} ==> {$course->id} via Ilios {$synctype} {$ilioslearnergroupid}",
$output
);
$this->assertEquals(1, substr_count($output, 'unenrolling:'));
$this->assertStringContainsString(
"unassigning role: {$user4->id} ==> {$course->id} as {$studentrole->shortname}",
$output
);
$this->assertEquals(1, substr_count($output, 'unassigning role:'));

// Check user enrolments post-sync.
$this->assertEquals(
Expand Down Expand Up @@ -809,10 +886,12 @@ function (RequestInterface $request) {
$this->assertEquals(0, $DB->count_records('user_enrolments'));

// Instantiate an enrolment instance that targets cohort members in Ilios.
$learnergroupid = 1;
$synctype = 'learnerGroup';
$plugin->add_instance($course, [
'customint1' => 1, // Ilios learner-group ID.
'customint1' => $learnergroupid,
'customint2' => 1, // Ilios Instructors enrolment.
'customchar1' => 'learnerGroup', // Enrol from learner-group.
'customchar1' => $synctype,
'roleid' => $studentrole->id,
]
);
Expand Down Expand Up @@ -841,8 +920,34 @@ function (RequestInterface $request) {
$this->assertEquals(0, $DB->count_records('user_enrolments', ['enrolid' => $instance->id]));

// Run enrolment sync.
$trace = new null_progress_trace();
$trace = new progress_trace_buffer(new text_progress_trace(), false);
$plugin->sync($trace, null);
$output = $trace->get_buffer();
$trace->finished();
$trace->reset_buffer();

// Check the logging output.
$this->assertStringContainsString(
"Enrolling instructors to Course ID {$course->id} with Role ID "
. "{$studentrole->id} through Ilios Sync ID {$instance->id}.",
$output
);
$this->assertStringContainsString('9 Ilios users found.', $output);
foreach ($users as $user) {
$this->assertStringContainsString(
'enrolling with ' . ENROL_USER_ACTIVE . " status: userid {$user->id} ==> courseid {$course->id}",
$output
);
}
$this->assertEquals(count($users), substr_count($output, 'enrolling with ' . ENROL_USER_ACTIVE . ' status:'));
$this->assertStringNotContainsString('Suspending enrollment for disabled Ilios user:', $output);
$this->assertStringContainsString(
"Unenrolling users from Course ID {$course->id} with Role ID {$studentrole->id} " .
"that no longer associate with Ilios Sync ID {$instance->id}.",
$output
);
$this->assertStringNotContainsString('unenrolling:', $output);
$this->assertStringNotContainsString('unassigning role:', $output);

// Check user enrolments post-sync.
$this->assertEquals(
Expand Down

0 comments on commit decfeaf

Please sign in to comment.