View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\Component\Utility\UrlHelper;
use Drupal\entity_share_client\ImportContext;
use Drupal\node\NodeInterface;
class RevisionTest extends EntityShareClientFunctionalTestBase {
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected $urlsByPass = [];
protected function setUp() : void {
parent::setUp();
$this
->prepareContent();
$this
->populateRequestService();
$this
->editContentAndRepopulate(2);
$this
->deleteContent();
}
protected function editContentAndRepopulate(int $version) {
foreach ($this->entities as $entities_per_type) {
foreach ($entities_per_type as $entity) {
$entity
->set('title', $entity
->label() . " V{$version}")
->save();
}
}
foreach ($this->visitedUrlsDuringSetup as $url) {
$parsed_url = UrlHelper::parse($url);
$parsed_url['query'][$version] = $version;
$query = UrlHelper::buildQuery($parsed_url['query']);
$prepared_url = $parsed_url['path'] . '?' . $query;
$this->remoteManager
->request($this->remote, 'GET', $prepared_url);
$this->urlsByPass[$url][$version] = $prepared_url;
}
}
protected function getImportConfigProcessorSettings() {
$processors = parent::getImportConfigProcessorSettings();
$processors['revision'] = [
'weights' => [
'process_entity' => 10,
],
'enforce_new_revision' => TRUE,
'translation_affected' => FALSE,
];
return $processors;
}
protected function getEntitiesDataArray() {
return [
'node' => [
'en' => [
'es_test' => $this
->getCompleteNodeInfos([
'status' => [
'value' => NodeInterface::PUBLISHED,
'checker_callback' => 'getValue',
],
]),
],
],
];
}
public function testRevisionPlugin() {
$this
->pullEveryChannels();
$this
->checkCreatedEntities();
$imported_node = $this
->loadEntity('node', 'es_test');
$revision_ids = $this->entityTypeManager
->getStorage('node')
->revisionIds($imported_node);
$this
->assertEquals(count($revision_ids), 1, "After the initial import, node " . $imported_node
->uuid() . " has only one revision.");
$this->importService
->getRuntimeImportContext()
->clearImportedEntities();
$channel_id = static::$entityTypeId . '_' . static::$entityBundleId . '_' . static::$entityLangcode;
$import_context = new ImportContext($this->remote
->id(), $channel_id, $this::IMPORT_CONFIG_ID);
$channel_infos = $this->remoteManager
->getChannelsInfos($this->remote);
$channel_url = $channel_infos[$channel_id]['url'];
$current_pass_url = $this->urlsByPass[$channel_url][2];
$this->importService
->prepareImport($import_context);
$this->importService
->importFromUrl($current_pass_url);
$imported_node = $this
->loadEntity('node', 'es_test');
$revision_ids = $this->entityTypeManager
->getStorage('node')
->revisionIds($imported_node);
$this
->assertEquals(count($revision_ids), 2, "After the second import, node " . $imported_node
->uuid() . " has two revisions.");
$this
->removePluginFromImportConfig('revision');
$this
->resetImportedContent();
$this->urlsByPass = [];
$this
->prepareContent();
$this
->populateRequestService();
$this
->editContentAndRepopulate(2);
$this
->deleteContent();
$this
->pullEveryChannels();
$imported_node = $this
->loadEntity('node', 'es_test');
$revision_ids = $this->entityTypeManager
->getStorage('node')
->revisionIds($imported_node);
$this
->assertEquals(count($revision_ids), 1, "After the initial import, node " . $imported_node
->uuid() . " has only one revision.");
$import_context = new ImportContext($this->remote
->id(), $channel_id, $this::IMPORT_CONFIG_ID);
$channel_infos = $this->remoteManager
->getChannelsInfos($this->remote);
$channel_url = $channel_infos[$channel_id]['url'];
$current_pass_url = $this->urlsByPass[$channel_url][2];
$this->importService
->prepareImport($import_context);
$this->importService
->importFromUrl($current_pass_url);
$imported_node = $this
->loadEntity('node', 'es_test');
$revision_ids = $this->entityTypeManager
->getStorage('node')
->revisionIds($imported_node);
$this
->assertEquals(count($revision_ids), 1, "After the second import, node " . $imported_node
->uuid() . " has only one revision.");
}
}