You are here

public function ActivityUnitTest::testUserActivityInsert in Activity 7

File

tests/activity_unit.test, line 317

Class

ActivityUnitTest

Code

public function testUserActivityInsert() {
  $handler = activity_load_handler('user_insert');
  $handler->templates = array(
    'en' => array(
      'user' => 'Registered User',
      'public' => 'Public Message',
    ),
  );
  $handler->options = array(
    'roles' => array(),
  );
  $handler->actions_id = -1;
  $handler->label = 'Test user insert';
  $objects1['user'] = (object) array(
    'uid' => 7,
    'status' => 1,
    'created' => REQUEST_TIME - 68,
    'roles' => array(
      1 => 'admin',
    ),
  );
  $objects2['user'] = (object) array(
    'uid' => 45,
    'status' => 0,
    'created' => REQUEST_TIME - 678,
    'roles' => array(
      2 => 'other_role',
    ),
  );

  // Ensure the proper eid is returned.
  $this
    ->assertEqual($objects1['user']->uid, $handler
    ->determineEid(array(
    'account' => $objects1['user'],
  )), t('Proper Eid is returned'));

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

  // Check timestamp.
  $this
    ->assertEqual($objects1['user']->created, $handler
    ->determineTimestamp($objects1), t('Returned proper timestamp'));

  // Check published flag.
  $this
    ->assertTrue($handler
    ->isPublished($objects1, $objects1['user']->uid), t('Correctly flagged user insert activity as published'));
  $this
    ->assertTrue(!$handler
    ->isPublished($objects2, $objects2['user']->uid), t('Correctly flagged user insert activity as unpublished.'));

  // Check Role validation
  $handler->options = array(
    'roles' => array(
      1,
    ),
  );
  $this
    ->assertTrue($handler
    ->valid($objects1['user']->uid, $objects1['user']->uid, REQUEST_TIME, $objects1, NULL, NULL), t('Correctly marked a user registeration with role 1 as valid'));
  $this
    ->assertTrue(!$handler
    ->valid($objects2['user']->uid, $objects2['user']->uid, REQUEST_TIME, $objects2, NULL, NULL), t('Correctly marked a user registeration without role 1 as invalid'));
  $this
    ->assertEqual($handler
    ->determineNid($objects1), NULL, t('Returned proper a NULL nid'));
}