You are here

public function ModerationFormTest::testModerationFormSetsRevisionAuthor 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::testModerationFormSetsRevisionAuthor()
  2. 10 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 249

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
    ->drupalPostForm(sprintf('node/%d/latest', $node
    ->id()), [
    'new_state' => 'published',
  ], t('Apply'));
  $this
    ->drupalGet(sprintf('node/%d/revisions', $node
    ->id()));
  $this
    ->assertText('by ' . $another_user
    ->getAccountName());

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