You are here

protected function ModerationStateFieldItemListTest::assertEmptiedModerationFieldItemList in Drupal 10

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

Assert the set of expectations when the moderation state field is emptied.

@internal

File

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

Class

ModerationStateFieldItemListTest
@coversDefaultClass \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList

Namespace

Drupal\Tests\content_moderation\Kernel

Code

protected function assertEmptiedModerationFieldItemList() : void {
  $this
    ->assertTrue($this->testNode->moderation_state
    ->isEmpty());

  // Test the empty value causes a violation in the entity.
  $violations = $this->testNode
    ->validate();
  $this
    ->assertCount(1, $violations);
  $this
    ->assertEquals('This value should not be null.', $violations
    ->get(0)
    ->getMessage());

  // Test that incorrectly saving the entity regardless will not produce a
  // change in the moderation state.
  $this->testNode
    ->save();
  $this
    ->assertEquals('draft', Node::load($this->testNode
    ->id())->moderation_state->value);
}