You are here

public function ModerationFormTest::testModerationFormSetsRevisionAuthor 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::testModerationFormSetsRevisionAuthor()

Tests the revision author is updated when the moderation form is used.

File

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

Class

ModerationFormTest
Tests the moderation form, specifically on nodes.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testModerationFormSetsRevisionAuthor() {

  // Create new moderated content in published.
  $node = $this
    ->createNode([
    'type' => 'moderated_content',
    'moderation_state' => 'published',
  ]);

  // Make a pending revision.
  $node->title = $this
    ->randomMachineName();
  $node->moderation_state->value = 'draft';
  $node
    ->setRevisionCreationTime(12345);
  $node
    ->save();
  $another_user = $this
    ->drupalCreateUser($this->permissions);
  $this
    ->grantUserPermissionToCreateContentOfType($another_user, 'moderated_content');
  $this
    ->drupalLogin($another_user);
  $this
    ->drupalGet(sprintf('node/%d/latest', $node
    ->id()));
  $this
    ->submitForm([
    'new_state' => 'published',
  ], 'Apply');
  $this
    ->drupalGet(sprintf('node/%d/revisions', $node
    ->id()));
  $this
    ->assertSession()
    ->pageTextContains('by ' . $another_user
    ->getAccountName());

  // Verify the revision creation time has been updated.
  $node = $node
    ->load($node
    ->id());
  $this
    ->assertGreaterThan(12345, $node
    ->getRevisionCreationTime());
}