View source
<?php
class ActionsContentTest extends DrupalTestCase {
var $_cleanup_roles = array();
var $_cleanup_users = array();
function get_info() {
return array(
'name' => t('Actions content'),
'desc' => t('Perform various tests with content actions.'),
'group' => 'Actions',
);
}
function testActionsContent() {
global $user;
$this
->drupalModuleEnable('trigger');
$content_actions = array(
'node_publish_action',
'node_unpublish_action',
'node_make_sticky_action',
'node_make_unsticky_action',
'node_promote_action',
'node_unpromote_action',
);
$hash = md5('node_publish_action');
$not_clean = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('" . implode("','", $content_actions) . "')"));
$this
->assertFalse($not_clean, t('Actions were already assigned to the trigger. Unassign all content triggers before attempting to run again.'));
if ($not_clean) {
return;
}
$test_user = $this
->drupalCreateUserRolePerm(array(
'administer actions',
'create page content',
));
$this
->drupalLoginUser($test_user);
$edit = array(
'aid' => $hash,
);
$this
->drupalPost('admin/build/trigger/node', $edit, 'Assign');
$node = $this
->drupalCreateNode(array(
'status' => 0,
));
$loaded_node = node_load($node->nid);
$this
->assertTrue($loaded_node->status == 1, t('Check to make sure the node is automatically published'));
$edit = array(
'aid' => $hash,
);
$this
->drupalPost('admin/build/trigger/node', $edit, 'Assign');
$this
->assertWantedRaw(t('The action you chose is already assigned to that trigger.'), t('Check to make sure an error occurs when assigning an action to a trigger twice.'));
$this
->drupalPost('admin/build/trigger/unassign/nodeapi/presave/' . $hash, array(), 'Unassign');
$this
->assertWantedRaw(t('Action %action has been unassigned.', array(
'%action' => 'Publish post',
)), t('Check to make sure action can be unassigned from trigger.'));
$assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('" . implode("','", $content_actions) . "')"));
$this
->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.'));
}
}