function ModerationInformationTest::testHasPendingRevision

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

@covers ::hasPendingRevision

File

core/modules/content_moderation/tests/src/Kernel/ModerationInformationTest.php, line 218

Class

ModerationInformationTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21content_moderation%21src%21ModerationInformation.php/class/ModerationInformation/8.9.x" title="General service for moderation-related questions about Entity API." class="local">\Drupal\content_moderation\ModerationInformation</a> @group content_moderation

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testHasPendingRevision() {
    $entity = EntityTestMulRevPub::create([
        'moderation_state' => 'published',
    ]);
    $entity->save();
    // Add a translation as a new revision.
    $translated = $entity->addTranslation('de');
    $translated->moderation_state = 'published';
    $translated->setNewRevision(TRUE);
    // Test a scenario where the default revision exists with the default
    // language in a published state and a non-default language in an unsaved
    // state.
    $this->assertFalse($this->moderationInformation
        ->hasPendingRevision($translated));
    // Save the translation and assert there is no pending revision.
    $translated->save();
    $this->assertFalse($this->moderationInformation
        ->hasPendingRevision($translated));
    // Create a new draft for the translation and assert there is a pending
    // revision.
    $translated->moderation_state = 'draft';
    $translated->setNewRevision(TRUE);
    $translated->save();
    $this->assertTrue($this->moderationInformation
        ->hasPendingRevision($translated));
}

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