You are here

public function AreaTest::testRenderAreaToken in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/AreaTest.php \Drupal\views\Tests\Handler\AreaTest::testRenderAreaToken()

Tests global tokens.

File

core/modules/views/src/Tests/Handler/AreaTest.php, line 195
Contains \Drupal\views\Tests\Handler\AreaTest.

Class

AreaTest
Tests the plugin base of the area handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testRenderAreaToken() {
  $admin_user = $this
    ->drupalCreateUser(array(
    '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.
  $element = $this
    ->xpath('//ul[@class="global-tokens"]');
  $this
    ->assertTrue($element, 'Token list found on the options form.');
  $empty_handler =& $view->empty['test_example'];

  // Test the list of available tokens.
  $available = $empty_handler
    ->getAvailableGlobalTokens();
  foreach (array(
    'site',
    'view',
  ) as $type) {
    $this
      ->assertTrue(!empty($available[$type]) && is_array($available[$type]));

    // Test that each item exists in the list.
    foreach ($available[$type] as $token => $info) {
      $this
        ->assertText("[{$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 = $this->container
    ->get('renderer')
    ->renderRoot($output);
  $expected = \Drupal::token()
    ->replace('[site:name]');
  $this
    ->assertTrue(strpos($output, $expected) !== FALSE);
}