1 comment.test CommentPreviewTest::testCommentPreview()

Tests comment preview.

File

core/modules/comment/tests/comment.test, line 1015
Tests for the Comment module.

Class

CommentPreviewTest
Tests previewing comments.

Code

function testCommentPreview() {
  $langcode = LANGUAGE_NONE;

  // As admin user, configure comment settings.
  $this->backdropLogin($this->admin_user);
  $this->setCommentPreview(BACKDROP_OPTIONAL);
  $this->setCommentForm(TRUE);
  $this->setCommentSubject(TRUE);
  $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
  $this->backdropLogout();

  // Login as web user and add a signature and a user picture.
  $this->backdropLogin($this->web_user);
  config('system.core')
    ->set('user_signatures', 1)
    ->set('user_pictures', 1)
    ->save();
  $test_signature = $this->randomName();
  $edit['signature[value]'] = '<a href="http://example.com/">' . $test_signature . '</a>';
  $edit['signature[format]'] = 'filtered_html';
  $image = current($this->backdropGetTestFiles('image'));
  $edit['files[picture_upload]'] = backdrop_realpath($image->uri);
  $this->backdropPost('user/' . $this->web_user->uid . '/edit', $edit, t('Save'));

  // As the web user, fill in the comment form and preview the comment.
  $edit = array();
  $edit['subject'] = $this->randomName(8);
  $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16);
  $this->backdropPost('node/' . $this->node->nid, $edit, t('Preview'));

  // Check that the preview is displaying the title and body.
  $this->assertTitle(t('Preview comment | Backdrop CMS'), 'Page title is "Preview comment".');
  $this->assertText($edit['subject'], 'Title displayed.');
  $this->assertText($edit['comment_body[' . $langcode . '][0][value]'], 'Comment displayed.');

  // Check that the title and body fields are displayed with the correct values.
  $this->assertFieldByName('subject', $edit['subject'], 'Title field displayed.');
  $this->assertFieldByName('comment_body[' . $langcode . '][0][value]', $edit['comment_body[' . $langcode . '][0][value]'], 'Comment field displayed.');

  // Check that the signature is displaying with the correct text format.
  $this->assertLink($test_signature);

  // Check that the user picture is displayed.
  $this->assertFieldByXPath("//article[contains(@class, 'comment-preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
}