You are here

public function ModerationFormTest::testNonBundleModerationForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php \Drupal\Tests\content_moderation\Functional\ModerationFormTest::testNonBundleModerationForm()

Tests moderation non-bundle entity type.

File

core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php, line 187

Class

ModerationFormTest
Tests the moderation form, specifically on nodes.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testNonBundleModerationForm() {
  $this
    ->drupalLogin($this->rootUser);
  $this->workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub');
  $this->workflow
    ->save();

  // Create new moderated content in draft.
  $this
    ->drupalGet('entity_test_mulrevpub/add');
  $this
    ->submitForm([
    'moderation_state[0][state]' => 'draft',
  ], 'Save');

  // The latest version page should not show, because there is no pending
  // revision.
  $this
    ->drupalGet('/entity_test_mulrevpub/manage/1/latest');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Update the draft.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1/edit');
  $this
    ->submitForm([
    'moderation_state[0][state]' => 'draft',
  ], 'Save');

  // The latest version page should not show, because there is still no
  // pending revision.
  $this
    ->drupalGet('/entity_test_mulrevpub/manage/1/latest');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Publish the draft.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1/edit');
  $this
    ->submitForm([
    'moderation_state[0][state]' => 'published',
  ], 'Save');

  // The published view should not have a moderation form, because it is the
  // default revision.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextNotContains('Status');

  // The latest version page should not show, because there is still no
  // pending revision.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1/latest');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Make a pending revision.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1/edit');
  $this
    ->submitForm([
    'moderation_state[0][state]' => 'draft',
  ], 'Save');

  // The published view should not have a moderation form, because it is the
  // default revision.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextNotContains('Status');

  // The latest version page should show the moderation form and have "Draft"
  // status, because the pending revision is in "Draft".
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1/latest');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Moderation state');
  $this
    ->assertSession()
    ->pageTextContains('Draft');

  // Submit the moderation form to change status to published.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1/latest');
  $this
    ->submitForm([
    'new_state' => 'published',
  ], 'Apply');

  // The latest version page should not show, because there is no
  // pending revision.
  $this
    ->drupalGet('entity_test_mulrevpub/manage/1/latest');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}