You are here

public function RoleExpireApiTest::testRoleExpireGetExpired 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::testRoleExpireGetExpired()

Tests getExpired method.

File

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

Class

RoleExpireApiTest
Tests that the Role expire API works.

Namespace

Drupal\Tests\role_expire\Functional

Code

public function testRoleExpireGetExpired() {
  $account = $this
    ->createUser([
    'administer role expire',
  ]);
  $this
    ->drupalLogin($account);
  $account_id = $account
    ->id();
  $rid_1 = 'role_test_1';
  $rid_2 = 'role_test_2';
  $this
    ->createRole([], $rid_1, 'Role test 1');
  $this
    ->createRole([], $rid_2, 'Role test 2');
  $account
    ->addRole($rid_1);
  $account
    ->addRole($rid_2);
  $expiration_1 = strtotime('+1 day');
  $expiration_2 = strtotime('+2 days');
  $this->apiService
    ->writeRecord($account_id, $rid_1, $expiration_1);
  $this->apiService
    ->writeRecord($account_id, $rid_2, $expiration_2);
  $fake_current_time = strtotime('+1 month');
  $results = $this->apiService
    ->getExpired($fake_current_time);
  $actual = count($results) == 2;
  $this
    ->assertTrue($actual);
  $results = $this->apiService
    ->getExpired();
  $actual = count($results) == 0;
  $this
    ->assertTrue($actual);
}