PagerTest.php in Drupal 10
File
core/modules/views/tests/src/Functional/Wizard/PagerTest.php
View source
<?php
namespace Drupal\Tests\views\Functional\Wizard;
class PagerTest extends WizardTestBase {
protected $defaultTheme = 'stark';
public function testPager() {
$this
->drupalCreateContentType([
'type' => 'page',
]);
for ($i = 0; $i < 12; $i++) {
$this
->drupalCreateNode([
'created' => REQUEST_TIME - $i,
]);
}
$path_with_pager = 'test-view-with-pager';
$this
->createViewAtPath($path_with_pager, TRUE);
$this
->drupalGet($path_with_pager);
$elements = $this
->xpath('//ul[contains(@class, :class)]/li', [
':class' => 'pager__items',
]);
$this
->assertNotEmpty($elements, 'Full pager found.');
$path_with_no_pager = 'test-view-without-pager';
$this
->createViewAtPath($path_with_no_pager, FALSE);
$this
->drupalGet($path_with_no_pager);
$elements = $this
->xpath('//ul[contains(@class, :class)]/li', [
':class' => 'pager__items',
]);
$this
->assertEmpty($elements, 'Full pager not found.');
}
protected function createViewAtPath($path, $pager = TRUE) {
$view = [];
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['show[sort]'] = 'node_field_data-created:ASC';
$view['page[create]'] = 1;
$view['page[title]'] = $this
->randomMachineName(16);
$view['page[path]'] = $path;
$view['page[pager]'] = $pager;
$this
->drupalGet('admin/structure/views/add');
$this
->submitForm($view, 'Save and edit');
}
}
Classes
Name |
Description |
PagerTest |
Tests the ability of the views wizard to create views without a pager. |