You are here

public function RoleExpireApiTest::testRoleExpireSetGet in Role Expire 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/RoleExpireApiTest.php \Drupal\Tests\role_expire\Functional\RoleExpireApiTest::testRoleExpireSetGet()

Tests setter and getter for expiration of a role.

File

tests/src/Functional/RoleExpireApiTest.php, line 57

Class

RoleExpireApiTest
Tests that the Role expire API works.

Namespace

Drupal\Tests\role_expire\Functional

Code

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

  // New users have no expiration time.
  $saved_expiration = $this->apiService
    ->getUserRoleExpiryTime($account_id, 'administrator');
  $this
    ->assertEquals('', $saved_expiration);

  // Check expiration date saving process.
  $expiration = strtotime('+1 year');
  $saved_expiration = $this
    ->setAndGetExpiration($account_id, 'administrator', $expiration);
  $this
    ->assertEquals($expiration, $saved_expiration);
  $expiration = strtotime('+1 month');
  $saved_expiration = $this
    ->setAndGetExpiration($account_id, 'administrator', $expiration);
  $this
    ->assertEquals($expiration, $saved_expiration);
  $expiration = strtotime('12 hours');
  $saved_expiration = $this
    ->setAndGetExpiration($account_id, 'administrator', $expiration);
  $this
    ->assertEquals($expiration, $saved_expiration);
}