1 comment.test CommentPreviewTest::testCommentPreview()

Tests comment preview.


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


Tests previewing comments.


function testCommentPreview() {
  $langcode = LANGUAGE_NONE;

  // As admin user, configure comment settings.
  $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');

  // Login as web user and add a signature and a user picture.
    ->set('user_signatures', 1)
    ->set('user_pictures', 1)
  $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.

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