public function FieldCustomTest::testFieldCustomTokens in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/src/Tests/Handler/FieldCustomTest.php \Drupal\views\Tests\Handler\FieldCustomTest::testFieldCustomTokens()
Ensure that custom fields can use tokens.
File
- core/
modules/ views/ src/ Tests/ Handler/ FieldCustomTest.php, line 68 - Contains \Drupal\views\Tests\Handler\FieldCustomTest.
Class
- FieldCustomTest
- Tests the core Drupal\views\Plugin\views\field\Custom handler.
Namespace
Drupal\views\Tests\HandlerCode
public function testFieldCustomTokens() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('fields', [
'age' => [
'id' => 'age',
'exclude' => TRUE,
'table' => 'views_test_data',
'field' => 'age',
],
'name' => [
'id' => 'name',
'table' => 'views_test_data',
'field' => 'name',
'relationship' => 'none',
'alter' => [
'text' => 'Amount of kittens: {{ age }}',
],
],
]);
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$preview = $view
->preview();
$output = $renderer
->renderRoot($preview);
$expected_text = 'Amount of kittens: ' . $view->style_plugin
->getField(0, 'age');
$this
->assertTrue(strpos((string) $output, $expected_text), 'The views token has been successfully replaced.');
}