You are here

public function UUIDCommentTestCase::testCommentCrud in Universally Unique IDentifier 7

Test CRUD on comments with UUID functions.

File

./uuid.test, line 501
Test suite for UUID module.

Class

UUIDCommentTestCase
Tests the Comment implementation.

Code

public function testCommentCrud() {

  // This is sub optimal, but due to how CommentHelperCase::setUp() is
  // constructed we are enforced to do this. So unfortunately this test
  // depends on 'entity' module for now.
  module_enable(array(
    'uuid',
    'entity',
  ));
  $user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user);
  $node = $this
    ->drupalCreateNode();
  $return = $this
    ->postComment($node, 'Lorem ipsum');
  $comment = comment_load($return->id);
  $this
    ->assertUuid($comment->uuid, 'Comment UUID was generated.');

  // Test updating comment.
  $comment_test = clone $comment;
  $comment_test->subject = 'new subject';
  comment_save($comment_test);
  $comment_test = comment_load($comment->cid);
  $this
    ->assertEqual($comment_test->uuid, $comment->uuid, 'Comment UUID was intact after update.');

  // Test entity_uuid_load().
  $comments = entity_uuid_load('comment', array(
    $comment->uuid,
  ), array(), TRUE);
  $comment_test = reset($comments);
  $this
    ->assertEqual($comment_test->cid, $return->id, 'Comment was correctly loaded with UUID.');
  $this
    ->assertEqual($comment_test->uid, $user->uuid, "Comment property 'uid' was transformed to UUID when loaded with UUID.");
  $this
    ->assertEqual($comment_test->nid, $node->uuid, "Comment property 'nid' was transformed to UUID when loaded with UUID.");

  // The following tests depends on the optional Entity API module.
  if (module_exists('entity')) {

    // Test entity_uuid_save() for comments.
    $comments = entity_uuid_load('comment', array(
      $comment->uuid,
    ), array(), TRUE);
    $comment_test = reset($comments);
    $comment_test->cid = rand();
    $comment_test->subject = 'newer subject';
    entity_uuid_save('comment', $comment_test);
    $comment_test = comment_load($comment->cid);
    $this
      ->assertEqual($comment_test->subject, 'newer subject', 'Saving comment with UUID mapped to correct comment.');
    $this
      ->assertEqual($comment_test->uuid, $comment->uuid, 'Comment UUID was intact after saving with UUID.');
    $this
      ->assertEqual($comment_test->uid, $user->uid, "Comment property 'uid' was after saving with UUID.");
    $this
      ->assertEqual($comment_test->nid, $node->nid, "Comment property 'nid' was after saving with UUID.");

    // Test entity_uuid_delete() for comments.
    entity_uuid_delete('comment', $comment->uuid);
    $comment_test = comment_load($comment->cid);
    $this
      ->assertFalse($comment_test, 'Deleting comment with UUID worked.');
  }
}