protected function BlazyCreationTestTrait::setUpContentWithItems in Blazy 8
Same name and namespace in other branches
- 8.2 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.
8 calls to BlazyCreationTestTrait::setUpContentWithItems()
- 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.
- BlazyFormatterTest::setUp in tests/
src/ Kernel/ BlazyFormatterTest.php - Set the default field storage backend for fields created during tests.
- BlazyJavaScriptTest::testFormatterDisplay in tests/
src/ FunctionalJavascript/ BlazyJavaScriptTest.php - Test the Blazy element from loading to loaded states.
- BlazyManagerTest::setUp in tests/
src/ Kernel/ BlazyManagerTest.php - Set the default field storage backend for fields created during tests.
File
- tests/
src/ Traits/ BlazyCreationTestTrait.php, line 221
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)) {
$node->body->value = $this
->getRandomGenerator()
->paragraphs($this->maxParagraphs);
$node->body->format = 'restricted_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->{$field_name}
->generateSampleItems($max);
}
}
}
$node
->save();
$this->testItems = $node->{$this->testFieldName};
$this->entity = $node;
return $node;
}