protected function BlazyCreationTestTrait::setUpContentWithItems in Blazy 8.2
Same name and namespace in other branches
- 8 tests/src/Traits/BlazyCreationTestTrait.php \Drupal\Tests\blazy\Traits\BlazyCreationTestTrait::setUpContentWithItems()
Build dummy nodes with optional fields.
Parameters
string $bundle: The bundle name.
array $settings: (Optional) configurable settings.
Return value
\Drupal\node\Entity\Node|null The node instance.
10 calls to BlazyCreationTestTrait::setUpContentWithItems()
- BlazyBlazyJavaScriptTest::testFormatterDisplay in tests/
src/ FunctionalJavascript/ BlazyBlazyJavaScriptTest.php - Test the Blazy element from loading to loaded states.
- BlazyCreationTestTrait::createReferencingEntity in tests/
src/ Traits/ BlazyCreationTestTrait.php - Create referencing entity.
- BlazyCreationTestTrait::setUpContentWithEntityReference in tests/
src/ Traits/ BlazyCreationTestTrait.php - Build dummy contents with entity references.
- BlazyEntityTest::setUp in tests/
src/ Kernel/ BlazyEntityTest.php - Set the default field storage backend for fields created during tests.
- BlazyEntityTest::testGetEntityView in tests/
src/ Kernel/ BlazyEntityTest.php - Tests the entity view builder.
File
- tests/
src/ Traits/ BlazyCreationTestTrait.php, line 214
Class
- BlazyCreationTestTrait
- A Trait common for Blazy tests.
Namespace
Drupal\Tests\blazy\TraitsCode
protected function setUpContentWithItems($bundle = '', array $settings = []) {
$title = empty($settings['title']) ? $this->testPluginId : $settings['title'];
$data = empty($settings['values']) ? [] : $settings['values'];
$values = $data + [
'title' => $title . ' : ' . $this
->randomMachineName(),
'type' => $bundle,
'status' => TRUE,
];
$node = $this->blazyManager
->getEntityTypeManager()
->getStorage($this->entityType)
->create($values);
$node
->save();
if (isset($node->body)) {
$text = $this
->getRandomGenerator()
->paragraphs($this->maxParagraphs);
if (!empty($settings['extra_text'])) {
$text .= $settings['extra_text'];
}
$node
->get('body')
->setValue([
'value' => $text,
'format' => 'full_html',
]);
}
if (!empty($this->testFieldName)) {
$settings['fields'][$this->testFieldName] = empty($this->testFieldType) ? 'image' : $this->testFieldType;
}
if (!empty($settings['field_name']) && !empty($settings['field_type'])) {
$settings['fields'][$settings['field_name']] = $settings['field_type'];
}
if (!empty($settings['fields'])) {
foreach ($settings['fields'] as $field_name => $field_type) {
$multiple = $field_type == 'image' || strpos($field_name, 'mul') !== FALSE;
if (strpos($field_name, 'empty') !== FALSE) {
continue;
}
if (isset($this->entityFieldName) && $field_name == $this->entityFieldName) {
continue;
}
$max = $multiple ? $this->maxItems : 2;
if (isset($node->{$field_name})) {
// @see \Drupal\Core\Field\FieldItemListInterface::generateSampleItems
$node
->get($field_name)
->generateSampleItems($max);
}
}
}
$node
->save();
$this->testItems = $node->{$this->testFieldName};
$this->entity = $node;
return $node;
}