external_entity-1.0.x-dev/tests/src/Concerns/StubbedHttpResponses.php
tests/src/Concerns/StubbedHttpResponses.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\external_entity\Concerns;
use Drupal\Core\Field\FieldItemList;
use Drupal\text\Plugin\Field\FieldType\TextFieldItemList;
trait StubbedHttpResponses {
/**
* Define the external entity fetch stubbed data.
* @return array[]
*/
protected function fetchStubbedData(): array {
return [
'node' => [
'label' => 'Content',
'type' => 'node',
'variations' => [
'page' => [
'label' => 'Basic page'
]
],
'properties' => [
'page' => [
'id' => [
'label' => 'ID',
'name' => 'nid',
'type' => 'integer',
'settings' => [
'unsigned' => true,
'size' => 'normal',
'min' => '',
'max' => '',
'prefix' => '',
'suffix' => ''
],
'properties' => []
],
'uuid' => [
'label' => 'UUID',
'name' => 'uuid',
'type' => 'uuid',
'settings' => [
'max_length' => 128,
'is_ascii' => true,
'case_sensitive' => false
],
'properties' => []
],
'label' => [
'label' => 'Title',
'name' => 'title',
'type' => 'string',
'settings' => [
'max_length' => 255,
'is_ascii' => false,
'case_sensitive' => false
],
'properties' => []
],
'body' => [
'label' => 'Body',
'name' => 'body',
'type' => 'text_with_summary',
'settings' => [
'display_summary' => true,
'required_summary' => false,
'allowed_formats' => []
],
'properties' => [
'format' => [
'type' => 'filter_format'
],
'summary' => [
'type' => 'string'
]
]
]
]
],
'status' => true
]
];
}
/**
* Define the external entity lookup stubbed data.
*
* @param $stub_uuid
*
* @return array[]
*/
protected function lookupStubbedData($stub_uuid = null): array {
$uuid = $stub_uuid ?? '0ac544a2-6bf9-4886-9da9-b07abc1234ef';
return [
$uuid => [
'resource' => 'node',
'properties' => [
'id' => [
'type' => 'integer',
'label' => 'ID',
'value' => [
[
'value' => '1'
]
],
'class' => FieldItemList::class
],
'uuid' => [
'type' => 'uuid',
'label' => 'UUID',
'value' => [
[
'value' => $uuid
]
],
'class' => FieldItemList::class
],
'label' => [
'type' => 'string',
'label' => 'Title',
'value' => [
[
'value' => 'Testing'
]
],
'class' => FieldItemList::class
],
'body' => [
'type' => 'text_with_summary',
'label' => 'Body',
'value' => [
[
'value' => '<p>Here is some content from the main site.</p>',
'summary' => '',
'format' => 'basic_html'
]
],
'class' => TextFieldItemList::class
]
],
'variation' => 'page',
'path' => 'https://example.com/node/1'
]
];
}
/**
* Define the external entity search stubbed data.
*
* @param string|null $stub_uuid
*
* @return array
*/
protected function searchStubbedData(?string $stub_uuid = null): array {
$uuid = $stub_uuid ?? '0ac544a2-6bf9-4886-9da9-b07abc1234ef';
return [
'info' => [
'total' => 1,
],
'results' => [
$uuid => [
'resource' => 'node',
'variation' => 'page',
'properties' => [
'id' => [
'type' => 'integer',
'label' => 'ID',
'value' => [
['value' => '1'],
],
'class' => FieldItemList::class,
],
'uuid' => [
'type' => 'uuid',
'label' => 'UUID',
'value' => [
['value' => $uuid],
],
'class' => FieldItemList::class,
],
'label' => [
'type' => 'string',
'label' => 'Title',
'value' => [
['value' => 'Testing'],
],
'class' => FieldItemList::class,
],
'body' => [
'type' => 'text_with_summary',
'label' => 'Body',
'value' => [
[
'value' => '<p>Here is some content from the main site.</p>',
'summary' => '',
'format' => 'basic_html',
],
],
'class' => TextFieldItemList::class,
],
],
'path' => 'https://example.com/node/1',
],
],
];
}
}
