You are here

public function UiRoleExpireTest::testRoleExpireEditUserFieldsAction in Role Expire 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/UiRoleExpireTest.php \Drupal\Tests\role_expire\Functional\UiRoleExpireTest::testRoleExpireEditUserFieldsAction()

Tests that we can add a role with default expiration and assign it to a new user.

File

tests/src/Functional/UiRoleExpireTest.php, line 161

Class

UiRoleExpireTest
Tests that the Role expire interface is available.

Namespace

Drupal\Tests\role_expire\Functional

Code

public function testRoleExpireEditUserFieldsAction() {
  $account = $this
    ->drupalCreateUser([
    'administer permissions',
    'administer role expire',
  ]);
  $this
    ->drupalLogin($account);

  // Create a role with an expiration date.
  $value_to_store = '2 days';
  $this
    ->createRoleWithOptionalExpirationUI('test role', 'test_role', $value_to_store);

  // Assign the role to that user.
  $this
    ->drupalGet('user/' . $account
    ->id() . '/edit');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->getSession()
    ->getPage()
    ->checkField('edit-roles-test-role');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Save');

  // Check that the user has the role and it has the default expiration date.
  $expected_date = date('Y-m-d', strtotime('2 days'));
  $this
    ->drupalGet('user/' . $account
    ->id() . '/edit');
  $stored_value = $this
    ->getSession()
    ->getPage()
    ->findField('edit-role-expire-test-role')
    ->getValue();
  $stored_date = substr($stored_value, 0, 10);
  $this
    ->assertEquals($expected_date, $stored_date);

  // Test that we can set expiration for user roles.
  $this
    ->assertSession()
    ->pageTextContains('role expiration date/time');
}