MDL-31356 enrol_imsenterprise: add additional test coverage

This commit is contained in:
Dan Poltawski 2013-09-27 14:41:18 +08:00 committed by Issam Taboubi
parent ecf6a0ab5b
commit 81e849bc71

View File

@ -145,42 +145,29 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
public function test_user_update() {
global $DB;
$user3 = new StdClass();
$user3->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$user3->username = 'u3';
$user3->email = 'u3@u3.org';
$user3->firstname = 'U';
$user3->lastname = '3';
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
$imsuser = new stdClass();
$imsuser->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_UPDATE;
// THIS SHOULD WORK, surely?: $imsuser->username = $user->username;
// But this is required...
$imsuser->username = $user->idnumber;
$imsuser->email = 'u3@u3.org';
$imsuser->firstname = 'U';
$imsuser->lastname = '3';
$users = array($user3);
$this->set_xml_file($users);
$this->set_xml_file(array($imsuser));
$this->imsplugin->cron();
$user3u = $DB->get_record('user', array('username' => $user3->username));
$user3u->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_UPDATE;
$user3u->email = 'updated_u3@updated_u3.org';
$user3u->firstname = 'updated_U';
$user3u->lastname = 'updated_3';
$users = array($user3u);
$this->set_xml_file($users);
$this->imsplugin->cron();
$dbuser = $DB->get_record('user', array('username' => $user3->username));
$this->assertEquals($dbuser->email, $user3u->email);
$this->assertEquals($dbuser->firstname, $user3u->firstname);
$this->assertEquals($dbuser->lastname, $user3u->lastname);
$dbuser = $DB->get_record('user', array('id' => $user->id), '*', MUST_EXIST);
$this->assertEquals($imsuser->email, $dbuser->email);
$this->assertEquals($imsuser->firstname, $dbuser->firstname);
$this->assertEquals($imsuser->lastname, $dbuser->lastname);
}
/**
* Update user disabled
*/
public function test_user_update_disabled() {
global $DB;
$this->imsplugin->set_config('imsupdateusers', false);
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
$imsuser = new stdClass();
$imsuser ->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_UPDATE;
@ -190,8 +177,10 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$imsuser->email = 'u3@u3.org';
$imsuser->firstname = 'U';
$imsuser->lastname = '3';
$this->set_xml_file(array($imsuser));
$this->imsplugin->cron();
// Verify no changes have been made.
$dbuser = $DB->get_record('user', array('id' => $user->id), '*', MUST_EXIST);
$this->assertEquals($user->email, $dbuser->email);
@ -207,6 +196,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('imsdeleteusers', true);
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
$imsuser = new stdClass();
$imsuser->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_DELETE;
$imsuser->username = $user->username;
@ -214,6 +204,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$imsuser->lastname = $user->lastname;
$imsuser->email = $user->email;
$this->set_xml_file(array($imsuser));
$this->imsplugin->cron();
$this->assertEquals(1, $DB->get_field('user', 'deleted', array('id' => $user->id), '*', MUST_EXIST));
}
@ -223,8 +214,10 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
*/
public function test_user_delete_disabled() {
global $DB;
$this->imsplugin->set_config('imsdeleteusers', false);
$user = $this->getDataGenerator()->create_user(array('idnumber' => 'test-update-user'));
$imsuser = new stdClass();
$imsuser->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_DELETE;
$imsuser->username = $user->username;
@ -232,11 +225,11 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$imsuser->lastname = $user->lastname;
$imsuser->email = $user->email;
$this->set_xml_file(array($imsuser));
$this->imsplugin->cron();
$this->assertEquals(0, $DB->get_field('user', 'deleted', array('id' => $user->id), '*', MUST_EXIST));
}
/**
* Existing courses are not created again
*/
@ -297,19 +290,27 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
$this->imsplugin->set_config('createnewcourses', false);
$prevncourses = $DB->count_records('course');
$course1 = new StdClass();
$course1->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course1->idnumber = 'id1';
$course1->imsshort = 'id1';
$course1->category = 'DEFAULT CATNAME';
$course2 = new StdClass();
$course2->recstatus = enrol_imsenterprise_plugin::IMSENTERPRISE_ADD;
$course2->idnumber = 'id2';
$course2->imsshort = 'id2';
$course2->category = 'DEFAULT CATNAME';
$courses = array($course1, $course2);
$this->set_xml_file(false, $courses);
$this->imsplugin->cron();
$courses = array($course1, $course2);
$this->set_xml_file(false, $courses);
$this->imsplugin->cron();
// Verify the courses have not ben creased.
$this->assertEquals($prevncourses , $DB->count_records('course'));
$this->assertFalse($DB->record_exists('course', array('idnumber' => $course1->idnumber)));