You are here

protected function AuthcacheCommentTest::postComment in Authenticated User Page Caching (Authcache) 7.2

Post comment.

See also

CommentHelperCase::postComment()

9 calls to AuthcacheCommentTest::postComment()
AuthcacheCommentTest::testCommentAttributionWithFormCache in modules/authcache_comment/authcache_comment.test
Test that comments get properly attributed when the form cache is in use.
AuthcacheCommentTest::testEditLinkNoSubstitutionForEditor in modules/authcache_comment/authcache_comment.test
Test the edit-link for admin role.
AuthcacheCommentTest::testEditLinkNoSubstitutionWhenEditNotAllowed in modules/authcache_comment/authcache_comment.test
Test the edit-link when edit is not allowed.
AuthcacheCommentTest::testEditLinkSubstitutionWhenEditAllowed in modules/authcache_comment/authcache_comment.test
Test the edit-link when edit own is allowed.
AuthcacheCommentTest::testNewMarkerRemoval in modules/authcache_comment/authcache_comment.test
Test removal of the new marker.

... See full list

File

modules/authcache_comment/authcache_comment.test, line 89
Test cases for the Authcache Comment module.

Class

AuthcacheCommentTest
Tests for markup substitution.

Code

protected function postComment($node, $comment, $subject = '', $contact = NULL, $extra_post = NULL) {
  $langcode = LANGUAGE_NONE;
  $edit = array();
  $edit['comment_body[' . $langcode . '][0][value]'] = $comment;
  $preview_mode = variable_get('comment_preview_article', DRUPAL_OPTIONAL);
  $subject_mode = variable_get('comment_subject_field_article', 1);

  // Must get the page before we test for fields.
  if ($node !== NULL) {
    $this
      ->drupalGet('comment/reply/' . $node->nid);
  }
  if ($subject_mode == TRUE) {
    $edit['subject'] = $subject;
  }
  else {
    $this
      ->assertNoFieldByName('subject', '', 'Subject field not found.');
  }
  if ($contact !== NULL && is_array($contact)) {
    $edit += $contact;
  }
  switch ($preview_mode) {
    case DRUPAL_REQUIRED:

      // Preview required so no save button should be found.
      $this
        ->assertNoFieldByName('op', t('Save'), 'Save button not found.');
      $this
        ->drupalPost(NULL, $edit, t('Preview'), array(), array(), NULL, $extra_post);

    // Don't break here so that we can test post-preview field presence and
    // function below.
    case DRUPAL_OPTIONAL:
      $this
        ->assertFieldByName('op', t('Preview'), 'Preview button found.');
      $this
        ->assertFieldByName('op', t('Save'), 'Save button found.');
      $this
        ->drupalPost(NULL, $edit, t('Save'), array(), array(), NULL, $extra_post);
      break;
    case DRUPAL_DISABLED:
      $this
        ->assertNoFieldByName('op', t('Preview'), 'Preview button not found.');
      $this
        ->assertFieldByName('op', t('Save'), 'Save button found.');
      $this
        ->drupalPost(NULL, $edit, t('Save'), array(), array(), NULL, $extra_post);
      break;
  }
  $match = array();

  // Get comment ID.
  preg_match('/#comment-([0-9]+)/', $this
    ->getURL(), $match);

  // Get comment.
  if ($contact !== TRUE) {
    if ($subject) {
      $this
        ->assertText($subject, 'Comment subject posted.');
    }
    $this
      ->assertText($comment, 'Comment body posted.');
    $this
      ->assertTrue(!empty($match) && !empty($match[1]), 'Comment id found.');
  }
  if (isset($match[1])) {
    return (object) array(
      'id' => $match[1],
      'subject' => $subject,
      'comment' => $comment,
    );
  }
}