You are here

public function RevisionTest::testRevisionPlugin in Entity Share 8.3

Test the "Revision" Import Processor plugin.

Test in enabled and disabled state.

File

modules/entity_share_client/tests/src/Functional/RevisionTest.php, line 125

Class

RevisionTest
Functional test class to test import plugin "Revision".

Namespace

Drupal\Tests\entity_share_client\Functional

Code

public function testRevisionPlugin() {

  // Verify that entities can be pulled with this plugin enabled.
  $this
    ->pullEveryChannels();
  $this
    ->checkCreatedEntities();

  // Verify that pulled entity has just one revision.
  $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();

  // Prepare import context.
  $channel_id = static::$entityTypeId . '_' . static::$entityBundleId . '_' . static::$entityLangcode;
  $import_context = new ImportContext($this->remote
    ->id(), $channel_id, $this::IMPORT_CONFIG_ID);

  // Import data from the remote URL: here we are using the 2nd version
  // of the channel URL, which contains data after the modification.
  $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);

  // Verify that pulled entity has two revisions.
  $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.");

  // Disable the import plugin.
  $this
    ->removePluginFromImportConfig('revision');

  // Reset all content.
  $this
    ->resetImportedContent();
  $this->urlsByPass = [];

  // Prepare content twice.
  $this
    ->prepareContent();
  $this
    ->populateRequestService();
  $this
    ->editContentAndRepopulate(2);
  $this
    ->deleteContent();

  // Pull twice and the number of revisions should always be one.
  $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.");
}