function ContentModerationSyncingTest::testSingleRevisionStateChangedDuringSync

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

Tests changing the moderation state during a sync.

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testSingleRevisionStateChangedDuringSync() : void {
    $entity = EntityTestMulRevPub::create([
        'moderation_state' => 'published',
        'name' => 'foo',
    ]);
    $entity->save();
    $initial_revision_id = $entity->getRevisionId();
    $this->assertTrue($entity->isDefaultRevision());
    $this->assertTrue($entity->isPublished());
    $entity->setSyncing(TRUE);
    $entity->moderation_state = 'draft';
    $entity->save();
    // If a moderation state is changed to a draft while syncing, it will revert
    // to the same properties of an item of content that was initially created
    // as a draft.
    $this->assertEquals($initial_revision_id, $entity->getRevisionId());
    $this->assertFalse($entity->isPublished());
    $this->assertTrue($entity->isDefaultRevision());
    $this->assertEquals('draft', $entity->moderation_state->value);
}

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