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