3 namespace Drupal\Tests\views\Functional\Handler;
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;
11 * Tests the "Display all values in the same row" setting.
15 class FieldGroupRowsWebTest extends ViewTestBase {
18 * Views used by this test.
22 public static $testViews = ['test_group_rows', 'test_ungroup_rows'];
29 public static $modules = ['node'];
34 * @var \Drupal\node\NodeTypeInterface
39 * The used field name in the test.
48 * @var \Drupal\field\Entity\FieldStorageConfig
50 protected $fieldStorage;
55 * @var \Drupal\field\Entity\FieldConfig
62 protected function setUp($import_test_views = TRUE) {
63 parent::setUp($import_test_views);
65 // Create content type with unlimited text field.
66 $this->nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
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',
74 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
76 $this->fieldStorage->save();
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(),
86 'title' => $this->randomMachineName(),
87 $this->fieldName => ['a', 'b', 'c'],
89 $this->drupalCreateNode($edit);
93 * Testing when "Display all values in the same row" is checked.
95 public function testGroupRows() {
96 $this->drupalGet('test-group-rows');
97 $result = $this->cssSelect('div.views-field-field-views-testing-group- div');
100 foreach ($result as $row) {
101 $rendered_value[] = $row->getText();
103 $this->assertEqual(['a, b, c'], $rendered_value);
107 * Testing when "Display all values in the same row" is unchecked.
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();
116 $this->assertEqual(['a', 'b', 'c'], $rendered_value);