View source
<?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;
class FieldGroupRowsWebTest extends ViewTestBase {
public static $testViews = [
'test_group_rows',
'test_ungroup_rows',
];
protected static $modules = [
'node',
];
protected $defaultTheme = 'stark';
protected $nodeType;
protected $fieldName;
protected $fieldStorage;
protected $field;
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$this->nodeType = $this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$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();
$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);
}
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
->assertEquals([
'a, b, c',
], $rendered_value);
}
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();
}
$this
->assertEquals([
'a',
'b',
'c',
], $rendered_value);
}
}