function RowEntityRenderersTest::setUp
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php \Drupal\Tests\views\Kernel\Entity\RowEntityRenderersTest::setUp()
- 8.9.x core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php \Drupal\Tests\views\Kernel\Entity\RowEntityRenderersTest::setUp()
- 11.x core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php \Drupal\Tests\views\Kernel\Entity\RowEntityRenderersTest::setUp()
Overrides ViewsKernelTestBase::setUp
File
-
core/
modules/ views/ tests/ src/ Kernel/ Entity/ RowEntityRenderersTest.php, line 88
Class
- RowEntityRenderersTest
- Tests the entity row renderers.
Namespace
Drupal\Tests\views\Kernel\EntityCode
protected function setUp($import_test_views = TRUE) : void {
parent::setUp(FALSE);
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installSchema('node', [
'node_access',
]);
$this->installConfig([
'node',
'language',
]);
$this->langcodes = [
\Drupal::languageManager()->getDefaultLanguage()
->getId(),
];
for ($i = 0; $i < 2; $i++) {
$langcode = 'l' . $i;
$this->langcodes[] = $langcode;
ConfigurableLanguage::createFromLangcode($langcode)->save();
}
$this->testAuthor = User::create([
'name' => 'foo',
]);
$this->testAuthor
->save();
// Make sure we do not try to render non-existing user data.
$node_type = NodeType::create([
'type' => 'test',
'name' => 'Test',
]);
$node_type->setDisplaySubmitted(FALSE);
$node_type->save();
FieldStorageConfig::create([
'entity_type' => 'node',
'type' => 'entity_reference',
'field_name' => 'field_reference',
])->save();
FieldConfig::create([
'entity_type' => 'node',
'bundle' => 'test',
'field_name' => 'field_reference',
])->save();
$this->values = [];
$this->ids = [];
$controller = \Drupal::entityTypeManager()->getStorage('node');
$langcode_index = 0;
for ($i = 0; $i < count($this->langcodes); $i++) {
// Create a node with a different default language each time.
$default_langcode = $this->langcodes[$langcode_index++];
$node = $controller->create([
'type' => 'test',
'uid' => $this->testAuthor
->id(),
'langcode' => $default_langcode,
]);
// Ensure the default language is processed first.
$langcodes = array_merge([
$default_langcode,
], array_diff($this->langcodes, [
$default_langcode,
]));
foreach ($langcodes as $langcode) {
// Ensure we have a predictable result order.
$this->values[$i][$langcode] = $i . '-' . $langcode . '-' . $this->randomMachineName();
if ($langcode != $default_langcode) {
$node->addTranslation($langcode, [
'title' => $this->values[$i][$langcode],
'field_reference' => ($i + 1) % 3 + 1,
]);
}
else {
$node->setTitle($this->values[$i][$langcode]);
$node->set('field_reference', ($i + 1) % 3 + 1);
}
$node->save();
$this->ids[] = [
'nid' => $node->id(),
'uid' => $this->testAuthor
->id(),
];
}
}
ViewTestData::createTestViews(static::class, [
'views_test_config',
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.