View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\entity_share_client\ImportContext;
use Drupal\user\UserInterface;
class TaxonomyEntityReferenceTest extends EntityShareClientFunctionalTestBase {
protected static $entityTypeId = 'taxonomy_term';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected function setUp() : void {
parent::setUp();
$this
->postSetupFixture();
}
protected function getEntitiesDataArray() {
return [
'taxonomy_term' => [
'en' => [
'parent_tag' => $this
->getCompleteTaxonomyTermInfos([]),
'child_tag' => $this
->getCompleteTaxonomyTermInfos([
'parent' => [
'value_callback' => function () {
return [
[
'target_id' => $this
->getEntityId('taxonomy_term', 'parent_tag'),
],
];
},
'checker_callback' => 'getExpectedTaxonomyParentReferenceValue',
],
]),
],
],
'node' => [
'en' => [
'es_test_taxonomy_reference' => $this
->getCompleteNodeInfos([
'type' => [
'value' => 'es_test',
'checker_callback' => 'getTargetId',
],
'field_es_test_taxonomy' => [
'value_callback' => function () {
return [
[
'target_id' => $this
->getEntityId('taxonomy_term', 'child_tag'),
],
];
},
'checker_callback' => 'getExpectedTaxonomyReferenceValue',
],
]),
],
],
];
}
public function testReferencedEntityCreated() {
$selected_entities = [
'es_test_taxonomy_reference',
];
$prepared_url = $this
->prepareUrlFilteredOnUuids($selected_entities, 'node_es_test_en');
$import_context = new ImportContext($this->remote
->id(), 'node_es_test_en', $this::IMPORT_CONFIG_ID);
$this->importService
->prepareImport($import_context);
$this->importService
->importFromUrl($prepared_url);
$this
->checkCreatedEntities();
}
protected function populateRequestService() {
parent::populateRequestService();
$selected_entities = [
'es_test_taxonomy_reference',
];
$prepared_url = $this
->prepareUrlFilteredOnUuids($selected_entities, 'node_es_test_en');
$this
->discoverJsonApiEndpoints($prepared_url);
}
protected function createChannel(UserInterface $user) {
parent::createChannel($user);
$channel_storage = $this->entityTypeManager
->getStorage('channel');
$channel = $channel_storage
->create([
'id' => 'node_es_test_en',
'label' => $this
->randomString(),
'channel_entity_type' => 'node',
'channel_bundle' => 'es_test',
'channel_langcode' => static::$entityLangcode,
'authorized_users' => [
$user
->uuid(),
],
]);
$channel
->save();
$this->channels[$channel
->id()] = $channel;
}
protected function getExpectedTaxonomyReferenceValue(ContentEntityInterface $entity, string $field_name) {
return [
[
'target_id' => $this
->getEntityId('taxonomy_term', 'child_tag'),
],
];
}
protected function getExpectedTaxonomyParentReferenceValue(ContentEntityInterface $entity, string $field_name) {
return [
[
'target_id' => $this
->getEntityId('taxonomy_term', 'parent_tag'),
],
];
}
}