protected function EntityToTableRendererTest::setUp in Reference Table Formatter 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/EntityToTableRendererTest.php \Drupal\Tests\reference_table_formatter\Kernel\EntityToTableRendererTest::setUp()
Overrides EntityKernelTestBase::setUp
File
- tests/
src/ Kernel/ EntityToTableRendererTest.php, line 57
Class
- EntityToTableRendererTest
- Tests reference table formatter entity to table renderer.
Namespace
Drupal\Tests\reference_table_formatter\KernelCode
protected function setUp() {
parent::setUp();
$this
->installConfig([
'system',
]);
$this
->installSchema('node', [
'node_access',
]);
NodeType::create([
'type' => 't_shirt',
])
->save();
$fields = [
[
[
'type' => 'string',
'field_name' => 'field_color',
],
[
'label' => 'Color',
],
],
[
[
'type' => 'float',
'field_name' => 'field_price',
],
[
'label' => 'Price',
'settings' => [
'prefix' => '$',
],
],
],
[
[
'type' => 'string',
'field_name' => 'field_size',
],
[
'label' => 'Size',
],
],
];
foreach ($fields as $parameters) {
list($storage, $instance) = $parameters;
$this
->createField($storage, $instance + [
'bundle' => 't_shirt',
]);
}
EntityViewMode::create([
'id' => 'node.teaser',
'targetEntityType' => 'node',
])
->save();
$this->displayRepository = $this->container
->get('entity_display.repository');
$this->displayRepository
->getViewDisplay('node', 't_shirt', 'teaser')
->setComponent('title', [
'weight' => -5,
])
->setComponent('field_color', [
'weight' => 3,
])
->setComponent('field_price', [
'weight' => 1,
])
->setComponent('field_size', [
'weight' => 2,
])
->save();
$node_0 = Node::create([
'title' => 'Red Medium T',
'type' => 't_shirt',
'field_color' => 'Red',
'field_price' => 1.0,
'field_size' => 'M',
]);
$node_0
->save();
$node_1 = Node::create([
'title' => 'Green Large T',
'type' => 't_shirt',
'field_color' => 'Green',
'field_price' => 2.0,
'field_size' => 'L',
]);
$node_1
->save();
$this->nodes = [
$node_0,
$node_1,
];
$entity_manager = $this->container
->get('entity_type.manager');
$this->renderer = $this->container
->get('renderer');
$this->tableRenderer = new EntityToTableRenderer($entity_manager, $this->renderer, $this->displayRepository);
}