FieldGroupRowsWebTest.php in Zircon Profile 8
File
core/modules/views/src/Tests/Handler/FieldGroupRowsWebTest.php
View source
<?php
namespace Drupal\views\Tests\Handler;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\views\Tests\ViewTestBase;
class FieldGroupRowsWebTest extends ViewTestBase {
public static $testViews = [
'test_group_rows',
'test_ungroup_rows',
];
public static $modules = [
'node',
];
protected $nodeType;
protected $fieldName;
protected $fieldStorage;
protected $field;
protected function setUp() {
parent::setUp();
$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[] = (string) $row[0];
}
$this
->assertEqual([
'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[] = (string) $row[0];
}
$this
->assertEqual([
'a',
'b',
'c',
], $rendered_value);
}
}