You are here

public function PurgeTest::test in Lightning Workflow 8.2

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

Overrides MigrationTestBase::test

File

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

Class

PurgeTest
@group lightning @group lightning_workflow @group lightning_scheduler

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 block entities 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 block entities')
    ->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 block entities.');
  $assert
    ->optionExists($select, 'custom block entities');
  $assert
    ->optionNotExists($select, 'content items');
  $storage = $this
    ->postMigration('node');

  /** @var 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
    ->assertTrue($node);
  $this
    ->assertFalse($node
    ->hasTranslation('fr'));
}