Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Functional / Plugin / StyleSummaryTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Plugin;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\Tests\views\Functional\ViewTestBase;
7
8 /**
9  * Tests the summary style plugin.
10  *
11  * @group views
12  */
13 class StyleSummaryTest extends ViewTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['entity_test', 'views_ui'];
19
20   /**
21    * {@inheritdoc}
22    */
23   public static $testViews = ['test_summary'];
24
25   /**
26    * @var \Drupal\entity_test\Entity\EntityTest[]
27    */
28   protected $entities = [];
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUp($import_test_views = TRUE) {
34     parent::setUp($import_test_views);
35
36     // Create 5 entities per bundle, to allow a summary overview per bundle.
37     for ($i = 0; $i < 5; $i++) {
38       for ($j = 0; $j < 5; $j++) {
39         $this->entities[] = $entity = EntityTest::create([
40           'name' => 'Entity ' . ($i * 5 + $j),
41           'type' => 'type' . $i,
42         ]);
43         $entity->save();
44       }
45     }
46
47     $views_user = $this->drupalCreateUser(['administer views']);
48     $this->drupalLogin($views_user);
49   }
50
51   /**
52    * Tests a summary view.
53    */
54   public function testSummaryView() {
55     $this->drupalGet('test-summary');
56
57     // Ensure styles are properly added for summary views.
58     $this->assertRaw('stable/css/views/views.module.css');
59
60     $summary_list = $this->cssSelect('ul.views-summary li');
61     $this->assertEqual(4, count($summary_list));
62
63     foreach ($summary_list as $summary_list_item) {
64       $this->assertEqual('(5)', trim(explode(' ', $summary_list_item->getText())[1]));
65     }
66
67     $summary_links = $this->cssSelect('ul.views-summary a');
68     $this->assertEqual(4, count($summary_links));
69     foreach ($summary_links as $index => $summary_link) {
70       $this->assertEqual('type' . $index, trim($summary_link->getText()));
71     }
72
73     $this->clickLink('type1');
74     $entries = $this->cssSelect('div.view-content div.views-row');
75     $this->assertEqual(2, count($entries));
76
77     // Add a base path to the summary settings.
78     $edit = [
79       'options[summary][options][default_summary][base_path]' => 'test-summary',
80     ];
81     $this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
82     $this->drupalPostForm(NULL, [], t('Save'));
83
84     // Test that the links still work.
85     $this->drupalGet('test-summary');
86     $this->clickLink('type1');
87     $entries = $this->cssSelect('div.view-content div.views-row');
88     $this->assertEqual(2, count($entries));
89
90     // Change the summary display to an unformatted list displaying 3 items.
91     $edit = [
92       'options[summary][format]' => 'unformatted_summary',
93       'options[summary][options][unformatted_summary][override]' => '1',
94       'options[summary][options][unformatted_summary][items_per_page]' => '3',
95     ];
96     $this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
97     $this->drupalPostForm(NULL, [], t('Save'));
98
99     $this->drupalGet('admin/structure/views/nojs/handler/test_summary/page_1/argument/type');
100     $this->drupalGet('test-summary');
101
102     $summary_list = $this->cssSelect('.views-summary-unformatted');
103     $this->assertEqual(3, count($summary_list));
104
105     foreach ($summary_list as $summary_list_item) {
106       $this->assertEqual('(5)', trim(explode(' ', $summary_list_item->getText())[1]));
107     }
108
109     $summary_links = $this->cssSelect('.views-summary-unformatted a');
110     $this->assertEqual(3, count($summary_links));
111     foreach ($summary_links as $index => $summary_link) {
112       $this->assertEqual('type' . $index, trim($summary_link->getText()));
113     }
114
115     $this->clickLink('type1');
116     $entries = $this->cssSelect('div.view-content div.views-row');
117     $this->assertEqual(2, count($entries));
118
119     // Add a base path to the summary settings.
120     $edit = [
121       'options[summary][options][unformatted_summary][base_path]' => 'test-summary',
122     ];
123     $this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
124     $this->drupalPostForm(NULL, [], t('Save'));
125
126     // Test that the links still work.
127     $this->drupalGet('test-summary');
128     $this->clickLink('type1');
129     $entries = $this->cssSelect('div.view-content div.views-row');
130     $this->assertEqual(2, count($entries));
131
132     // Set base_path to an unknown path and test that the links lead to the
133     // front page.
134     $edit = [
135       'options[summary][options][unformatted_summary][base_path]' => 'unknown-path',
136     ];
137     $this->drupalPostForm('admin/structure/views/nojs/handler/test_summary/page_1/argument/type', $edit, t('Apply'));
138     $this->drupalPostForm(NULL, [], t('Save'));
139     $this->drupalGet('test-summary');
140     $this->assertLinkByHref('/');
141   }
142
143 }