SkipImportedTest.php in Entity Share 8.3
File
modules/entity_share_client/tests/src/Functional/SkipImportedTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\node\NodeInterface;
class SkipImportedTest extends EntityShareClientFunctionalTestBase {
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected function setUp() : void {
parent::setUp();
$this->entityTypeManager
->getStorage('jsonapi_resource_config')
->create([
'id' => 'node--es_test',
'disabled' => FALSE,
'path' => 'node/es_test',
'resourceType' => 'node--es_test',
'resourceFields' => [
'changed' => [
'fieldName' => 'changed',
'publicName' => 'changed',
'enhancer' => [
'id' => '',
],
'disabled' => FALSE,
],
],
])
->save();
$this
->postSetupFixture();
}
protected function getImportConfigProcessorSettings() {
$processors = parent::getImportConfigProcessorSettings();
$processors['skip_imported'] = [
'weights' => [
'is_entity_importable' => -5,
],
];
return $processors;
}
protected function getEntitiesDataArray() {
return [
'node' => [
'en' => [
'es_test' => $this
->getCompleteNodeInfos([
'status' => [
'value' => NodeInterface::PUBLISHED,
'checker_callback' => 'getValue',
],
]),
],
],
];
}
public function testSkipImportedPlugin() {
$this
->pullEveryChannels();
$this
->checkCreatedEntities();
$this->importService
->getRuntimeImportContext()
->clearImportedEntities();
$recreated_node = $this
->loadEntity('node', 'es_test');
$recreated_node
->delete();
$this
->pullChannel('node_es_test_en');
$imported_entities = $this->importService
->getRuntimeImportContext()
->getImportedEntities();
$imported_entities_en = $imported_entities['en'] ?? [];
$this->importService
->getRuntimeImportContext()
->clearImportedEntities();
$this
->assertEquals(count($imported_entities_en), 1);
$this
->pullChannel('node_es_test_en');
$imported_entities = $this->importService
->getRuntimeImportContext()
->getImportedEntities();
$imported_entities_en = $imported_entities['en'] ?? [];
$this
->assertEquals(count($imported_entities_en), 0);
$this->importService
->getRuntimeImportContext()
->clearImportedEntities();
$recreated_node = $this
->loadEntity('node', 'es_test');
$recreated_node
->delete();
$this
->removePluginFromImportConfig('skip_imported');
$this
->pullChannel('node_es_test_en');
$imported_entities = $this->importService
->getRuntimeImportContext()
->getImportedEntities();
$imported_entities_en = $imported_entities['en'] ?? [];
$this->importService
->getRuntimeImportContext()
->clearImportedEntities();
$this
->assertEquals(count($imported_entities_en), 1);
$this
->pullChannel('node_es_test_en');
$imported_entities = $this->importService
->getRuntimeImportContext()
->getImportedEntities();
$imported_entities_en = $imported_entities['en'] ?? [];
$this
->assertEquals(count($imported_entities_en), 1);
}
}