You are here

AssertRoleExpireTrait.php in Role Expire 2.x

Same filename and directory in other branches
  1. 8 tests/src/Traits/AssertRoleExpireTrait.php

File

tests/src/Traits/AssertRoleExpireTrait.php
View source
<?php

namespace Drupal\Tests\role_expire\Traits;


/**
 * Adds helper functions.
 */
trait AssertRoleExpireTrait {

  /**
   * Writes and then gets role expiration for a given user and role ID.
   *
   * @param $account_id
   *   User ID.
   * @param string $rid
   *   Role ID.
   * @param int $expiration
   *   The expiration timestamp.
   * @return array
   *   Array with the expiration time.
   */
  protected function setAndGetExpiration($account_id, $rid, $expiration) {
    $this->apiService
      ->writeRecord($account_id, $rid, $expiration);
    $saved_expiration = $this->apiService
      ->getUserRoleExpiryTime($account_id, $rid);
    return $saved_expiration;
  }

  /**
   * Creates a role with optional expiration via UI.
   *
   * @param $rid
   *   Role ID.
   * @param $roleName
   *   Role name.
   * @param string $expiration
   *   The strtotime-compatible duration string.
   */
  protected function createRoleWithOptionalExpirationUI($roleName, $rid, $expiration = '') {
    $this
      ->drupalGet('admin/people/roles/add');
    $this
      ->getSession()
      ->getPage()
      ->fillField('Role name', $roleName);
    $this
      ->getSession()
      ->getPage()
      ->fillField('Machine-readable name', $rid);
    if (!empty($expiration)) {
      $this
        ->getSession()
        ->getPage()
        ->fillField('Default duration for the role', $expiration);
    }
    $this
      ->getSession()
      ->getPage()
      ->pressButton('Save');
    $this
      ->assertSession()
      ->statusCodeEquals(200);
  }

}

Traits

Namesort descending Description
AssertRoleExpireTrait Adds helper functions.