public function CounterTest::testCounterRandomStart in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php \Drupal\Tests\views\Unit\Plugin\field\CounterTest::testCounterRandomStart()
Tests a counter with a random start.
@dataProvider providerRowIndexes
Parameters
int $i: The row index to test.
File
- core/
modules/ views/ tests/ src/ Unit/ Plugin/ field/ CounterTest.php, line 136
Class
- CounterTest
- @coversDefaultClass \Drupal\views\Plugin\views\field\Counter @group views
Namespace
Drupal\Tests\views\Unit\Plugin\fieldCode
public function testCounterRandomStart($i) {
// Setup a counter field with a random start.
$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 = $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');
}