1 token.test TokenCommentTestCase::testCommentTokens()

File

core/modules/simpletest/tests/token.test, line 408
Test integration for the token module.

Class

TokenCommentTestCase

Code

function testCommentTokens() {
  $node = $this->backdropCreateNode(array('comment' => COMMENT_NODE_OPEN));

  $parent_comment = new Comment();
  $parent_comment->nid = $node->nid;
  $parent_comment->pid = 0;
  $parent_comment->cid = NULL;
  $parent_comment->uid = 0;
  $parent_comment->name = 'anonymous user';
  $parent_comment->mail = 'anonymous@example.com';
  $parent_comment->subject = $this->randomName();
  $parent_comment->timestamp = mt_rand($node->created, REQUEST_TIME);
  $parent_comment->language = LANGUAGE_NONE;
  $parent_comment->body[LANGUAGE_NONE][0] = $this->randomName();
  comment_save($parent_comment);

  $tokens = array(
    'url' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
    'url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
    'url:relative' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => FALSE)),
    'url:path' => 'comment/' . $parent_comment->cid,
    'parent:url:absolute' => NULL,
  );
  $this->assertTokens('comment', array('comment' => $parent_comment), $tokens);

  $comment = new Comment();
  $comment->nid = $node->nid;
  $comment->pid = $parent_comment->cid;
  $comment->cid = NULL;
  $comment->uid = 1;
  $comment->subject = $this->randomName();
  $comment->timestamp = mt_rand($parent_comment->created, REQUEST_TIME);
  $comment->language = LANGUAGE_NONE;
  $comment->body[LANGUAGE_NONE][0] = $this->randomName();
  comment_save($comment);

  $tokens = array(
    'url' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
    'url:absolute' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => TRUE)),
    'url:relative' => url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid, 'absolute' => FALSE)),
    'url:path' => 'comment/' . $comment->cid,
    'parent:url:absolute' => url('comment/' . $parent_comment->cid, array('fragment' => 'comment-' . $parent_comment->cid, 'absolute' => TRUE)),
  );
  $this->assertTokens('comment', array('comment' => $comment), $tokens);
}