6fc9de603209e09d54bfe0d6076a1a0ae22ba920
[yaffs-website] / vendor / drush / drush / tests / RoleTest.php
1 <?php
2
3 namespace Unish;
4
5 use Webmozart\PathUtil\Path;
6
7 /**
8  *  @group slow
9  *  @group commands
10  */
11 class RoleCase extends CommandUnishTestCase
12 {
13     use TestModuleHelperTrait;
14
15     /**
16      * Create, edit, block, and cancel users.
17      */
18     public function testRole()
19     {
20         $this->setUpDrupal(1, true);
21
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']);
26
27         $this->drush('role-list');
28         $output = $this->getOutput();
29         $this->assertNotContains('cancel other accounts', $output);
30
31         $this->drush('role-list', [], ['filter' => 'cancel other accounts']);
32         $output = $this->getOutput();
33         $this->assertNotContains('authenticated', $output);
34         $this->assertNotContains('anonymous', $output);
35
36         // Create the role foo.
37         $rid = 'foo';
38         $this->drush('role-create', [$rid]);
39         $this->drush('role-list');
40         $this->assertContains($rid, $this->getOutput());
41
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));
47
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));
53
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));
59
60         // Delete the foo role
61         $this->drush('role-delete', [$rid]);
62         $this->drush('role-list');
63         $this->assertNotContains($rid, $this->getOutput());
64     }
65 }