DomainTokenTest.php in Domain Access 8
File
domain/tests/src/Functional/DomainTokenTest.php
View source
<?php
namespace Drupal\Tests\domain\Functional;
use Drupal\Core\Session\AccountInterface;
class DomainTokenTest extends DomainTestBase {
public static $modules = [
'domain',
'block',
];
public function testDomainTokens() {
$this
->domainTableIsEmpty();
$this
->domainCreateTestDomains(4);
$this
->drupalPlaceBlock('domain_token_block');
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
'view domain information',
]);
foreach (\Drupal::entityTypeManager()
->getStorage('domain')
->loadMultiple() as $domain) {
$this
->drupalGet($domain
->getPath());
$this
->assertRaw($domain
->label(), 'Loaded the proper domain.');
$this
->assertRaw('<th>Token</th>', 'Token values printed.');
foreach ($this
->tokenList() as $token => $callback) {
$this
->assertRaw("<td>{$token}</td>", "{$token} found correctly.");
$value = $domain
->{$callback}();
if ($token == '[domain:url]') {
$value = str_replace('user', '', $value);
if (substr($value, -1) != '/') {
$value .= '/';
}
}
$this
->assertRaw('<td>' . $value . '</td>', 'Value set correctly to ' . $value);
}
}
}
private function tokenList() {
$tokens = [];
foreach (\Drupal::service('domain.token')
->getCallbacks() as $key => $callback) {
$name = "[domain:{$key}]";
$tokens[$name] = $callback;
}
return $tokens;
}
}