protected function RESTTestBase::entityValues in Drupal 8
Provides an array of suitable property values for an entity type.
Required properties differ from entity type to entity type, so we keep a minimum mapping here.
Parameters
string $entity_type_id: The ID of the type of entity that should be created.
Return value
array An array of values keyed by property name.
1 call to RESTTestBase::entityValues()
- RESTTestBase::entityCreate in core/
modules/ rest/ src/ Tests/ RESTTestBase.php - Creates entity objects based on their types.
File
- core/
modules/ rest/ src/ Tests/ RESTTestBase.php, line 309
Class
- RESTTestBase
- Test helper class that provides a REST client method to send HTTP requests.
Namespace
Drupal\rest\TestsCode
protected function entityValues($entity_type_id) {
switch ($entity_type_id) {
case 'entity_test':
return [
'name' => $this
->randomMachineName(),
'user_id' => 1,
'field_test_text' => [
0 => [
'value' => $this
->randomString(),
'format' => 'plain_text',
],
],
];
case 'config_test':
return [
'id' => $this
->randomMachineName(),
'label' => 'Test label',
];
case 'node':
return [
'title' => $this
->randomString(),
'type' => 'resttest',
];
case 'node_type':
return [
'type' => 'article',
'name' => $this
->randomMachineName(),
];
case 'user':
return [
'name' => $this
->randomMachineName(),
];
case 'comment':
return [
'subject' => $this
->randomMachineName(),
'entity_type' => 'node',
'comment_type' => 'comment',
'comment_body' => $this
->randomString(),
'entity_id' => 'invalid',
'field_name' => 'comment',
];
case 'taxonomy_vocabulary':
return [
'vid' => 'tags',
'name' => $this
->randomMachineName(),
];
case 'block':
// Block placements depend on themes, ensure Bartik is installed.
$this->container
->get('theme_installer')
->install([
'bartik',
]);
return [
'id' => strtolower($this
->randomMachineName(8)),
'plugin' => 'system_powered_by_block',
'theme' => 'bartik',
'region' => 'header',
];
default:
if ($this
->isConfigEntity($entity_type_id)) {
return $this
->configEntityValues($entity_type_id);
}
return [];
}
}