function AreaTest::testRenderAreaToken
Same name in other branches
- 9 core/modules/views/tests/src/Functional/Handler/AreaTest.php \Drupal\Tests\views\Functional\Handler\AreaTest::testRenderAreaToken()
- 8.9.x core/modules/views/tests/src/Functional/Handler/AreaTest.php \Drupal\Tests\views\Functional\Handler\AreaTest::testRenderAreaToken()
- 11.x core/modules/views/tests/src/Functional/Handler/AreaTest.php \Drupal\Tests\views\Functional\Handler\AreaTest::testRenderAreaToken()
Tests global tokens.
File
-
core/
modules/ views/ tests/ src/ Functional/ Handler/ AreaTest.php, line 97
Class
- AreaTest
- Tests the plugin base of the area handler.
Namespace
Drupal\Tests\views\Functional\HandlerCode
public function testRenderAreaToken() : void {
$admin_user = $this->drupalCreateUser([
'administer views',
'administer site configuration',
]);
$this->drupalLogin($admin_user);
$view = Views::getView('test_example_area');
$view->initHandlers();
$this->drupalGet('admin/structure/views/nojs/handler/test_example_area/default/empty/test_example');
// Test that the list is token present.
$this->assertSession()
->elementExists('xpath', '//ul[@class="global-tokens"]');
$empty_handler =& $view->empty['test_example'];
// Test the list of available tokens.
$available = $empty_handler->getAvailableGlobalTokens();
foreach ([
'site',
'view',
] as $type) {
$this->assertNotEmpty($available[$type]);
$this->assertIsArray($available[$type]);
// Test that each item exists in the list.
foreach ($available[$type] as $token => $info) {
$this->assertSession()
->pageTextContains("[{$type}:{$token}]");
}
}
// Test the rendered output of a token.
$empty_handler->options['string'] = '[site:name]';
// Test we have the site:name token in the output.
$output = $view->preview();
$output = (string) $this->container
->get('renderer')
->renderRoot($output);
$expected = \Drupal::token()->replace('[site:name]');
$this->assertStringContainsString($expected, $output);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.