class ActivityAPITest in Activity 5.3
Same name and namespace in other branches
- 5.4 tests/ActivityAPITests.test \ActivityAPITest
- 5.2 tests/ActivityAPITests.test \ActivityAPITest
- 6 tests/ActivityAPITests.test \ActivityAPITest
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \ActivityAPITest
Expanded class hierarchy of ActivityAPITest
File
- tests/
ActivityAPITests.test, line 3
View source
class ActivityAPITest extends DrupalTestCase {
private $beginning_aid;
private $sequences_id;
function get_info() {
return array(
'name' => t('Activity API tests'),
'desc' => t('Test activity_insert_activity and activity_get_activity'),
'group' => 'Activity Tests',
);
}
function setUp() {
parent::setUp();
//count current activities.
$this->beginning_aid = db_result(db_query("SELECT MAX(aid) FROM {activity}"));
//get the last id from sequences.
$this->sequences_id = db_result(db_query("SELECT id FROM {sequences} WHERE name = 'activity'"));
}
function tearDown() {
parent::tearDown();
db_query('DELETE FROM {activity} WHERE aid > %d', $this->beginning_aid);
db_query('DELETE FROM {activity_targets} WHERE aid > %d', $this->beginning_aid);
db_query("UPDATE {sequences} SET id = %d WHERE name = 'activity'", $this->sequences_id);
}
function testActivityGetInfo() {
$this
->drupalModuleEnable('nodeactivity');
// Assert that the api function activity_get_info exists
if ($this
->assertTrue(function_exists('activity_get_info'), '%s ' . t('Asserting that activity_get_info exists'))) {
// It exists. Let's call it.
$info = activity_get_info();
// The API's contract is to return an array.
$this
->assertTrue(is_array($info), '%s ' . t('Asserting that return value is an array.'));
// Assert that all of the modules we're looking for are in the array.
$this
->assertTrue(in_array('nodeactivity', array_keys($info)), '%s ' . t('Asserting that nodeactivity is one of the returned values.'));
// Assert that all three parts of the array are present and the right type.
// Expecting ops, types, roles all to be arrays
$this
->assertTrue(is_array($info['nodeactivity']['ops']), '%s ' . t('Expecting ops, types, roles all to be arrays'));
$this
->assertTrue(is_array($info['nodeactivity']['types']), '%s ' . t('Expecting ops, types, roles all to be arrays'));
$this
->assertTrue(is_array($info['nodeactivity']['roles']), '%s ' . t('Expecting ops, types, roles all to be arrays'));
}
}
/**
* function activity_insert($module, $type, $operation, $data, $target_users_roles)
* - the return value should be 1 greater than the previous greatest activity.
*/
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'));
}
/**
* Test activity_get_activity
* activity_get_activity($uids = ACTIVITY_ALL, $filters = NULL, $limit = NULL, $tablesort_headers = NULL)
*
* Assert that function can take a uid or an array of uids
* Can take an optional array of filters to filter the results
* Takes a limit parameter
* Support HTML tables with tablesort query additions
* Should always return an array, even if empty.
* array items shall be ordered by database so that tablesort queries are possible.
*/
function testGetActivity1() {
// Does this function exist?
$this
->assertTrue(function_exists('activity_get_activity'));
// Make a new user to test with
$tester = $this
->drupalCreateUserRolePerm();
// Create some activity
$module = 'simpletest';
$type = 'testing';
$operation = 'insert';
$data = array(
'dummydata' => 'foobar',
);
$target_users_roles = array(
ACTIVITY_ALL => 'All',
$tester->uid => 'Author',
'4711' => 'Court Jester',
'4712' => 'King of Spades',
);
$aid = activity_insert($module, $type, $operation, $data, $target_users_roles);
// Assert that each of the following only returns the one activity we inserted.
$activities[1] = activity_get_activity($tester->uid);
$activities[2] = activity_get_activity(array(
$tester->uid,
));
$activities[3] = activity_get_activity(array(
$tester->uid,
999999,
));
$activities[4] = activity_get_activity(array(
$tester->uid,
), array(
'module' => $module,
));
$activities[5] = activity_get_activity($tester->uid, NULL, 40);
foreach ($activities as $key => $activity) {
$this
->assertEqual($aid, $activity[0]['aid'], $key . ': %s ' . t('Expecting aid to be @aid. Found @activity_id.', array(
'@aid' => $aid,
'@activity_id' => $activity[0]['aid'],
)));
}
}
function testGetActivity2() {
// Test the filter process
// Invent some more modules
$modules = array(
'huba',
'foobar',
'barbaz',
);
$types = array(
'test1',
'test2',
'test3',
);
$operations = array(
'insert',
'delete',
'update',
'view',
);
$roles = array(
'Author',
'Editor',
'Viewer',
);
$data = array(
'dummydata' => 'foobar',
);
// Make another new user to test with
$users[] = $this
->drupalCreateUserRolePerm();
$users[] = $this
->drupalCreateUserRolePerm();
$users[] = $this
->drupalCreateUserRolePerm();
$users[] = $this
->drupalCreateUserRolePerm();
$users[] = $this
->drupalCreateUserRolePerm();
// Create a LOT of new activity
// activity_insert($module, $type, $operation, $data, $target_users_roles);
$count = 0;
for ($a = 0; $a < 3; $a++) {
$module = $modules[$a];
for ($b = 0; $b < 3; $b++) {
$type = $types[$b];
for ($c = 0; $c < 4; $c++) {
$operation = $operations[$c];
for ($d = 0; $d < 5; $d++) {
$user = $users[$d];
for ($e = 0; $e < 3; $e++) {
$role = $roles[$e];
$target_users_roles = array(
ACTIVITY_ALL => 'All',
$user->uid => $role,
);
$count++;
activity_insert($module, $type, $operation, $data, $target_users_roles);
}
}
}
}
}
$activity = activity_get_activity(ACTIVITY_ALL);
$this
->assertEqual($count, count($activity), '%s ' . t("Expecting {$count} activities."));
$activity = activity_get_activity(array(
ACTIVITY_ALL,
));
$this
->assertEqual($count, count($activity), '%s ' . t("Expecting {$count} activities."));
// $activity = activity_get_activity('*', array('huba', 'foobar'));
// $this->assertEqual(100, count($activity), '%s '. t('Expecting 100 huba and foobar activities.'));
// $activity = activity_get_activity('*', array('huba', 'foobar'), 17);
// $this->assertEqual(17, count($activity), '%s '. t('Expecting 17 huba and foobar activities on one page.'));
// $activity = activity_get_activity(1, array('huba', 'foobar'));
// $this->assertEqual(0, count($activity), '%s '. t('Expecting 0 huba and foobar activities created by user #1.'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActivityAPITest:: |
private | property | ||
ActivityAPITest:: |
private | property | ||
ActivityAPITest:: |
function | |||
ActivityAPITest:: |
function | |||
ActivityAPITest:: |
function |
tearDown implementation, setting back switched modules etc Overrides DrupalTestCase:: |
||
ActivityAPITest:: |
function | |||
ActivityAPITest:: |
function | Test activity_get_activity activity_get_activity($uids = ACTIVITY_ALL, $filters = NULL, $limit = NULL, $tablesort_headers = NULL) | ||
ActivityAPITest:: |
function | |||
ActivityAPITest:: |
function | function activity_insert($module, $type, $operation, $data, $target_users_roles) | ||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter |