function ModerationStateFieldItemListTest::testModerationStateSampleValues

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

Test generating sample values for entities with a moderation state.

File

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

Class

ModerationStateFieldItemListTest
@coversDefaultClass \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList[[api-linebreak]]

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testModerationStateSampleValues() : void {
  $this->container
    ->get('current_user')
    ->setAccount($this->createUser([
    'use editorial transition create_new_draft',
    'use editorial transition publish',
  ]));
  $sample = $this->container
    ->get('entity_type.manager')
    ->getStorage('node')
    ->createWithSampleValues('example');
  $this->assertCount(0, $sample->validate());
  $this->assertEquals('draft', $sample->moderation_state->value);
}

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