trait ContentHubEntityTrait in Acquia Content Hub 8
Same name in this branch
- 8 tests/src/Functional/ContentHubEntityTrait.php \Drupal\Tests\acquia_contenthub\Functional\ContentHubEntityTrait
- 8 tests/src/Unit/ContentHubEntityTrait.php \Drupal\Tests\acquia_contenthub\Unit\ContentHubEntityTrait
Defines a Trait for creating a Content Hub Entity.
Hierarchy
- trait \Drupal\Tests\acquia_contenthub\Unit\ContentHubEntityTrait
File
- tests/
src/ Unit/ ContentHubEntityTrait.php, line 12
Namespace
Drupal\Tests\acquia_contenthub\UnitView source
trait ContentHubEntityTrait {
/**
* Creates a Content Hub Entity for testing purposes.
*
* @param array $values
* An array of values.
*
* @return \Acquia\ContentHubClient\Entity
* A Content Hub Entity fully loaded.
*
* @throws \Exception
*/
private function createContentHubEntity(array $values = []) {
// Defining a default entity.
$values = $values + [
'uuid' => '00000000-1111-0000-0000-000000000000',
'type' => 'node',
'origin' => '00000000-0000-0000-0000-000000000000',
'created' => '2017-12-21T20:12:11+00:00Z',
'modified' => '2014-12-21T20:12:11+00:00Z',
'attributes' => [
'type' => [
'type' => 'string',
'value' => [
'en' => 'article',
],
],
'langcode' => [
'type' => 'string',
'value' => [
'en' => 'en',
],
],
'title' => [
'type' => 'string',
'value' => [
'en' => 'Title Test',
],
],
'url' => [
'type' => 'string',
'value' => [
'en' => 'http://localhost/test/node/1',
],
],
],
'assets' => [],
];
// Creating a Content Hub Entity.
$entity = new Entity();
$entity
->setUuid($values['uuid']);
$entity
->setType($values['type']);
$entity
->setOrigin($values['origin']);
$entity
->setCreated($values['created']);
$entity
->setModified($values['modified']);
// Adding Attributes.
foreach ($values['attributes'] as $name => $attr) {
$attribute = new Attribute($attr['type']);
$attribute
->setValues($attr['value']);
$entity
->setAttribute($name, $attribute);
}
// Adding Assets.
foreach ($values['assets'] as $myasset) {
$asset = new Asset();
$asset
->setUrl($myasset['url']);
$asset
->setReplaceToken($myasset['replace-token']);
$entity
->addAsset($asset);
}
return $entity;
}
/**
* Creates a Multilanguage Content Hub Entity for testing purposes.
*
* @param array $values
* An array of values.
*
* @return \Acquia\ContentHubClient\Entity
* A Content Hub Entity fully loaded.
*
* @throws \Exception
*/
private function createMultilanguageContentHubEntity(array $values = []) {
// Defining a default entity.
$values = $values + [
'uuid' => '00000000-1111-0000-0000-000000000000',
'type' => 'node',
'origin' => '00000000-0000-0000-0000-000000000000',
'created' => '2017-12-21T20:12:11+00:00Z',
'modified' => '2014-12-21T20:12:11+00:00Z',
'attributes' => [
'type' => [
'type' => 'string',
'value' => [
'en' => 'article',
'es' => 'articulo',
],
],
'langcode' => [
'type' => 'string',
'value' => [
'en' => 'en',
'es' => 'es',
],
],
'default_langcode' => [
'type' => 'array<boolean>',
'value' => [
'en' => [
0 => 1,
],
'es' => [
0 => 0,
],
],
],
'title' => [
'type' => 'string',
'value' => [
'en' => 'Title Test',
'es' => 'Titulo de Prueba',
],
],
'url' => [
'type' => 'string',
'value' => [
'en' => 'http://localhost/test/node/1',
],
],
],
'assets' => [],
];
// Creating a Content Hub Entity.
$entity = new Entity();
$entity
->setUuid($values['uuid']);
$entity
->setType($values['type']);
$entity
->setOrigin($values['origin']);
$entity
->setCreated($values['created']);
$entity
->setModified($values['modified']);
// Adding Attributes.
foreach ($values['attributes'] as $name => $attr) {
$attribute = new Attribute($attr['type']);
$attribute
->setValues($attr['value']);
$entity
->setAttribute($name, $attribute);
}
// Adding Assets.
foreach ($values['assets'] as $myasset) {
$asset = new Asset();
$asset
->setUrl($myasset['url']);
$asset
->setReplaceToken($myasset['replace-token']);
$entity
->addAsset($asset);
}
return $entity;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentHubEntityTrait:: |
private | function | Creates a Content Hub Entity for testing purposes. | |
ContentHubEntityTrait:: |
private | function | Creates a Multilanguage Content Hub Entity for testing purposes. |