You are here

function PagePreviewTest::testPagePreviewWithRevisions in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/node/src/Tests/PagePreviewTest.php \Drupal\node\Tests\PagePreviewTest::testPagePreviewWithRevisions()

Checks the node preview functionality, when using revisions.

File

core/modules/node/src/Tests/PagePreviewTest.php, line 271
Contains \Drupal\node\Tests\PagePreviewTest.

Class

PagePreviewTest
Tests the node entity preview functionality.

Namespace

Drupal\node\Tests

Code

function testPagePreviewWithRevisions() {
  $title_key = 'title[0][value]';
  $body_key = 'body[0][value]';
  $term_key = $this->fieldName . '[target_id]';

  // Force revision on "Basic page" content.
  $node_type = NodeType::load('page');
  $node_type
    ->setNewRevision(TRUE);
  $node_type
    ->save();

  // Fill in node creation form and preview node.
  $edit = array();
  $edit[$title_key] = $this
    ->randomMachineName(8);
  $edit[$body_key] = $this
    ->randomMachineName(16);
  $edit[$term_key] = $this->term
    ->id();
  $edit['revision_log[0][value]'] = $this
    ->randomString(32);
  $this
    ->drupalPostForm('node/add/page', $edit, t('Preview'));

  // Check that the preview is displaying the title, body and term.
  $this
    ->assertTitle(t('@title | Drupal', array(
    '@title' => $edit[$title_key],
  )), 'Basic page title is preview.');
  $this
    ->assertText($edit[$title_key], 'Title displayed.');
  $this
    ->assertText($edit[$body_key], 'Body displayed.');
  $this
    ->assertText($edit[$term_key], 'Term displayed.');

  // Check that the title and body fields are displayed with the correct
  // values after going back to the content edit page.
  $this
    ->clickLink(t('Back to content editing'));
  $this
    ->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
  $this
    ->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
  $this
    ->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.');

  // Check that the revision log field has the correct value.
  $this
    ->assertFieldByName('revision_log[0][value]', $edit['revision_log[0][value]'], 'Revision log field displayed.');
}