-
Notifications
You must be signed in to change notification settings - Fork 126
/
UserRoleRemoveTest.php
110 lines (93 loc) · 2.44 KB
/
UserRoleRemoveTest.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @file
* Contains \Drupal\Tests\rules\Integration\Action\UserRoleRemoveTest.
*/
namespace Drupal\Tests\rules\Integration\Action;
use Drupal\Tests\rules\Integration\RulesEntityIntegrationTestBase;
use Drupal\Tests\rules\Integration\RulesUserIntegrationTestTrait;
/**
* @coversDefaultClass \Drupal\rules\Plugin\Action\UserRoleRemove
* @group rules_actions
*/
class UserRoleRemoveTest extends RulesEntityIntegrationTestBase
{
use RulesUserIntegrationTestTrait;
/**
* The action that is being tested.
*
* @var \Drupal\rules\Core\RulesActionInterface
*/
protected $action;
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->enableModule('user');
$this->action = $this->actionManager->createInstance('rules_user_role_remove');
}
/**
* Tests the summary.
*
* @covers ::summary
*/
public function testSummary()
{
$this->assertEquals('Remove roles of particular users', $this->action->summary());
}
/**
* Tests removing existing role from user.
*
* @covers ::execute
* @dataProvider rolesProvider
* @param $account
* @param $user
*/
public function testRemoveExistingRole($account, $user)
{
// Set-up a mock user with role 'editor'.
$editor = $this->getMockedUserRole('editor');
// Test removing one role.
$this->action
->setContextValue('user', $account)
->setContextValue('roles', [$editor])
->execute();
$this->assertEquals($this->action->autoSaveContext(), $user, 'Action returns nothing for auto saving since the user has been saved already.');
}
/**
* @return array
*/
public function rolesProvider()
{
$account1 = $this->getMockedUser();
$account1->expects($this->once())
->method('hasRole')
->with(
$this->equalTo('editor')
)
->will($this->returnValue(TRUE));
$account1->expects($this->once())
->method('removeRole')
->with(
$this->equalTo('editor')
);
$account2 = $this->getMockedUser();
$account2->expects($this->once())
->method('hasRole')
->with(
$this->equalTo('editor')
)
->will($this->returnValue(FALSE));
$account2->expects($this->never())
->method('removeRole')
->with(
$this->equalTo('editor')
);
return array(
'removing of one role' => array($account1, ['user']),
'removing of none role' => array($account2, []),
);
}
}