You are here

protected function SectionTokenTest::assertTokens in Workbench Access 8

Helper function to assert tokens.

Parameters

string $type: The token type.

array $data: The input data.

array $tokens: The tokens.

\Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata: The cache metadata.

Return value

array The array of replacements.

2 calls to SectionTokenTest::assertTokens()
SectionTokenTest::testNodeSectionTokens in tests/src/Kernel/SectionTokenTest.php
Tests the node section tokens.
SectionTokenTest::testUserSectionTokens in tests/src/Kernel/SectionTokenTest.php
Tests the user section tokens.

File

tests/src/Kernel/SectionTokenTest.php, line 265

Class

SectionTokenTest
Tests workbench_access integration with tokens.

Namespace

Drupal\Tests\workbench_access\Kernel

Code

protected function assertTokens($type, array $data, array $tokens, BubbleableMetadata $bubbleable_metadata) {
  $input = array_reduce(array_keys($tokens), function ($carry, $token) use ($type) {
    $carry[$token] = "[{$type}:{$token}]";
    return $carry;
  }, []);
  $replacements = \Drupal::token()
    ->generate($type, $input, $data, [], $bubbleable_metadata);
  foreach ($tokens as $name => $expected) {
    $token = $input[$name];
    $this
      ->assertEquals($replacements[$token], $expected);
  }
  return $replacements;
}