You are here

function ActivityAPITest::testInsertActivity in Activity 5.4

Same name and namespace in other branches
  1. 5.2 tests/ActivityAPITests.test \ActivityAPITest::testInsertActivity()
  2. 5.3 tests/ActivityAPITests.test \ActivityAPITest::testInsertActivity()
  3. 6 tests/ActivityAPITests.test \ActivityAPITest::testInsertActivity()

function activity_insert($module, $type, $operation, $data, $target_users_roles)

  • the return value should be 1 greater than the previous greatest activity.

File

tests/ActivityAPITests.test, line 57

Class

ActivityAPITest

Code

function testInsertActivity() {

  //insert some permutations of activites.
  $module = 'simpletest';
  $type = 'testing';
  $operation = 'insert';
  $data = array(
    'dummydata' => 'foobar',
  );
  $target_users_roles = array(
    ACTIVITY_ALL => 'All',
    '4711' => 'Court Jester',
    '4712' => 'King of Spades',
  );
  $aid = activity_insert($module, $type, $operation, $data, $target_users_roles);

  // $aid is supposed to be the id of the resultant insert. Assert that it is.
  $this
    ->assertTrue(is_numeric($aid), '%s ' . t('activity_insert is supposed to return a numeric id'));

  // $aid is supposed to have incremented by 1 over the begninng.
  $this
    ->assertEqual($aid, $this->sequences_id + 1, '%s ' . t('the insert created an aid that is one greater than the previous.'));

  // Manually get the information from the activity table which we just put in.
  $activity = db_fetch_object(db_query("SELECT * FROM {activity} WHERE aid = %d", $aid));
  $this
    ->assertEqual($activity->module, $module, '%s ' . t('module is supposed to be @module', array(
    '@module' => $module,
  )));
  $this
    ->assertEqual($activity->type, $type, '%s ' . t('type is supposed to be @type', array(
    '@type' => $type,
  )));
  $this
    ->assertEqual($activity->operation, $operation, '%s ' . t('operation is supposed to be @action', array(
    '@action' => $operation,
  )));
  $new_data = unserialize($activity->data);
  $this
    ->assertTrue(is_array($new_data), '%s ' . t('Supposed to be an array'));
  $this
    ->assertTrue(count(array_diff($new_data, $data)) === 0, '%s ' . t('There are supposed to be no differences between the data arrays'));
}