function AreaTextTokenTest::testAreaTextToken

Same name in other branches
  1. 10 core/modules/views/tests/src/Kernel/Handler/AreaTextTokenTest.php \Drupal\Tests\views\Kernel\Handler\AreaTextTokenTest::testAreaTextToken()

Tests the token into text area plugin within header.

File

core/modules/views/tests/src/Kernel/Handler/AreaTextTokenTest.php, line 43

Class

AreaTextTokenTest
Tests the token in text area handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testAreaTextToken() : void {
    
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container
        ->get('renderer');
    $view = Views::getView('test_view');
    $view->setDisplay();
    // Enable checkbox 'token replacement', add token into href in text header.
    $string = '<a href="[site:url]">Added Site URL token in href</a>';
    $view->displayHandlers
        ->get('default')
        ->overrideOption('header', [
        'area' => [
            'id' => 'area',
            'table' => 'views',
            'field' => 'area',
            'content' => [
                'value' => $string,
            ],
            'tokenize' => TRUE,
        ],
    ]);
    // Execute the view.
    $this->executeView($view);
    $build = $view->display_handler->handlers['header']['area']
        ->render();
    $replaced_token = \Drupal::token()->replace('[site:url]');
    $desired_output = str_replace('[site:url]', $replaced_token, $string);
    $this->assertEquals(check_markup($desired_output), $renderer->renderRoot($build), 'Global token assessed in href');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.