function ModerationStateFieldItemListTest::testWithExistingUnmoderatedContent

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

Test the field item list when used with existing unmoderated content.

File

core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php, line 374

Class

ModerationStateFieldItemListTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21content_moderation%21src%21Plugin%21Field%21ModerationStateFieldItemList.php/class/ModerationStateFieldItemList/8.9.x" title="A computed field that provides a content entity&#039;s moderation state." class="local">\Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList</a>

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testWithExistingUnmoderatedContent() {
    $node = Node::create([
        'title' => 'Test title',
        'type' => 'unmoderated',
    ]);
    $node->save();
    $translation = $node->addTranslation('de', $node->toArray());
    $translation->title = 'Translated';
    $translation->save();
    $workflow = Workflow::load('editorial');
    $workflow->getTypePlugin()
        ->addEntityTypeAndBundle('node', 'unmoderated');
    $workflow->save();
    // After enabling moderation, both the original node and translation should
    // have a published moderation state.
    $node = Node::load($node->id());
    $translation = $node->getTranslation('de');
    $this->assertEquals('published', $node->moderation_state->value);
    $this->assertEquals('published', $translation->moderation_state->value);
    // After the node has been updated, both the original node and translation
    // should still have a value.
    $node->title = 'Updated title';
    $node->save();
    $translation = $node->getTranslation('de');
    $this->assertEquals('published', $node->moderation_state->value);
    $this->assertEquals('published', $translation->moderation_state->value);
}

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