You are here

function CommentGoodnessDeleteOwnTestCase::testCommentDeleteOwn in Comment goodness 7

Test if the user can delete her own content.

File

tests/comment_goodness.test, line 78

Class

CommentGoodnessDeleteOwnTestCase
Test the deletion of own comments.

Code

function testCommentDeleteOwn() {
  $this
    ->drupalLogin($this->admin_user);
  $langcode = LANGUAGE_NONE;
  $title_key = "title";
  $body_key = "body[{$langcode}][0][value]";

  // Create node to comment on with admin user.
  $edit = array();
  $edit[$title_key] = $this
    ->randomName(8);
  $edit[$body_key] = $this
    ->randomName(16);
  $this
    ->drupalPost('node/add/article', $edit, t('Save'));
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->web_user);

  // Post comment on previously created node with an authenticated
  // (non-admin) user.
  $node = $this
    ->drupalGetNodeByTitle($edit[$title_key]);
  $comment_text = $this
    ->randomName();
  $comment = $this
    ->postComment($node, $comment_text);
  $this
    ->assertTrue($this
    ->commentExists($comment), t('Comment found.'));

  // Delete own comment.
  $this
    ->drupalPost("comment/{$comment->id}/delete-own", NULL, t('Delete'));

  // Confirm own comment got deleted.
  $this
    ->assertFalse(comment_load($comment->id), t('Own comment deleted.'));
  $this
    ->drupalLogout();
}