You are here

private function ForumAccessTestCase::testForumAccessDeleteComment in Forum Access 6

This function test if the user can delete a comment Three steps: is there a delete link, does the delete page opens and can the comment be deleted

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

File

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

Class

ForumAccessTestCase
This is the base class for forum access testing.

Code

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

    // Check to see if the delete link is on the view page
    $this
      ->drupalGet('node/' . $topic_id, array(
      'fragment' => 'comment-' . $comment_id,
    ));
    if ($allowed) {
      if (!$this
        ->assertPattern("/comment\\/delete\\/{$comment_id}/", t('For @user there should be a delete-this-comment-link 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\\/delete\\/{$comment_id}/", t('For @user there should NOT be a delete-this-comment-link 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 delete page
    $page_opened = FALSE;
    $this
      ->drupalGet('comment/delete/' . $comment_id);
    if ($allowed) {
      if (!$this
        ->assertNoText("not authorized", t('@user should be allowed to open the delete 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
        ->assertText("not authorized", t('@user should NOT be allowed to open the delete 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 edit the comment
      $this
        ->drupalPost('comment/delete/' . $comment_id, array(), t('Delete'));
      if ($allowed) {
        if (!$this
          ->assertNoText("not authorized", t('@user should be allowed to delete this comment: @page', array(
          '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
          '@page' => $this
            ->getUrl(),
        )))) {
          $this
            ->testForumAccessDumpDebugInfo('comment', $comment_id);
        }
      }
      else {
        if (!$this
          ->assertText("not authorized", t('@user should NOT be allowed to delete this comment: @page', array(
          '@user' => $this->loggedInUser ? t('The user') : t('Anonymous'),
          '@page' => $this
            ->getUrl(),
        )))) {
          $this
            ->testForumAccessDumpDebugInfo('comment', $comment_id);
        }
      }
    }
  }
}