Skip to content

Commit

Permalink
MDL-65726 role: do not fail unittest if plugins create their roles
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed May 28, 2019
1 parent e39f3b7 commit d6c2bf6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/tests/accesslib_test.php
Expand Up @@ -727,8 +727,13 @@ public function test_get_all_roles() {
$this->resetAfterTest();

$allroles = get_all_roles();
$this->assertInternalType('array', $allroles);
$this->assertCount(8, $allroles); // There are 8 roles is standard install.
$this->assertIsArray($allroles);
$initialrolescount = count($allroles);
$this->assertTrue($initialrolescount >= 8); // There are 8 roles is standard install.
$rolenames = array_column($allroles, 'shortname');
foreach (get_role_archetypes() as $archetype) {
$this->assertContains($archetype, $rolenames);
}

$role = reset($allroles);
$role = (array)$role;
Expand All @@ -750,8 +755,8 @@ public function test_get_all_roles() {
$renames = $DB->get_records_menu('role_names', array('contextid'=>$coursecontext->id), '', 'roleid, name');

$allroles = get_all_roles($coursecontext);
$this->assertInternalType('array', $allroles);
$this->assertCount(9, $allroles);
$this->assertIsArray($allroles);
$this->assertCount($initialrolescount + 1, $allroles);
$role = reset($allroles);
$role = (array)$role;

Expand Down Expand Up @@ -784,11 +789,11 @@ public function test_get_role_archetypes() {
public function test_get_archetype_roles() {
$this->resetAfterTest();

// New install should have 1 role for each archetype.
// New install should have at least 1 role for each archetype.
$archetypes = get_role_archetypes();
foreach ($archetypes as $archetype) {
$roles = get_archetype_roles($archetype);
$this->assertCount(1, $roles);
$this->assertGreaterThanOrEqual(1, count($roles));
$role = reset($roles);
$this->assertSame($archetype, $role->archetype);
}
Expand Down Expand Up @@ -818,8 +823,11 @@ public function test_role_get_name() {
$renames = $DB->get_records_menu('role_names', array('contextid'=>$coursecontext->id), '', 'roleid, name');

foreach ($allroles as $role) {
if (in_array($role->shortname, get_role_archetypes())) {
// Standard roles do not have a set name.
$this->assertSame('', $role->name);
}
// Get localised name from lang pack.
$this->assertSame('', $role->name);
$name = role_get_name($role, null, ROLENAME_ORIGINAL);
$this->assertNotEmpty($name);
$this->assertNotEquals($role->shortname, $name);
Expand Down

0 comments on commit d6c2bf6

Please sign in to comment.