protected function EntityQueryTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::setUp()
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php \Drupal\KernelTests\Core\Entity\EntityQueryTest::setUp()
File
- core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php, line 66
Class
- EntityQueryTest
- Tests Entity Query functionality.
Namespace
Drupal\KernelTests\Core\Entity
Code
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test_mulrev');
$this
->installConfig([
'language',
]);
$figures = mb_strtolower($this
->randomMachineName());
$greetings = mb_strtolower($this
->randomMachineName());
foreach ([
$figures => 'shape',
$greetings => 'text',
] as $field_name => $field_type) {
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test_mulrev',
'type' => $field_type,
'cardinality' => 2,
]);
$field_storage
->save();
$field_storages[] = $field_storage;
}
$bundles = [];
for ($i = 0; $i < 2; $i++) {
do {
$bundle = $this
->randomMachineName();
} while ($bundles && strtolower($bundles[0]) >= strtolower($bundle));
entity_test_create_bundle($bundle);
foreach ($field_storages as $field_storage) {
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
])
->save();
}
$bundles[] = $bundle;
}
$units[] = [
$figures,
'en',
[
'color' => 'red',
'shape' => 'triangle',
],
];
$units[] = [
$figures,
'en',
[
'color' => 'blue',
'shape' => 'circle',
],
];
$units[] = [
$greetings,
'tr',
[
'value' => 'merhaba',
'format' => 'format-tr',
],
];
$units[] = [
$greetings,
'pl',
[
'value' => 'siema',
'format' => 'format-pl',
],
];
ConfigurableLanguage::createFromLangcode('tr')
->save();
ConfigurableLanguage::createFromLangcode('pl')
->save();
for ($i = 1; $i <= 15; $i++) {
$entity = EntityTestMulRev::create([
'type' => $bundles[$i & 1],
'name' => $this
->randomMachineName(),
'langcode' => 'en',
]);
foreach ([
'tr',
'pl',
] as $langcode) {
$entity
->addTranslation($langcode)->name = $this
->randomMachineName();
}
foreach (array_reverse(str_split(decbin($i))) as $key => $bit) {
if ($bit) {
$entity
->getTranslation($units[$key][1])->{$units[$key][0]}[] = $units[$key][2];
}
}
$entity
->save();
}
$this->bundles = $bundles;
$this->figures = $figures;
$this->greetings = $greetings;
$this->storage = $this->container
->get('entity_type.manager')
->getStorage('entity_test_mulrev');
}