5 use Webmozart\PathUtil\Path;
11 class RoleCase extends CommandUnishTestCase
13 use TestModuleHelperTrait;
16 * Create, edit, block, and cancel users.
18 public function testRole()
20 $this->setUpDrupal(1, true);
22 // In D8+, the testing profile has no perms.
23 // Copy the module to where Drupal expects it.
24 $this->setupModulesForTests(['user_form_test'], Path::join($this->webroot(), 'core/modules/user/tests/modules'));
25 $this->drush('pm-enable', ['user_form_test']);
27 $this->drush('role-list');
28 $output = $this->getOutput();
29 $this->assertNotContains('cancel other accounts', $output);
31 $this->drush('role-list', [], ['filter' => 'cancel other accounts']);
32 $output = $this->getOutput();
33 $this->assertNotContains('authenticated', $output);
34 $this->assertNotContains('anonymous', $output);
36 // Create the role foo.
38 $this->drush('role-create', [$rid]);
39 $this->drush('role-list');
40 $this->assertContains($rid, $this->getOutput());
42 // Assert that anon user starts without 'cancel other accounts' perm.
43 $perm = 'cancel other accounts';
44 $this->drush('role-list', [], ['format' => 'json']);
45 $role = $this->getOutputFromJSON($rid);
46 $this->assertFalse(in_array($perm, $role->perms));
48 // Now grant that perm to foo.
49 $this->drush('role-add-perm', [$rid, 'cancel other accounts']);
50 $this->drush('role-list', [], ['format' => 'json']);
51 $role = $this->getOutputFromJSON($rid);
52 $this->assertTrue(in_array($perm, $role->perms));
54 // Now remove the perm from foo.
55 $this->drush('role-remove-perm', [$rid, 'cancel other accounts']);
56 $this->drush('role-list', [], ['format' => 'json']);
57 $role = $this->getOutputFromJSON($rid);
58 $this->assertFalse(in_array($perm, $role->perms));
60 // Delete the foo role
61 $this->drush('role-delete', [$rid]);
62 $this->drush('role-list');
63 $this->assertNotContains($rid, $this->getOutput());