You are here

public function ActivityUnitTest::testCommentActivityInsert in Activity 7

File

tests/activity_unit.test, line 233

Class

ActivityUnitTest

Code

public function testCommentActivityInsert() {
  $handler = activity_load_handler('comment_insert');
  $handler->templates = array(
    'en' => array(
      'comment' => 'Comment Author Message',
      'node' => 'Node Author Message',
      'node_comment' => 'Node and Comment Message',
      'public' => 'Public Message',
    ),
  );
  $handler->options = array(
    'types' => array(),
    'view_modes' => array(),
  );
  $handler->actions_id = -1;
  $handler->label = 'Test comment insert';
  $node1 = (object) array(
    'nid' => 1,
    'vid' => 1,
    'uid' => 0,
    // Avoids the window check, which queries the users table.
    'type' => 'article',
    'language' => 'und',
    'title' => 'Test1',
    'created' => REQUEST_TIME,
    'status' => 1,
  );
  $node2 = (object) array(
    'nid' => 2,
    'vid' => 2,
    'uid' => 0,
    'type' => 'page',
    'language' => 'und',
    'title' => 'Test2',
    'created' => REQUEST_TIME,
    'status' => 0,
  );
  $comment1 = (object) array(
    'cid' => 1,
    'uid' => 0,
    'created' => REQUEST_TIME,
    'status' => 1,
  );
  $comment2 = (object) array(
    'cid' => 1,
    'uid' => 0,
    'created' => REQUEST_TIME,
    'status' => 0,
  );
  $objects1 = array(
    'node' => $node1,
    'comment' => $comment1,
  );
  $objects2 = array(
    'node' => $node2,
    'comment' => $comment2,
  );

  // Ensure the proper eid is returned.
  $this
    ->assertEqual($comment1->cid, $handler
    ->determineEid($objects1), t('Proper Eid is returned'));

  // Ensure the proper actor is returned.
  $this
    ->assertEqual($comment1->uid, $handler
    ->determineActor($objects1), t('Proper Actor id is returned'));

  // Check timestamp.
  $this
    ->assertEqual($comment1->created, $handler
    ->determineTimestamp($objects2), t('Returned proper timestamp'));

  // Check published flag.
  $this
    ->assertTrue($handler
    ->isPublished($objects1, $comment1->uid), t('Correctly flagged comment activity as published'));
  $this
    ->assertTrue(!$handler
    ->isPublished($objects2, $comment2->uid), t('Correctly flagged comment activity as not published'));
  $this
    ->assertEqual($handler
    ->determineNid($objects1), $objects1['node']->nid, t('Returned proper nid'));

  // Test to make sure getUid functions properly.
  $objects1['node']->uid = 2;
  $objects1['comment']->uid = 3;
  $messages = $handler
    ->tokenize($objects1);
  $this
    ->assertTrue(isset($messages['en']), t('English Messages are returned'));
  $this
    ->assertEqual($messages['en'][$objects1['comment']->uid], $handler->templates['en']['comment'], t('Comment author message is properly returned'));
  $this
    ->assertEqual($messages['en'][$objects1['node']->uid], $handler->templates['en']['node'], t('Node author message is properly returned'));
  $this
    ->assertEqual($messages['en'][$objects1['comment']->uid], $handler->templates['en']['comment'], t('Comment author message is properly returned'));
  $this
    ->assertEqual($messages['en'][0], $handler->templates['en']['public'], t('Properly return the public message'));

  // Check that the comment author == node author case.
  $objects1['comment']->uid = $objects1['node']->uid;
  $messages = $handler
    ->tokenize($objects1);
  $this
    ->assertEqual($messages['en'][$objects1['node']->uid], $handler->templates['en']['node_comment'], t('Comment and Node author message is properly handled'));
}