function 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\KernelCode
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.