View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\NodeInterface;
use Drupal\user\UserInterface;
class MissingFieldsTest extends EntityShareClientFunctionalTestBase {
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected function setUp() : void {
parent::setUp();
$this->remoteManager
->getfieldMappings($this->remote);
$this
->postSetupFixture();
FieldConfig::loadByName('node', 'es_test', 'field_es_test_text_plain_long')
->delete();
FieldConfig::loadByName('node', 'es_test', 'field_es_test_taxonomy')
->delete();
}
protected function getEntitiesDataArray() {
return [
'taxonomy_term' => [
'en' => [
'es_test_tag' => $this
->getCompleteTaxonomyTermInfos([
'vid' => [
'value' => 'es_test',
],
]),
],
],
'node' => [
'en' => [
'es_test_missing_fields' => $this
->getCompleteNodeInfos([
'field_es_test_text_plain_long' => [
'value' => $this->faker
->text(1000),
'checker_callback' => 'getValue',
],
'field_es_test_taxonomy' => [
'value_callback' => function () {
return [
[
'target_id' => $this
->getEntityId('taxonomy_term', 'es_test_tag'),
],
];
},
],
]),
],
'fr' => [
'es_test_missing_fields' => $this
->getCompleteNodeInfos([
'field_es_test_text_plain_long' => [
'value' => $this->faker
->text(1000),
'checker_callback' => 'getValue',
],
'field_es_test_taxonomy' => [
'value_callback' => function () {
return [
[
'target_id' => $this
->getEntityId('taxonomy_term', 'es_test_tag'),
],
];
},
],
]),
],
],
];
}
public function testMissingFieldsImport() {
$this
->pullChannel('node_es_test_en');
$this->importService
->getRuntimeImportContext()
->clearImportedEntities();
$node = $this
->loadEntity('node', 'es_test_missing_fields');
$this
->assertTrue($node instanceof NodeInterface, 'The node had been imported');
$this
->pullChannel('node_es_test_fr');
$this->importService
->getRuntimeImportContext()
->clearImportedEntities();
$node = $this
->loadEntity('node', 'es_test_missing_fields');
$node_translation = $node
->getTranslation('fr');
$this
->assertFalse($node_translation
->isDefaultTranslation(), 'The French translation had been created.');
$this
->pullChannel('node_es_test_fr');
$node = $this
->loadEntity('node', 'es_test_missing_fields');
$node_translation = $node
->getTranslation('fr');
$this
->assertFalse($node_translation
->isDefaultTranslation(), 'The French translation had been updated.');
}
protected function createChannel(UserInterface $user) {
parent::createChannel($user);
$channel_storage = $this->entityTypeManager
->getStorage('channel');
$channel = $channel_storage
->create([
'id' => 'node_es_test_fr',
'label' => $this
->randomString(),
'channel_entity_type' => 'node',
'channel_bundle' => 'es_test',
'channel_langcode' => 'fr',
'authorized_users' => [
$user
->uuid(),
],
]);
$channel
->save();
$this->channels[$channel
->id()] = $channel;
}
}