forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoleTest.php
65 lines (53 loc) · 2.21 KB
/
RoleTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Unish;
use Webmozart\PathUtil\Path;
/**
* @group slow
* @group commands
*/
class RoleTest extends CommandUnishTestCase
{
use TestModuleHelperTrait;
/**
* Create, edit, block, and cancel users.
*/
public function testRole()
{
$this->setUpDrupal(1, true);
// In D8+, the testing profile has no perms.
// Copy the module to where Drupal expects it.
$this->setupModulesForTests(['user_form_test'], Path::join($this->webroot(), 'core/modules/user/tests/modules'));
$this->drush('pm-install', ['user_form_test']);
$this->drush('role-list');
$output = $this->getOutput();
$this->assertStringNotContainsString('cancel other accounts', $output);
$this->drush('role-list', [], ['filter' => 'cancel other accounts']);
$output = $this->getOutput();
$this->assertStringNotContainsString('authenticated', $output);
$this->assertStringNotContainsString('anonymous', $output);
// Create the role foo.
$rid = 'foo';
$this->drush('role-create', [$rid]);
$this->drush('role-list');
$this->assertStringContainsString($rid, $this->getOutput());
// Assert that anon user starts without 'cancel other accounts' perm.
$perm = 'cancel other accounts';
$this->drush('role-list', [], ['format' => 'json']);
$role = $this->getOutputFromJSON($rid);
$this->assertFalse(in_array($perm, $role['perms']));
// Now grant that perm to foo.
$this->drush('role-add-perm', [$rid, 'cancel other accounts']);
$this->drush('role-list', [], ['format' => 'json']);
$role = $this->getOutputFromJSON($rid);
$this->assertTrue(in_array($perm, $role['perms']));
// Now remove the perm from foo.
$this->drush('role-remove-perm', [$rid, 'cancel other accounts']);
$this->drush('role-list', [], ['format' => 'json']);
$role = $this->getOutputFromJSON($rid);
$this->assertFalse(in_array($perm, $role['perms']));
// Delete the foo role
$this->drush('role-delete', [$rid]);
$this->drush('role-list');
$this->assertStringNotContainsString($rid, $this->getOutput());
}
}