function ActivityAPITest::testInsertActivity in Activity 5.2
Same name and namespace in other branches
- 5.4 tests/ActivityAPITests.test \ActivityAPITest::testInsertActivity()
- 5.3 tests/ActivityAPITests.test \ActivityAPITest::testInsertActivity()
- 6 tests/ActivityAPITests.test \ActivityAPITest::testInsertActivity()
- ability to pass in user or null
- when null global user should be used.
- the return value should be 1 greater than the previous greatest activity.
File
- tests/
ActivityAPITests.test, line 50
Class
Code
function testInsertActivity() {
//insert some permutations of activites.
$tokens = array(
'dummydata' => 'foobar',
);
$module = 'simpletest';
$type = 'testing';
$action = 'insert';
$uid = 4711;
$aid = activity_insert($module, $type, $action, $tokens, $uid);
// $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->uid, $uid, '%s ' . t('uid is supposed to be @uid', array(
'@uid' => $uid,
)));
$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->action, $action, '%s ' . t('action is supposed to be @action', array(
'@action' => $action,
)));
$new_tokens = unserialize($activity->tokens);
$this
->assertTrue(is_array($new_tokens), '%s ' . t('Supposed to be an array'));
$this
->assertTrue(count(array_diff($new_tokens, $tokens)) === 0, '%s ' . t('There are supposed to be no differences between the tokens arrays'));
// Test that not passing a $user_id results in the global $user->uid being used.
global $user;
$global_uid = $user->uid;
$aid2 = activity_insert($module, $type, $action, serialize($tokens));
// $aid is supposed to be the id of the resultant insert. Assert that it is.
$this
->assertTrue(is_numeric($aid2), '%s ' . t('activity_insert is supposed to return a numeric id'));
// $aid is supposed to have incremented by 2 over the begninng.
$this
->assertEqual($aid2, $this->sequences_id + 2, '%s ' . t('the insert created an aid that is two greater than the beginning.'));
// Now assert that the $global_uid and the inserted uid are the same.
$activity2 = db_fetch_object(db_query("SELECT * FROM {activity} WHERE aid = %d", $aid2));
$this
->assertEqual($global_uid, $activity2->uid, '%s ' . t('The inserted uid (@uid1) is supposed to be equal to the global $user->uid (@uid2).', array(
'@uid1' => $aid2,
'@uid2' => $activity2->uid,
)));
}