function TokenReplaceTest::testTokenReplacementWithSpecificNumberOfItems

Same name in other branches
  1. 11.x core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::testTokenReplacementWithSpecificNumberOfItems()

Tests token replacement of [view:total-rows] when pager is disabled.

It calls "Some" views pager plugin.

File

core/modules/views/tests/src/Kernel/TokenReplaceTest.php, line 119

Class

TokenReplaceTest
Tests core view token replacement.

Namespace

Drupal\Tests\views\Kernel

Code

public function testTokenReplacementWithSpecificNumberOfItems() : void {
    $token_handler = \Drupal::token();
    $view = Views::getView('test_tokens');
    $view->setDisplay('page_4');
    $this->executeView($view);
    $total_rows_in_table = ViewTestData::dataSet();
    $this->assertTrue($view->get_total_rows, 'The query was set to calculate the total number of rows.');
    $this->assertGreaterThan(3, count($total_rows_in_table));
    $expected = [
        '[view:label]' => 'Test tokens',
        '[view:id]' => 'test_tokens',
        '[view:url]' => $view->getUrl(NULL, 'page_4')
            ->setAbsolute(TRUE)
            ->toString(),
        '[view:total-rows]' => '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);
    }
}

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