You are here

private function ForumAccessTestCase::testForumAccessCreateReply in Forum Access 6

This function test if the user can create a reply on a comment Three steps: is there a create link, does the create reply page opens and can the new reply on a comment be saved

1 call to ForumAccessTestCase::testForumAccessCreateReply()
ForumAccessTestCase::testForumAccessRun in ./forum_access.test
The main function which is used to start testing a specific forum configuration.

File

./forum_access.test, line 899
Test file for forum_access.module.

Class

ForumAccessTestCase
This is the base class for forum access testing.

Code

private function testForumAccessCreateReply($topic_id = 0, $comment_id = 0) {
  if (intval($topic_id) > 0 && intval($comment_id) > 0) {
    $allowed = $this
      ->testForumAccessAllowed('comment_create');

    // Check to see if the reply link is on the view page
    $this
      ->drupalGet('node/' . $topic_id, array(
      'fragment' => 'comment-' . $comment_id,
    ));
    if ($allowed) {
      if (!$this
        ->assertPattern("/comment\\/reply\\/{$topic_id}\\/{$comment_id}/", t('For @user there should be a reply link on this comment on the page: @page', array(
        '@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('comment', $comment_id);
      }
    }
    else {
      if (!$this
        ->assertNoPattern("/comment\\/reply\\/{$topic_id}\\/{$comment_id}/", t('For @user there should NOT be any reply link on this comment on the page: @page', array(
        '@user' => $this->loggedInUser ? t('this user') : t('anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('comment', $comment_id);
      }
    }

    // Check to see if the user/anonymous is allowed to open the reply page
    $page_opened = FALSE;
    $this
      ->drupalGet('comment/reply/' . $topic_id . '/' . $comment_id);
    if ($allowed) {
      if (!$this
        ->assertNoTextArray(array(
        "not authorized",
        "not exist",
      ), t('@user should be allowed to open the reply page for this comment: @page', array(
        '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('comment', $comment_id);
      }
      else {
        $page_opened = TRUE;
      }
    }
    else {
      if (!$this
        ->assertTextArray(array(
        "not authorized",
        "not exist",
      ), t('@user should NOT be allowed to open the reply page for this comment: @page', array(
        '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
        '@page' => $this
          ->getUrl(),
      )))) {
        $this
          ->testForumAccessDumpDebugInfo('comment', $comment_id);
        $page_opened = TRUE;
      }
    }
    if ($page_opened) {

      // Check to see if the user/anonymous is allowed to reply the comment
      $comment_options = array(
        'subject' => 'Comment subject: ' . $this
          ->randomName(32),
        'comment' => 'Comment comment: ' . $this
          ->randomName(64),
      );
      $this
        ->drupalPost('comment/reply/' . $topic_id . '/' . $comment_id, $comment_options, t('Preview'));
      $this
        ->drupalPost(NULL, $comment_options, t('Save'));
      if ($allowed) {
        if ($this
          ->assertNoText("not authorized", t('@user should be allowed to reply on this comment: @page', array(
          '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
          '@page' => $this
            ->getUrl(),
        )))) {

          //preg_match_all('/node\/(?<topic_id>\d+)#comment-(?<comment_id>\d+)/', $this->url, $matches);

          //return (array_key_exists('comment_id', $matches) ? intval($matches['comment_id']) : 0);
          return TRUE;
        }
        else {
          $this
            ->testForumAccessDumpDebugInfo('comment', $comment_id);
        }
      }
      else {
        if (!$this
          ->assertText("not authorized", t('@user should NOT be allowed to reply on this comment: @page', array(
          '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
          '@page' => $this
            ->getUrl(),
        )))) {
          $this
            ->testForumAccessDumpDebugInfo('comment', $comment_id);

          //preg_match_all('/node\/(?<topic_id>\d+)#comment-(?<comment_id>\d+)/', $this->url, $matches);

          //return (array_key_exists('comment_id', $matches) ? intval($matches['comment_id']) : 0);
        }
      }
    }
  }
  return FALSE;
}