View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\Core\Entity\ContentEntityInterface;
class ParagraphTest extends EntityShareClientFunctionalTestBase {
public static $modules = [
'jsonapi_extras',
'paragraphs_test',
];
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected static $behaviorSettings = [
'test_bold_text' => [
'bold_text' => 1,
],
];
protected function setUp() : void {
parent::setUp();
$this->entityTypeManager
->getStorage('jsonapi_resource_config')
->create([
'id' => 'paragraph--es_test',
'disabled' => FALSE,
'path' => 'paragraph/es_test',
'resourceType' => 'paragraph--es_test',
'resourceFields' => [
'behavior_settings' => [
'fieldName' => 'behavior_settings',
'publicName' => 'behavior_settings',
'enhancer' => [
'id' => 'entity_share_serialized_data',
],
'disabled' => FALSE,
],
],
])
->save();
$this
->postSetupFixture();
}
protected function getEntitiesDataArray() {
return [
'paragraph' => [
'en' => [
'es_test_paragraph' => $this
->getCompleteParagraphInfos([
'field_es_test_text_plain' => [
'value' => $this->faker
->text(255),
'checker_callback' => 'getValue',
],
'behavior_settings' => [
'value' => serialize(static::$behaviorSettings),
'checker_callback' => 'getExpectedBehaviorSettingsValue',
],
]),
],
],
'node' => [
'en' => [
'es_test_paragraph_reference' => $this
->getCompleteNodeInfos([
'field_es_test_paragraphs' => [
'value_callback' => function () {
return [
[
'target_id' => $this
->getEntityId('paragraph', 'es_test_paragraph'),
'target_revision_id' => $this
->getEntityRevisionId('paragraph', 'es_test_paragraph'),
],
];
},
'checker_callback' => 'getExpectedParagraphReferenceValue',
],
]),
],
],
];
}
public function testReferenceEntityValue() {
$this
->pullEveryChannels();
$this
->checkCreatedEntities();
}
protected function getExpectedParagraphReferenceValue(ContentEntityInterface $entity, string $field_name) {
return [
[
'target_id' => $this
->getEntityId('paragraph', 'es_test_paragraph'),
'target_revision_id' => $this
->getEntityRevisionId('paragraph', 'es_test_paragraph'),
],
];
}
protected function getExpectedBehaviorSettingsValue(ContentEntityInterface $entity, string $field_name) {
return serialize(static::$behaviorSettings);
}
}