Tests core token replacements generated from a view.
function testTokenReplacement() {
$token_handler = \Drupal::token();
$view = views_get_view('test_tokens');
$view
->setDisplay('page_1');
$this
->executeView($view);
$expected = array(
'[view:label]' => 'Test tokens',
'[view:description]' => 'Test view to token replacement tests.',
'[view:id]' => '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_handler
->replace($token, array(
'view' => $view,
));
$this
->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', array(
'%token' => $token,
)));
}
}