You are here

public function ModerationFormTest::testNonBundleModerationForm in Drupal 8

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

Test moderation non-bundle entity type.

File

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

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
    ->drupalPostForm('entity_test_mulrevpub/add', [
    'moderation_state[0][state]' => 'draft',
  ], t('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
    ->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [
    'moderation_state[0][state]' => 'draft',
  ], t('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
    ->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [
    'moderation_state[0][state]' => 'published',
  ], t('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
    ->assertNoText('Status', 'The node view page has no moderation form.');

  // 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
    ->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [
    'moderation_state[0][state]' => 'draft',
  ], t('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
    ->assertNoText('Status', 'The node view page has no moderation form.');

  // 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
    ->assertText('Moderation state', 'Form text found on the latest-version page.');
  $this
    ->assertText('Draft', 'Correct status found on the latest-version page.');

  // Submit the moderation form to change status to published.
  $this
    ->drupalPostForm('entity_test_mulrevpub/manage/1/latest', [
    'new_state' => 'published',
  ], t('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);
}