3 namespace Drupal\Tests\user\Unit\Plugin\Action;
5 use Drupal\user\Plugin\Action\RemoveRoleUser;
8 * @coversDefaultClass \Drupal\user\Plugin\Action\RemoveRoleUser
11 class RemoveRoleUserTest extends RoleUserTestBase {
14 * Tests the execute method on a user with a role.
16 public function testExecuteRemoveExistingRole() {
17 $this->account->expects($this->once())
18 ->method('removeRole');
20 $this->account->expects($this->any())
22 ->with($this->equalTo('test_role_1'))
23 ->will($this->returnValue(TRUE));
25 $config = ['rid' => 'test_role_1'];
26 $remove_role_plugin = new RemoveRoleUser($config, 'user_remove_role_action', ['type' => 'user'], $this->userRoleEntityType);
28 $remove_role_plugin->execute($this->account);
32 * Tests the execute method on a user without a specific role.
34 public function testExecuteRemoveNonExistingRole() {
35 $this->account->expects($this->never())
36 ->method('removeRole');
38 $this->account->expects($this->any())
40 ->with($this->equalTo('test_role_1'))
41 ->will($this->returnValue(FALSE));
43 $config = ['rid' => 'test_role_1'];
44 $remove_role_plugin = new RemoveRoleUser($config, 'user_remove_role_action', ['type' => 'user'], $this->userRoleEntityType);
46 $remove_role_plugin->execute($this->account);