Unverified Commit ece5db40 authored by larowlan's avatar larowlan
Browse files

Issue #3063179 by Lendude, shubham.prakash, daffie: Add test coverage for...

Issue #3063179 by Lendude, shubham.prakash, daffie: Add test coverage for Drupal\views\Plugin\views\field\Counter::getValue()
parent f944ef3f
......@@ -10,9 +10,6 @@
* Tests the Drupal\views\Plugin\views\field\Counter handler.
*
* @group views
*
* @todo Write tests for pager in
* https://www.drupal.org/project/drupal/issues/3063179
*/
class FieldCounterTest extends ViewsKernelTestBase {
......@@ -88,4 +85,93 @@ public function testSimple() {
$this->assertEqual($counter, (string) $expected_number, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter]));
}
/**
* Tests the counter field when using a pager.
*/
public function testPager() {
$view = Views::getView('test_view');
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('fields', [
'counter' => [
'id' => 'counter',
'table' => 'views',
'field' => 'counter',
'relationship' => 'none',
],
'name' => [
'id' => 'name',
'table' => 'views_test_data',
'field' => 'name',
'relationship' => 'none',
],
]);
$view->displayHandlers->get('default')->setOption('pager', [
'type' => 'mini',
'options' => ['items_per_page' => 1],
]);
$view->preview();
$counter = $view->style_plugin->getField(0, 'counter');
$this->assertEquals('1', $counter);
$view->destroy();
// Go the the second page.
$view->setCurrentPage(1);
$view->preview();
$counter = $view->style_plugin->getField(0, 'counter');
$this->assertEquals('2', $counter);
$view->destroy();
// Go the the third page.
$view->setCurrentPage(2);
$view->preview();
$counter = $view->style_plugin->getField(0, 'counter');
$this->assertEquals('3', $counter);
$view->destroy();
// Test using the counter start option.
$counter_start = 1000000;
$view->setDisplay();
$view->displayHandlers->get('default')->overrideOption('fields', [
'counter' => [
'id' => 'counter',
'table' => 'views',
'field' => 'counter',
'relationship' => 'none',
'counter_start' => $counter_start,
],
'name' => [
'id' => 'name',
'table' => 'views_test_data',
'field' => 'name',
'relationship' => 'none',
],
]);
$view->preview();
$counter = $view->style_plugin->getField(0, 'counter');
$this->assertEquals($counter_start, $counter);
$view->destroy();
// Go the the second page.
$view->setCurrentPage(1);
$view->preview();
$counter = $view->style_plugin->getField(0, 'counter');
$this->assertEquals($counter_start + 1, $counter);
$view->destroy();
// Go the the third page.
$view->setCurrentPage(2);
$view->preview();
$counter = $view->style_plugin->getField(0, 'counter');
$this->assertEquals($counter_start + 2, $counter);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment