You are here

public function PurgeTest::test in Lightning Workflow 8.3

Same name and namespace in other branches
  1. 8.2 modules/lightning_scheduler/tests/src/Functional/PurgeTest.php \Drupal\Tests\lightning_scheduler\Functional\PurgeTest::test()

Runs a basic test of migrating old Lightning Scheduler data.

This doesn't really test that data integrity is preserved, so subclasses should override this method and call it before asserting other things.

Overrides MigrationTestBase::test

File

modules/lightning_scheduler/tests/src/Functional/PurgeTest.php, line 19

Class

PurgeTest
Tests purging of old Lightning Scheduler data, without migrating it.

Namespace

Drupal\Tests\lightning_scheduler\Functional

Code

public function test() {
  parent::test();
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextContains('You are about to migrate scheduled transitions for all custom blocks and content items.');

  // Assert that the purge-related fields are present and accounted for.
  $assert
    ->pageTextContains('Purge without migrating');
  $select = $assert
    ->fieldExists('purge[entity_type_id]')
    ->getAttribute('name');
  $this
    ->assertSame('block_content', $assert
    ->optionExists($select, 'custom blocks')
    ->getValue());
  $this
    ->assertSame('node', $assert
    ->optionExists($select, 'content items')
    ->getValue());
  $this
    ->getSession()
    ->getPage()
    ->fillField($select, 'node');
  $assert
    ->buttonExists('Purge')
    ->press();
  $assert
    ->pageTextContains('Purged scheduled transitions for content items.');
  $assert
    ->pageTextNotContains('All migrations are completed.');
  $assert
    ->pageTextContains('You are about to migrate scheduled transitions for all custom blocks.');
  $assert
    ->optionExists($select, 'custom blocks');
  $assert
    ->optionNotExists($select, 'content items');
  $storage = $this
    ->postMigration('node');

  /** @var \Drupal\node\NodeInterface $node */
  $node = $storage
    ->load(1);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertNode($node);
  $this
    ->assertTrue($node
    ->hasTranslation('fr'));
  $this
    ->assertNode($node
    ->getTranslation('fr'));

  // Test the default revision, loaded explicitly.
  $node = $storage
    ->loadRevision(5);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertNode($node);
  $this
    ->assertTrue($node
    ->hasTranslation('fr'));
  $this
    ->assertNode($node
    ->getTranslation('fr'));

  // Test previous revisions too.
  $node = $storage
    ->loadRevision(4);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertNode($node);
  $this
    ->assertTrue($node
    ->hasTranslation('fr'));
  $this
    ->assertNode($node
    ->getTranslation('fr'));
  $node = $storage
    ->loadRevision(3);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertNode($node);
  $this
    ->assertFalse($node
    ->hasTranslation('fr'));
  $node = $storage
    ->loadRevision(2);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertNode($node);
  $this
    ->assertFalse($node
    ->hasTranslation('fr'));
  $node = $storage
    ->loadRevision(1);
  $this
    ->assertInstanceOf(NodeInterface::class, $node);
  $this
    ->assertFalse($node
    ->hasTranslation('fr'));
}