3 namespace Drupal\Tests\views\Functional\Wizard;
6 * Tests the ability of the views wizard to create views without a pager.
10 class PagerTest extends WizardTestBase {
13 * Tests the pager option.
15 public function testPager() {
16 // Create nodes, each with a different creation time so that we have
17 // conditions that are meaningful for the use of a pager.
18 $this->drupalCreateContentType(['type' => 'page']);
19 for ($i = 0; $i < 12; $i++) {
20 $this->drupalCreateNode(['created' => REQUEST_TIME - $i]);
23 // Make a View that uses a pager.
24 $path_with_pager = 'test-view-with-pager';
25 $this->createViewAtPath($path_with_pager, TRUE);
26 $this->drupalGet($path_with_pager);
28 // This technique for finding the existence of a pager
29 // matches that used in Drupal\views_ui\Tests\PreviewTest.php.
30 $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
31 $this->assertTrue(!empty($elements), 'Full pager found.');
33 // Make a View that does not have a pager.
34 $path_with_no_pager = 'test-view-without-pager';
35 $this->createViewAtPath($path_with_no_pager, FALSE);
36 $this->drupalGet($path_with_no_pager);
37 $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
38 $this->assertTrue(empty($elements), 'Full pager not found.');
42 * Create a simple View of nodes at a given path.
45 * The path at which the View should be created.
47 * A boolean for whether the View created should use a pager.
49 protected function createViewAtPath($path, $pager = TRUE) {
51 $view['label'] = $this->randomMachineName(16);
52 $view['id'] = strtolower($this->randomMachineName(16));
53 $view['show[sort]'] = 'node_field_data-created:ASC';
54 $view['page[create]'] = 1;
55 $view['page[title]'] = $this->randomMachineName(16);
56 $view['page[path]'] = $path;
57 $view['page[pager]'] = $pager;
58 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));