Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / views / tests / src / Functional / Wizard / PagerTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Wizard;
4
5 /**
6  * Tests the ability of the views wizard to create views without a pager.
7  *
8  * @group views
9  */
10 class PagerTest extends WizardTestBase {
11
12   /**
13    * Tests the pager option.
14    */
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]);
21     }
22
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);
27
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.');
32
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.');
39   }
40
41   /**
42    * Create a simple View of nodes at a given path.
43    *
44    * @param string $path
45    *   The path at which the View should be created.
46    * @param bool $pager
47    *   A boolean for whether the View created should use a pager.
48    */
49   protected function createViewAtPath($path, $pager = TRUE) {
50     $view = [];
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'));
59   }
60
61 }