class RemoveRoleUserTest

Tests the role remove plugin.

Hierarchy

Expanded class hierarchy of RemoveRoleUserTest

See also

\Drupal\user\Plugin\Action\RemoveRoleUser

File

drupal/core/modules/user/tests/Drupal/user/Tests/Plugin/Action/RemoveRoleUserTest.php, line 18
Contains \Drupal\user\Tests\Plugin\Action\RemoveRoleUserTest.

Namespace

Drupal\user\Tests\Plugin\Action
View source
class RemoveRoleUserTest extends UnitTestCase {

  /**
   * The mocked account.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $account;
  public static function getInfo() {
    return array(
      'name' => 'Remove user plugin',
      'description' => 'Tests the role remove plugin',
      'group' => 'User',
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->account = $this
      ->getMockBuilder('Drupal\\user\\Plugin\\Core\\Entity\\User')
      ->disableOriginalConstructor()
      ->getMock();
  }

  /**
   * Tests the execute method on a user with a role.
   */
  public function testExecuteRemoveExistingRole() {
    $this->account
      ->expects($this
      ->once())
      ->method('removeRole');
    $this->account
      ->expects($this
      ->any())
      ->method('hasRole')
      ->with($this
      ->equalTo('test_role_1'))
      ->will($this
      ->returnValue(TRUE));
    $config = array(
      'rid' => 'test_role_1',
    );
    $remove_role_plugin = new RemoveRoleUser($config, 'user_remove_role_action', array(
      'type' => 'user',
    ));
    $remove_role_plugin
      ->execute($this->account);
  }

  /**
   * Tests the execute method on a user without a specific role.
   */
  public function testExecuteRemoveNonExistingRole() {
    $this->account
      ->expects($this
      ->never())
      ->method('removeRole');
    $this->account
      ->expects($this
      ->any())
      ->method('hasRole')
      ->with($this
      ->equalTo('test_role_1'))
      ->will($this
      ->returnValue(FALSE));
    $config = array(
      'rid' => 'test_role_1',
    );
    $remove_role_plugin = new RemoveRoleUser($config, 'user_remove_role_action', array(
      'type' => 'user',
    ));
    $remove_role_plugin
      ->execute($this->account);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RemoveRoleUserTest::$account protected property The mocked account.
RemoveRoleUserTest::getInfo public static function This method exists to support the simpletest UI runner. Overrides UnitTestCase::getInfo
RemoveRoleUserTest::setUp protected function
RemoveRoleUserTest::testExecuteRemoveExistingRole public function Tests the execute method on a user with a role.
RemoveRoleUserTest::testExecuteRemoveNonExistingRole public function Tests the execute method on a user without a specific role.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::randomName public static function Generates a random string containing letters and numbers.