You are here

function TokenReplaceTest::testTokenReplacement in Views (for Drupal 7) 8.3

Tests core token replacements generated from a view.

File

lib/Drupal/views/Tests/TokenReplaceTest.php, line 32
Definition of Drupal\views\Tests\TokenReplaceTest.

Class

TokenReplaceTest
Tests core view token replacement.

Namespace

Drupal\views\Tests

Code

function testTokenReplacement() {
  $view = views_get_view('test_tokens');
  $view
    ->setDisplay('page_1');
  $this
    ->executeView($view);
  $expected = array(
    '[view:name]' => 'Test tokens',
    '[view:description]' => 'Test view to token replacement tests.',
    '[view:machine-name]' => 'test_tokens',
    '[view:title]' => 'Test token page',
    '[view:url]' => url('test_tokens', array(
      'absolute' => TRUE,
    )),
    '[view:total-rows]' => (string) $view->total_rows,
    '[view:base-table]' => 'views_test_data',
    '[view:base-field]' => 'id',
    '[view:items-per-page]' => '10',
    '[view:current-page]' => '1',
    '[view:page-count]' => '1',
  );
  foreach ($expected as $token => $expected_output) {
    $output = token_replace($token, array(
      'view' => $view,
    ));
    $this
      ->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', array(
      '%token' => $token,
    )));
  }
}