You are here

public function DiffRevisionContentModerationTest::testContentModeration in Diff 8

Test content moderation integration.

File

tests/src/Functional/DiffRevisionContentModerationTest.php, line 62

Class

DiffRevisionContentModerationTest
Tests the revision overview with content moderation enabled.

Namespace

Drupal\Tests\diff\Functional

Code

public function testContentModeration() {
  $this
    ->loginAsAdmin();
  $title = $this
    ->randomString();
  $node = $this
    ->createNode([
    'type' => 'article',
    'title' => $title,
    'revision_log' => 'First revision',
  ]);

  // Add another draft.
  $node->title = $title . ' change 1';
  $node->revision_log = 'Second revision';
  $node
    ->save();

  // Publish.
  $node->moderation_state = 'published';
  $node->revision_log = 'Third revision';
  $node
    ->save();

  // Another draft.
  $node->title = $title . ' change 2';
  $node->moderation_state = 'draft';
  $node->revision_log = 'Fourth revision';
  $node
    ->save();

  // Verify moderation state information appears on revision overview.
  $this
    ->drupalGet($node
    ->toUrl('version-history'));

  // Verify proper moderation states are displayed.
  $diff_rows = $this
    ->xpath('//tbody/tr/td[1]/p');
  $this
    ->assertEqual('Fourth revision (Draft)', $diff_rows[0]
    ->getText());
  $this
    ->assertEqual('Third revision (Published)', $diff_rows[1]
    ->getText());
  $this
    ->assertEqual('Second revision (Draft)', $diff_rows[2]
    ->getText());
  $this
    ->assertEqual('First revision (Draft)', $diff_rows[3]
    ->getText());
}