You are here

public function CasAttributesSubscriberTest::tokenReplace in CAS Attributes 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/Subscriber/CasAttributesSubscriberTest.php \Drupal\Tests\cas_attributes\Unit\Subscriber\CasAttributesSubscriberTest::tokenReplace()

Callback function for the mocked token replacement service.

Parameters

string $input: The string containing a token.

array $data: Data for the token replacement.

Return value

string The token replacement.

File

tests/src/Unit/Subscriber/CasAttributesSubscriberTest.php, line 162

Class

CasAttributesSubscriberTest
CasAttributesSubscriber unit tests.

Namespace

Drupal\Tests\cas_attributes\Unit\Subscriber

Code

public function tokenReplace($input, array $data) {

  // We don't particularly care about token replacement logic in this test,
  // only that it happens we want it to. So for the purposes of this test,
  // we use very simple fake token syntax.
  $supplied_attribute = preg_replace('/\\[|\\]/', '', $input);
  if (isset($data['cas_attributes']) && is_array($data['cas_attributes'])) {
    if (isset($data['cas_attributes'][$supplied_attribute])) {
      return $data['cas_attributes'][$supplied_attribute][0];
    }
  }

  // No match, just return the input.
  return $input;
}