public function TokenReplaceTest::testTokenReplacementWithMiniPager in Drupal 8
Same name and namespace in other branches
- 9 core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::testTokenReplacementWithMiniPager()
Tests core token replacements generated from a view.
File
- core/
modules/ views/ tests/ src/ Kernel/ TokenReplaceTest.php, line 80
Class
- TokenReplaceTest
- Tests core view token replacement.
Namespace
Drupal\Tests\views\KernelCode
public function testTokenReplacementWithMiniPager() {
$token_handler = \Drupal::token();
$view = Views::getView('test_tokens');
$view
->setDisplay('page_3');
$this
->executeView($view);
$this
->assertSame(TRUE, $view->get_total_rows, 'The query was set to calculate the total number of rows.');
$expected = [
'[view:label]' => 'Test tokens',
'[view:description]' => 'Test view to token replacement tests.',
'[view:id]' => 'test_tokens',
'[view:title]' => 'Test token page with minipager',
'[view:url]' => $view
->getUrl(NULL, 'page_3')
->setAbsolute(TRUE)
->toString(),
'[view:total-rows]' => '5',
'[view:base-table]' => 'views_test_data',
'[view:base-field]' => 'id',
'[view:items-per-page]' => '2',
'[view:current-page]' => '1',
'[view:page-count]' => '3',
];
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($view->storage);
foreach ($expected as $token => $expected_output) {
$bubbleable_metadata = new BubbleableMetadata();
$output = $token_handler
->replace($token, [
'view' => $view,
], [], $bubbleable_metadata);
$this
->assertSame($expected_output, $output, sprintf('Token %s replaced correctly.', $token));
$this
->assertEquals($base_bubbleable_metadata, $bubbleable_metadata);
}
}