You are here

public function PublishedStateConstraintTest::testInvalidPublishStateTransition in Scheduler content moderation integration 8

Test invalid publish state transitions.

@covers ::validate

File

tests/src/Kernel/PublishedStateConstraintTest.php, line 51

Class

PublishedStateConstraintTest
Test covering the PublishedStateConstraintValidator.

Namespace

Drupal\Tests\scheduler_content_moderation_integration\Kernel

Code

public function testInvalidPublishStateTransition() {
  $node = Node::create([
    'type' => 'example',
    'title' => 'Test title',
    'moderation_state' => 'draft',
    'publish_on' => strtotime('tomorrow'),
    'publish_state' => 'archived',
  ]);

  // Assert that the invalid publish state fails validation, we get two
  // violations since the draft state does not exist.
  $violations = $node
    ->validate();
  $this
    ->assertEquals('The scheduled publishing state of <em class="placeholder">archived</em> is not a valid transition from the current moderation state of <em class="placeholder">draft</em> for this content.', $violations
    ->get(0)
    ->getMessage());

  // @todo Figure out how to actually test this with valid options that don't
  // break the select list widget but still test the invalid transition.
  // $this->assertCount(1, $violations);
}