Skip to content

Commit a024a02

Browse files
committed
MDL-65726 core_roles: allow to create roles in install.php
1 parent 53ef327 commit a024a02

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

enrol/self/tests/self_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ public function test_get_welcome_email_contact() {
669669
$context = context_course::instance($course1->id);
670670

671671
// Get editing teacher role.
672-
$editingteacherrole = $DB->get_record('role', ['archetype' => 'editingteacher']);
672+
$editingteacherrole = $DB->get_record('role', ['shortname' => 'editingteacher']);
673673
$this->assertNotEmpty($editingteacherrole);
674674

675675
// Enable self enrolment plugin and set to send email from course contact.
@@ -700,7 +700,7 @@ public function test_get_welcome_email_contact() {
700700
$this->assertEquals($user1->email, $contact->email);
701701

702702
// Get manager role, and enrol user as manager.
703-
$managerrole = $DB->get_record('role', ['archetype' => 'manager']);
703+
$managerrole = $DB->get_record('role', ['shortname' => 'manager']);
704704
$this->assertNotEmpty($managerrole);
705705
$instance1->customint4 = ENROL_SEND_EMAIL_FROM_KEY_HOLDER;
706706
$DB->update_record('enrol', $instance1);

lib/tests/accesslib_test.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ public function test_has_coursecontact_role() {
340340

341341
$user = $this->getDataGenerator()->create_user();
342342
$course = $this->getDataGenerator()->create_course();
343-
role_assign($CFG->coursecontact, $user->id, context_course::instance($course->id));
343+
$contactroles = preg_split('/,/', $CFG->coursecontact);
344+
$roleid = reset($contactroles);
345+
role_assign($roleid, $user->id, context_course::instance($course->id));
344346
$this->assertTrue(has_coursecontact_role($user->id));
345347
}
346348

@@ -800,7 +802,7 @@ public function test_get_archetype_roles() {
800802

801803
create_role('New student role', 'student2', 'New student description', 'student');
802804
$roles = get_archetype_roles('student');
803-
$this->assertCount(2, $roles);
805+
$this->assertGreaterThanOrEqual(2, count($roles));
804806
}
805807

806808
/**
@@ -1508,14 +1510,8 @@ public function test_get_default_enrol_roles() {
15081510
$allroles = get_all_roles();
15091511
$expected = array($id2=>$allroles[$id2]);
15101512

1511-
foreach (get_role_archetypes() as $archetype) {
1512-
$defaults = get_default_contextlevels($archetype);
1513-
if (in_array(CONTEXT_COURSE, $defaults)) {
1514-
$roles = get_archetype_roles($archetype);
1515-
foreach ($roles as $role) {
1516-
$expected[$role->id] = $role;
1517-
}
1518-
}
1513+
foreach (get_roles_for_contextlevels(CONTEXT_COURSE) as $roleid) {
1514+
$expected[$roleid] = $roleid;
15191515
}
15201516

15211517
$roles = get_default_enrol_roles($coursecontext);
@@ -2694,7 +2690,7 @@ public function test_permission_evaluation() {
26942690
$testcourses = array();
26952691
$testpages = array();
26962692
$testblocks = array();
2697-
$allroles = $DB->get_records_menu('role', array(), 'id', 'archetype, id');
2693+
$allroles = $DB->get_records_menu('role', array(), 'id', 'shortname, id');
26982694

26992695
$systemcontext = context_system::instance();
27002696
$frontpagecontext = context_course::instance(SITEID);
@@ -3616,8 +3612,8 @@ public function test_update_capabilities() {
36163612
$this->resetAfterTest(true);
36173613

36183614
$froncontext = context_course::instance($SITE->id);
3619-
$student = $DB->get_record('role', array('archetype'=>'student'));
3620-
$teacher = $DB->get_record('role', array('archetype'=>'teacher'));
3615+
$student = $DB->get_record('role', array('shortname'=>'student'));
3616+
$teacher = $DB->get_record('role', array('shortname'=>'teacher'));
36213617

36223618
$existingcaps = $DB->get_records('capabilities', array(), 'id', 'name, captype, contextlevel, component, riskbitmask');
36233619

0 commit comments

Comments
 (0)