Version 1
[yaffs-website] / web / core / modules / views / tests / src / Functional / Handler / FieldGroupRowsWebTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Handler;
4
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\Tests\views\Functional\ViewTestBase;
9
10 /**
11  * Tests the "Display all values in the same row" setting.
12  *
13  * @group views
14  */
15 class FieldGroupRowsWebTest extends ViewTestBase {
16
17   /**
18    * Views used by this test.
19    *
20    * @var array
21    */
22   public static $testViews = ['test_group_rows', 'test_ungroup_rows'];
23
24   /**
25    * Modules to enable.
26    *
27    * @var array
28    */
29   public static $modules = ['node'];
30
31   /**
32    * The page node type.
33    *
34    * @var \Drupal\node\NodeTypeInterface
35    */
36   protected $nodeType;
37
38   /**
39    * The used field name in the test.
40    *
41    * @var string
42    */
43   protected $fieldName;
44
45   /**
46    * The field storage.
47    *
48    * @var \Drupal\field\Entity\FieldStorageConfig
49    */
50   protected $fieldStorage;
51
52   /**
53    * The field config.
54    *
55    * @var \Drupal\field\Entity\FieldConfig
56    */
57   protected $field;
58
59   /**
60    * {@inheritdoc}
61    */
62   protected function setUp($import_test_views = TRUE) {
63     parent::setUp($import_test_views);
64
65     // Create content type with unlimited text field.
66     $this->nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
67
68     // Create the unlimited text field.
69     $this->fieldName = 'field_views_testing_group_rows';
70     $this->fieldStorage = FieldStorageConfig::create([
71       'field_name' => $this->fieldName,
72       'entity_type' => 'node',
73       'type' => 'text',
74       'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
75     ]);
76     $this->fieldStorage->save();
77
78     // Create an instance of the text field on the content type.
79     $this->field = FieldConfig::create([
80       'field_storage' => $this->fieldStorage,
81       'bundle' => $this->nodeType->id(),
82     ]);
83     $this->field->save();
84
85     $edit = [
86       'title' => $this->randomMachineName(),
87       $this->fieldName => ['a', 'b', 'c'],
88     ];
89     $this->drupalCreateNode($edit);
90   }
91
92   /**
93    * Testing when "Display all values in the same row" is checked.
94    */
95   public function testGroupRows() {
96     $this->drupalGet('test-group-rows');
97     $result = $this->cssSelect('div.views-field-field-views-testing-group- div');
98
99     $rendered_value = [];
100     foreach ($result as $row) {
101       $rendered_value[] = $row->getText();
102     }
103     $this->assertEqual(['a, b, c'], $rendered_value);
104   }
105
106   /**
107    * Testing when "Display all values in the same row" is unchecked.
108    */
109   public function testUngroupedRows() {
110     $this->drupalGet('test-ungroup-rows');
111     $result = $this->cssSelect('div.views-field-field-views-testing-group- div');
112     $rendered_value = [];
113     foreach ($result as $row) {
114       $rendered_value[] = $row->getText();
115     }
116     $this->assertEqual(['a', 'b', 'c'], $rendered_value);
117   }
118
119 }