function CounterTest::testCounterSecondPage

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php \Drupal\Tests\views\Unit\Plugin\field\CounterTest::testCounterSecondPage()
  2. 8.9.x core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php \Drupal\Tests\views\Unit\Plugin\field\CounterTest::testCounterSecondPage()
  3. 10 core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php \Drupal\Tests\views\Unit\Plugin\field\CounterTest::testCounterSecondPage()

Tests a counter field on the second page.

@dataProvider providerRowIndexes

Parameters

int $i: The row index to test.

File

core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php, line 196

Class

CounterTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21field%21Counter.php/class/Counter/11.x" title="Field handler to show a counter of the current row." class="local">\Drupal\views\Plugin\views\field\Counter</a> @group views

Namespace

Drupal\Tests\views\Unit\Plugin\field

Code

public function testCounterSecondPage($i) : void {
    $offset = 3;
    // Setup a pager on the second page.
    $this->pager
        ->setOffset($offset);
    $items_per_page = 5;
    $this->pager
        ->setItemsPerPage($items_per_page);
    $current_page = 1;
    $this->pager
        ->setCurrentPage($current_page);
    $rand_start = rand(5, 10);
    $counter_handler = new Counter([], 'counter', $this->definition);
    $options = [
        'counter_start' => $rand_start,
    ];
    $counter_handler->init($this->view, $this->display, $options);
    $this->view->row_index = $i;
    $expected = $items_per_page + $offset + $rand_start + $i;
    $counter = $counter_handler->getValue($this->testData[$i]);
    $this->assertEquals($expected, $counter, 'The expected number matches with the counter number');
    $counter = $this->renderCounter($counter_handler, $this->testData[$i]);
    $this->assertEquals($expected, $counter, 'The expected number matches with the rendered number');
}

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