View source
<?php
class WorkbenchModerationWebTestCase extends DrupalWebTestCase {
function setup() {
$modules = func_get_args();
if (isset($modules[0]) && is_array($modules[0])) {
$modules = $modules[0];
}
$modules += array(
'state_machine',
'state_flow',
'state_flow_entity',
'workbench_moderation',
'workbench_workflows',
'views',
);
parent::setup($modules);
module_load_include('inc', 'workbench_workflows', 'includes/workbench_workflows.starter');
workbench_workflows_import_starter_exportables();
ctools_export_load_object_reset();
$this
->checkPermissions(array(), TRUE);
$permissions = array(
'administer nodes',
'bypass node access',
'use workbench_moderation my drafts tab',
'use workbench_moderation needs review tab',
'administer_workbench_workflows',
'access administration pages',
'administer site configuration',
'administer content revisions',
);
$this->admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->admin_user);
}
function testOfDisbablingWorkflow() {
variable_set('workbench_workflows_default_to_ignore', TRUE);
$this
->drupalGet("node/add/article");
$this
->assertResponse(200);
$xpath_string = "//select[@id=:select_id]";
$xpath_replacements = array(
':select_id' => 'edit-event',
);
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1, 'There is a workflow available on the node add form.');
$this
->drupalGet("admin/config/workflow/workbench-workflows/workflows");
$this
->assertResponse(200);
$this
->clickLink('Disable');
$this
->drupalGet("node/add/article");
$this
->assertResponse(200);
$xpath_string = "//select[@id=:select_id]";
$xpath_replacements = array(
':select_id' => 'edit-event',
);
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 0, 'There is not workflow available on the node add form.');
}
function _testOfDuplicateStates() {
$states = db_select('state_flow_states')
->fields('state_flow_states', array())
->execute()
->fetchAll();
$hids = array();
$duplicates = FALSE;
foreach ($states as $state) {
if (!empty($state->hid)) {
if (empty($hids[$state->hid])) {
$hids[$state->hid][] = $state;
}
else {
$duplicates = TRUE;
}
}
}
$this
->assertFalse($duplicates, t('There are no duplicate records in State Flow States'));
if ($duplicates) {
debug($states);
}
}
}
class WorkbenchModerationBasicWebTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench Moderation basic tests',
'description' => 'Perform basic web tests on Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
function testOfDisbablingWorkflow() {
variable_set('workbench_workflows_default_to_ignore', TRUE);
$this
->drupalGet("node/add/article");
$this
->assertResponse(200);
$xpath_string = "//select[@id=:select_id]";
$xpath_replacements = array(
':select_id' => 'edit-event',
);
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 1, 'There is a workflow available on the node add form.');
$this
->drupalGet("admin/config/workflow/workbench-workflows/workflows");
$this
->assertResponse(200);
$this
->clickLink('Disable');
$this
->drupalGet("node/add/article");
$this
->assertResponse(200);
$xpath_string = "//select[@id=:select_id]";
$xpath_replacements = array(
':select_id' => 'edit-event',
);
$tr = $this
->xpath($xpath_string, $xpath_replacements);
$this
->assertEqual(count($tr), 0, 'There is not workflow available on the node add form.');
}
}
class WorkbenchModerationNodeAccessTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench Moderation Node Access tests',
'description' => 'Perform node access with Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
public function setup() {
parent::setup(func_get_args());
$permissions = array(
'view all content in state published',
);
$this->state_access_user = $this
->drupalCreateUser($permissions);
}
function testPublishedRevisionAccess() {
$edit = array();
$init_title = $this
->randomName(8);
$edit['title'] = $init_title;
$edit['event'] = 'published';
$edit['event_comment'] = $this
->randomName(8);
$this
->drupalPost("node/add/article", $edit, t('Save'));
$this
->drupalGet("node/1");
$this
->assertText($init_title, t('Title is visible on draft node for logged in user.'));
$edit = array();
$second_title = $this
->randomName(8);
$edit['title'] = $second_title;
$edit['event'] = 'needs_review';
$edit['revision'] = 1;
$this
->drupalPost("node/1/edit", $edit, t('Save'));
$edit = array();
$third_title = $this
->randomName(8);
$edit['title'] = $third_title;
$edit['event'] = 'published';
$edit['revision'] = 1;
$this
->drupalPost("node/1/edit", $edit, t('Save'));
$this
->drupalGet('node/1/revisions');
$this
->drupalGet('node/1/revisions/3/view');
$this
->assertResponse(200, 'Admin: Inactive published revision accessible');
$this
->assertText($init_title);
$this
->drupalGet('node/1/revisions/2/view');
$this
->assertResponse(200, 'Admin: Needs review revision accessible');
$this
->assertText($second_title);
$this
->drupalGet('node/1/revisions/4/view');
$this
->assertResponse(200, 'Admin: Active published revision accessible');
$this
->assertText($third_title);
$this
->drupalLogout();
$this
->drupalGet('node/1/revisions/3/view');
$this
->assertResponse(403, 'Anonymous: Inactive published revision inaccessible');
$this
->assertNoTitle($init_title);
$this
->drupalGet('node/1/revisions/2/view');
$this
->assertResponse(403, 'Admin: Needs review revision inaccessible');
$this
->assertNoTitle($second_title);
$this
->drupalGet('node/1/revisions/4/view');
$this
->assertResponse(200, 'Anonymous: Active published revision accessible');
$this
->assertText($third_title);
$this
->drupalLogin($this->state_access_user);
$this
->drupalGet('node/1/revisions/3/view');
$this
->assertResponse(200, 'Published-Access-User: Inactive published revision accessible');
$this
->assertText($init_title);
$this
->drupalGet('node/1/revisions/2/view');
$this
->assertResponse(403, 'Published-Access-User: Needs review revision inaccessible');
$this
->assertNoTitle($second_title);
$this
->drupalGet('node/1/revisions/4/view');
$this
->assertResponse(200, 'Published-Access-User: Active published revision accessible');
$this
->assertText($third_title);
}
}
class WorkbenchModerationModerateTabTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench Moderation Tabs tests',
'description' => 'Perform Tabs tests for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
function testMyDraftsTabDuplicates() {
$edit = array();
$new_title = $this
->randomName(8);
$edit['event'] = 'draft';
$edit['title'] = $this
->randomName(8);
$this
->drupalPost("node/add/article", $edit, t('Save'));
$edit = array(
'event' => 'needs_review',
);
$this
->drupalPost("node/1/revisions-state-flow-states", $edit, t('Update State'));
$this
->drupalPost("node/1/revisions-state-flow-states", $edit, t('Update State'));
$this
->drupalGet("admin/workbench/drafts");
$this
->assertResponse(200);
$xpath_string = "//tbody/tr";
$tr = $this
->xpath($xpath_string);
$this
->assertEqual(count($tr), 1, 'There is only one row for the one existing revision');
$this
->drupalGet("admin/workbench/needs-review");
$this
->assertResponse(200);
$tr = $this
->xpath($xpath_string);
$this
->assertEqual(count($tr), 1, 'There is only one row for the one existing revision');
}
}
class WorkbenchModerationDraftTabTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench Draft Tab tests',
'description' => 'Perform Draft Tab test for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
public function testViewDraftTab() {
$edit = array();
$title = $this
->randomName(8);
$edit['title'] = $title;
$edit['event'] = 'draft';
$edit['event_comment'] = $this
->randomName(8);
$this
->drupalPost("node/add/article", $edit, t('Save'));
$this
->drupalGet("node/1");
$this
->assertText($title, t('Title is visible on draft node for logged in user.'));
$this
->_testOfDuplicateStates();
$this
->drupalGet('node/1/draft');
$this
->assertResponse(403, 'View Draft tab responds with 403 to logged in user');
$this
->drupalLogout();
$this
->drupalGet("node/1");
$this
->assertNoText($title, t('Title is not visible on draft node for anonymous user.'));
$this
->assertResponse(403, 'Draft node page responds with 403 to anonymous user');
$this
->drupalGet('node/1/draft');
$this
->assertResponse(403, 'View Draft tab responds with 403 to anonymous user');
$web_user = $this
->drupalCreateUser(array(
'administer nodes',
'bypass node access',
'administer content revisions',
));
$this
->drupalLogin($web_user);
$edit = array();
$edit['event'] = 'published';
$edit['event_comment'] = $this
->randomName(8);
$this
->drupalPost("node/1/revisions-state-flow-states", $edit, t('Update State'));
$this
->drupalGet("node/1");
$this
->assertText($title, t('Title is visible on published node for logged in user.'));
$this
->_testOfDuplicateStates();
$this
->drupalGet('node/1/draft');
$this
->assertResponse(403, 'View Draft tab responds with 403 to logged in user');
$this
->drupalLogout();
$this
->drupalGet("node/1");
$this
->assertText($title, t('After publishing, anonymous user can see node title.'));
$this
->assertResponse(200, 'After publishing, anonymous user gets a 200 for node page.');
$this
->drupalGet('node/1/draft');
$this
->assertResponse(403, 'View Draft tab responds with 403 to anonymous user');
$web_user = $this
->drupalCreateUser(array(
'administer nodes',
'bypass node access',
'administer content revisions',
));
$this
->drupalLogin($web_user);
$edit = array();
$new_title = $this
->randomName(8);
$edit['title'] = $new_title;
$edit['event'] = 'needs_review';
$this
->drupalPost("node/1/edit", $edit, t('Save'));
$this
->_testOfDuplicateStates();
$this
->drupalGet("node/1");
$this
->assertText($title, t('User can see published node title.'));
$this
->assertResponse(200, 'User gets a 200 for node page.');
$this
->drupalGet("node/1/draft");
$this
->assertText($new_title, t('User can see node draft title.'));
$this
->assertResponse(200, 'User gets a 200 for node draft page.');
$this
->drupalLogout();
$this
->drupalGet("node/1");
$this
->assertText($title, t('Title is visible on published node for anonymous user.'));
$this
->assertResponse(200, 'Anonymous user gets a 200 for node page.');
$this
->drupalGet("node/1/draft");
$this
->assertNoText($new_title, t('Title is not visible on draft node for anonymous user.'));
$this
->assertResponse(403, 'Draft node page responds with 403 to anonymous user');
}
}
class WorkbenchModerationExternalNodeUpdateTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench DUMMY tests',
'description' => 'Perform WorkbenchModerationExternalNodeUpdateTestCase test for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
}
class WorkbenchModerationFilesTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench DUMMY tests',
'description' => 'Perform WorkbenchModerationFilesTestCase test for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
}
class WorkbenchModerationViewUnpublishedTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench DUMMY tests',
'description' => 'Perform WorkbenchModerationViewUnpublishedTestCase test for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
}
class WorkbenchModerationPublishFromNodeFormTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench DUMMY tests',
'description' => 'Perform WorkbenchModerationPublishFromNodeFormTestCase test for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
}
class WorkbenchModerationUnpublishTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench DUMMY tests',
'description' => 'Perform WorkbenchModerationUnpublishTestCase test for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
}
class WorkbenchRedirectAfterTitleChangeTestCase extends WorkbenchModerationWebTestCase {
public static function getInfo() {
return array(
'name' => 'Workbench DUMMY tests',
'description' => 'Perform WorkbenchRedirectAfterTitleChangeTestCase test for Workbench Moderation.',
'group' => 'Workbench Moderation',
);
}
}