public function PagerTest::testStorePagerSettings in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testStorePagerSettings()
- 10 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testStorePagerSettings()
Pagers was sometimes not stored.
See also
https://www.drupal.org/node/652712
File
- core/
modules/ views/ tests/ src/ Functional/ Plugin/ PagerTest.php, line 50
Class
- PagerTest
- Tests the pluggable pager system.
Namespace
Drupal\Tests\views\Functional\PluginCode
public function testStorePagerSettings() {
// Show the default display so the override selection is shown.
\Drupal::configFactory()
->getEditable('views.settings')
->set('ui.show.default_display', TRUE)
->save();
$admin_user = $this
->drupalCreateUser([
'administer views',
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
// Test behavior described in
// https://www.drupal.org/node/652712#comment-2354918.
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$edit = [
'pager[type]' => 'some',
];
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/pager');
$this
->submitForm($edit, 'Apply');
$items_per_page = $this
->assertSession()
->fieldExists("pager_options[items_per_page]");
$this
->assertSession()
->fieldValueEquals("pager_options[items_per_page]", 10);
$this
->assertSame('number', $items_per_page
->getAttribute('type'));
$this
->assertEquals(0, $items_per_page
->getAttribute('min'));
$offset = $this
->assertSession()
->fieldExists("pager_options[offset]");
$this
->assertSession()
->fieldValueEquals("pager_options[offset]", 0);
$this
->assertSame('number', $offset
->getAttribute('type'));
$this
->assertEquals(0, $offset
->getAttribute('min'));
$edit = [
'pager[type]' => 'none',
];
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/pager');
$this
->submitForm($edit, 'Apply');
$offset = $this
->assertSession()
->fieldExists("pager_options[offset]");
$this
->assertSession()
->fieldValueEquals("pager_options[offset]", 0);
$this
->assertSame('number', $offset
->getAttribute('type'));
$this
->assertEquals(0, $offset
->getAttribute('min'));
$edit = [
'pager[type]' => 'full',
];
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/pager');
$this
->submitForm($edit, 'Apply');
$items_per_page = $this
->assertSession()
->fieldExists("pager_options[items_per_page]");
$this
->assertSession()
->fieldValueEquals("pager_options[items_per_page]", 10);
$this
->assertSame('number', $items_per_page
->getAttribute('type'));
$this
->assertEquals(0, $items_per_page
->getAttribute('min'));
$offset = $this
->assertSession()
->fieldExists("pager_options[offset]");
$this
->assertSession()
->fieldValueEquals("pager_options[offset]", 0);
$this
->assertSame('number', $offset
->getAttribute('type'));
$this
->assertEquals(0, $offset
->getAttribute('min'));
$id = $this
->assertSession()
->fieldExists("pager_options[id]");
$this
->assertSession()
->fieldValueEquals("pager_options[id]", 0);
$this
->assertSame('number', $id
->getAttribute('type'));
$this
->assertEquals(0, $id
->getAttribute('min'));
$total_pages = $this
->assertSession()
->fieldExists("pager_options[total_pages]");
$this
->assertSession()
->fieldValueEquals("pager_options[total_pages]", '');
$this
->assertSame('number', $total_pages
->getAttribute('type'));
$this
->assertEquals(0, $total_pages
->getAttribute('min'));
$quantity = $this
->assertSession()
->fieldExists("pager_options[quantity]");
$this
->assertSession()
->fieldValueEquals("pager_options[quantity]", 9);
$this
->assertSame('number', $quantity
->getAttribute('type'));
$this
->assertEquals(0, $quantity
->getAttribute('min'));
$edit = [
'pager_options[items_per_page]' => 20,
];
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/pager_options');
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->pageTextContains('20 items');
// Change type and check whether the type is new type is stored.
$edit = [
'pager[type]' => 'mini',
];
$this
->drupalGet('admin/structure/views/nojs/display/test_view/default/pager');
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$this
->assertSession()
->pageTextContains('Mini');
// Test behavior described in
// https://www.drupal.org/node/652712#comment-2354400.
$view = Views::getView('test_store_pager_settings');
// Make it editable in the admin interface.
$view
->save();
$this
->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
$edit = [
'pager[type]' => 'full',
];
$this
->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/default/pager');
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
$this
->assertSession()
->pageTextContains('Full');
$edit = [
'pager_options[items_per_page]' => 20,
];
$this
->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options');
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->pageTextContains('20 items');
// add new display and test the settings again, by override it.
$edit = [];
// Add a display and override the pager settings.
$this
->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
$this
->submitForm($edit, 'Add Page');
$edit = [
'override[dropdown]' => 'page_1',
];
$this
->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager');
$this
->submitForm($edit, 'Apply');
$edit = [
'pager[type]' => 'mini',
];
$this
->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager');
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/view/test_store_pager_settings/edit/page_1');
$this
->assertSession()
->pageTextContains('Mini');
$edit = [
'pager_options[items_per_page]' => 10,
];
$this
->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options');
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->pageTextContains('10 items');
$this
->drupalGet('admin/structure/views/view/test_store_pager_settings/edit/page_1');
$this
->assertSession()
->pageTextContains('20 items');
// Test that the override element is only displayed on pager plugin selection form.
$this
->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager');
$this
->assertSession()
->fieldValueEquals('override[dropdown]', 'page_1');
$this
->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager_options');
$this
->assertSession()
->fieldNotExists('override[dropdown]');
$items_per_page = $this
->assertSession()
->fieldExists("pager_options[items_per_page]");
$this
->assertSession()
->fieldValueEquals("pager_options[items_per_page]", 20);
$this
->assertSame('number', $items_per_page
->getAttribute('type'));
$this
->assertEquals(0, $items_per_page
->getAttribute('min'));
$offset = $this
->assertSession()
->fieldExists("pager_options[offset]");
$this
->assertSession()
->fieldValueEquals("pager_options[offset]", 0);
$this
->assertSame('number', $offset
->getAttribute('type'));
$this
->assertEquals(0, $offset
->getAttribute('min'));
$id = $this
->assertSession()
->fieldExists("pager_options[id]");
$this
->assertSession()
->fieldValueEquals("pager_options[id]", 0);
$this
->assertSame('number', $id
->getAttribute('type'));
$this
->assertEquals(0, $id
->getAttribute('min'));
$total_pages = $this
->assertSession()
->fieldExists("pager_options[total_pages]");
$this
->assertSession()
->fieldValueEquals("pager_options[total_pages]", '');
$this
->assertSame('number', $total_pages
->getAttribute('type'));
$this
->assertEquals(0, $total_pages
->getAttribute('min'));
}