public function PathautoTokenTest::assertTokens in Pathauto 8
Function copied from TokenTestHelper::assertTokens().
1 call to PathautoTokenTest::assertTokens()
- PathautoTokenTest::testPathautoTokens in tests/
src/ Kernel/ PathautoTokenTest.php
File
- tests/
src/ Kernel/ PathautoTokenTest.php, line 84
Class
- PathautoTokenTest
- Tests tokens provided by Pathauto.
Namespace
Drupal\Tests\pathauto\KernelCode
public function assertTokens($type, array $data, array $tokens, array $options = []) {
$input = $this
->mapTokenNames($type, array_keys($tokens));
$bubbleable_metadata = new BubbleableMetadata();
$replacements = \Drupal::token()
->generate($type, $input, $data, $options, $bubbleable_metadata);
foreach ($tokens as $name => $expected) {
$token = $input[$name];
if (!isset($expected)) {
$this
->assertTrue(!isset($values[$token]), t("Token value for @token was not generated.", [
'@type' => $type,
'@token' => $token,
]));
}
elseif (!isset($replacements[$token])) {
$this
->fail(t("Token value for @token was not generated.", [
'@type' => $type,
'@token' => $token,
]));
}
elseif (!empty($options['regex'])) {
$this
->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", [
'@type' => $type,
'@token' => $token,
'@actual' => $replacements[$token],
'@expected' => $expected,
]));
}
else {
$this
->assertSame($expected, $replacements[$token], t("Token value for @token was '@actual', expected value '@expected'.", [
'@type' => $type,
'@token' => $token,
'@actual' => $replacements[$token],
'@expected' => $expected,
]));
}
}
return $replacements;
}