function ContentModerationSyncingTest::testStateChangedPreviousRevisionDuringSync

Same name in other branches
  1. 8.9.x core/modules/content_moderation/tests/src/Kernel/ContentModerationSyncingTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationSyncingTest::testStateChangedPreviousRevisionDuringSync()
  2. 10 core/modules/content_moderation/tests/src/Kernel/ContentModerationSyncingTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationSyncingTest::testStateChangedPreviousRevisionDuringSync()
  3. 11.x core/modules/content_moderation/tests/src/Kernel/ContentModerationSyncingTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationSyncingTest::testStateChangedPreviousRevisionDuringSync()

Tests a moderation state changed on a previous revision during a sync.

File

core/modules/content_moderation/tests/src/Kernel/ContentModerationSyncingTest.php, line 144

Class

ContentModerationSyncingTest
Test content moderation when an entity is marked as 'syncing'.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testStateChangedPreviousRevisionDuringSync() {
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('entity_test_mulrevpub');
    $entity = EntityTestMulRevPub::create([
        'moderation_state' => 'published',
        'name' => 'foo',
    ]);
    $entity->save();
    $entity->moderation_state = 'draft';
    $entity->name = 'bar';
    $entity->save();
    $draft_revision_id = $entity->getRevisionId();
    $entity->name = 'baz';
    $entity->moderation_state = 'published';
    $entity->save();
    $default_revision_id = $entity->getRevisionId();
    // Update the draft revision moderation state to published, which would
    // typically change the default status of a revision during moderation.
    $draft_revision = $storage->loadRevision($draft_revision_id);
    $draft_revision->setSyncing(TRUE);
    $draft_revision->name = 'qux';
    $draft_revision->moderation_state = 'published';
    $draft_revision->save();
    // Ensure the default revision is not changed during the sync.
    $reloaded_default_revision = $storage->load($entity->id());
    $this->assertEquals($default_revision_id, $reloaded_default_revision->getRevisionId());
    $this->assertEquals([
        'foo',
        'qux',
        'baz',
    ], $this->getAllRevisionNames($reloaded_default_revision));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.