class ActivityUnitTest in Activity 7
Hierarchy
- class \DrupalTestCase
- class \DrupalUnitTestCase
- class \ActivityUnitTest
- class \DrupalUnitTestCase
Expanded class hierarchy of ActivityUnitTest
File
- tests/
activity_unit.test, line 143
View source
class ActivityUnitTest extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => t('Activity Core Unit tests'),
'description' => t('Unit tests for the Activity module'),
'group' => t('Activity'),
);
}
public function setUp() {
parent::setUp('activity');
require_once './' . drupal_get_path('module', 'activity') . '/activity_action_handlers.inc';
}
public function testNodeActivityInsert() {
$handler = activity_load_handler('node_insert');
$handler->templates = array(
'en' => array(
'node' => 'Node Author Message',
'public' => 'Public Message',
),
);
$handler->options = array(
'types' => array(),
'view_modes' => array(),
);
$handler->actions_id = -1;
$handler->label = 'Test node 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,
);
$objects1 = array(
'node' => $node1,
);
$objects2 = array(
'node' => $node2,
);
// Make sure loaded objects match what is expected.
$this
->assertEqual($node1->nid, $objects1['node']->nid, t('Loaded up the correct article node'));
$this
->assertEqual($node2->nid, $objects2['node']->nid, t('Loaded up the correct page node'));
// Mock around the valid method.
$this
->assertTrue($handler
->valid($node1->nid, 1, REQUEST_TIME, $objects1, NULL, NULL), t('Activity handler correctly says article node is a valid activity'));
$this
->assertTrue($handler
->valid($node2->nid, 1, REQUEST_TIME, $objects2, NULL, NULL), t('Activity handler correctly says page node is a valid activity'));
$handler->options['types'] = array(
'article' => 'article',
);
$this
->assertTrue($handler
->valid($node1->nid, 1, REQUEST_TIME, $objects1, NULL, NULL), t('Activity handler correctly checks article node type'));
$this
->assertTrue(!$handler
->valid($node2->nid, 1, REQUEST_TIME, $objects2, NULL, NULL), t('Activity handler correctly checks page node type'));
$handler->options['types'] = array(
'page' => 'page',
);
$this
->assertTrue(!$handler
->valid($node1->nid, 1, REQUEST_TIME, $objects1, NULL, NULL), t('Activity handler prevents article from being valid'));
$this
->assertTrue($handler
->valid($node2->nid, 1, REQUEST_TIME, $objects2, NULL, NULL), t('Activity handler properly validates page node'));
// Ensure the proper eid is returned.
$this
->assertEqual($node1->nid, $handler
->determineEid($objects1), t('Proper Eid is returned'));
// Ensure the proper actor is returned.
$this
->assertEqual($node1->uid, $handler
->determineActor($objects1), t('Proper Actor id is returned'));
// Check timestamp.
$this
->assertEqual($node2->created, $handler
->determineTimestamp($objects2), t('Returned proper timestamp'));
// Check published flag.
$this
->assertTrue($handler
->isPublished($objects1, $node1->uid), t('Correctly flagged activity as published'));
$this
->assertTrue(!$handler
->isPublished($objects2, $node2->uid), t('Correctly flagged activity as not published'));
$this
->assertEqual($handler
->determineNid($objects1), $objects1['node']->nid, t('Returned proper nid'));
// Test tokenize method, which tests getUid.
$objects1['node']->uid = 2;
$messages = $handler
->tokenize($objects1);
$this
->assertTrue(isset($messages['en']), t('Node insert returns english messages'));
$this
->assertEqual($messages['en'][$objects1['node']->uid], $handler->templates['en']['node'], t('Node author message is returned'));
$this
->assertEqual($messages['en'][0], $handler->templates['en']['public'], t('Returned proper public message'));
}
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'));
}
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'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActivityUnitTest:: |
public static | function | ||
ActivityUnitTest:: |
public | function |
Sets up unit test environment. Overrides DrupalUnitTestCase:: |
|
ActivityUnitTest:: |
public | function | ||
ActivityUnitTest:: |
public | function | ||
ActivityUnitTest:: |
public | function | ||
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | Flag to indicate whether the test has been set up. | |
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
public | property | Whether to cache the installation part of the setUp() method. | |
DrupalTestCase:: |
public | property | Whether to cache the modules installation part of the setUp() method. | |
DrupalTestCase:: |
protected | property | URL to the verbose output file directory. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | 1 |
DrupalTestCase:: |
public | function | Handle errors during test runs. | 1 |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs a verbose message in a text file. | |
DrupalUnitTestCase:: |
protected | function | 1 | |
DrupalUnitTestCase:: |
function |
Constructor for DrupalUnitTestCase. Overrides DrupalTestCase:: |