Skip to content
Snippets Groups Projects
Commit 565f8300 authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-178] Merging test into staging -c858

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@859 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent b892a428
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
*/
class workbench_moderation_handler_filter_user_can_moderate extends views_handler_filter {
function options_form(&$form, &$form_state) {
parent::options_form(&$form, &$form_state);
parent::options_form($form, $form_state);
drupal_set_message(t("This filter isn't even possible right now since workbench moderation permissions are incomplete--there's no way to figure out what transitions a user may make for a particular type of content."), 'error');
}
......
......@@ -10,7 +10,7 @@ class WorkbenchModerationTestCase extends DrupalWebTestCase {
protected $moderator_user;
function setUp() {
parent::setUp('workbench_moderation', 'workbench');
parent::setUp(array('workbench_moderation', 'workbench'));
// Create a new content type and enable moderation on it.
$type = $this->drupalCreateContentType();
......@@ -52,9 +52,12 @@ class WorkbenchModerationModerateTabTestCase extends WorkbenchModerationTestCase
);
}
function testModerateTab() {
function setUp() {
parent::setUp();
$this->drupalLogin($this->moderator_user);
}
function testModerateTab() {
$is_moderated = workbench_moderation_node_type_moderated($this->content_type);
$this->assertTrue($is_moderated, t('The content type is moderated.'));
......@@ -111,11 +114,16 @@ class WorkbenchModerationDraftTabTestCase extends WorkbenchModerationTestCase {
);
}
function testDraftTab() {
function setUp() {
parent::setUp();
// Workbench is now required for the mini moderation form.
module_enable(array('workbench'));
$this->drupalLogin($this->moderator_user);
}
function testDraftTab() {
// Create a new node and make sure it is unpublished.
$body_name = 'body[' . LANGUAGE_NONE . '][0]';
$edit = array(
......@@ -174,9 +182,12 @@ class WorkbenchModerationPublishFromNodeFormTestCase extends WorkbenchModeration
);
}
function testPublishFromNodeForm() {
function setUp() {
parent::setUp();
$this->drupalLogin($this->admin_user);
}
function testPublishFromNodeForm() {
// Create a new node and publish it immediately.
$body_name = 'body[' . LANGUAGE_NONE . '][0]';
$edit = array(
......@@ -200,3 +211,41 @@ class WorkbenchModerationPublishFromNodeFormTestCase extends WorkbenchModeration
}
}
class WorkbenchModerationUnpublishTestCase extends WorkbenchModerationTestCase {
public static function getInfo() {
return array(
'name' => 'Unpublish moderated content',
'description' => 'Create and publish a moderated node, then unpublish using the "Moderate" tab.',
'group' => 'Workbench Moderation',
);
}
function setUp() {
parent::setUp();
$this->drupalLogin($this->admin_user);
}
function testUnpublish() {
// Create a new node and publish it immediately. Assumes that
// WorkbenchModerationPublishFromNodeFormTestCase passes.
$body_name = 'body[' . LANGUAGE_NONE . '][0]';
$edit = array(
'title' => $this->randomName(),
"{$body_name}[value]" => $this->randomString(128),
"{$body_name}[format]" => filter_default_format(),
'workbench_moderation_state_new' => workbench_moderation_state_published(),
);
$this->drupalPost("node/add/{$this->content_type}", $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title']);
// Unpublish the node via the unpublish confirmation form.
$this->drupalPost("node/{$node->nid}/moderation/{$node->vid}/unpublish", array(), t('Confirm'));
$unpublished_node = node_load($node->nid, FALSE, TRUE);
$this->assertFalse($unpublished_node->status, t('The node is not published.'));
$this->assertFalse(isset($unpublished_node->workbench_moderation['published']), t('Workbench moderation has no published revision.'));
}
}
......@@ -13,9 +13,9 @@ files[] = includes/workbench_moderation_handler_filter_user_can_moderate.inc
files[] = tests/workbench_moderation.test
files[] = tests/workbench_moderation.files.test
; Information added by drupal.org packaging script on 2011-06-13
; Information added by drupal.org packaging script on 2011-07-15
version = "7.x-1.x-dev"
core = "7.x"
project = "workbench_moderation"
datestamp = "1307925876"
datestamp = "1310691021"
......@@ -128,8 +128,9 @@ function workbench_moderation_menu_alter(&$items) {
$items['node/%node/revisions']['page callback'] = 'workbench_moderation_node_revisions_redirect';
$items['node/%node/revisions']['page arguments'] = array(1);
// For revert operations, use our own access check.
$items['node/%node/revisions/%/revert']['access callback'] = '_workbench_moderation_revert_access';
// For revert and delete operations, use our own access check.
$items['node/%node/revisions/%/revert']['access callback'] = '_workbench_moderation_revision_access';
$items['node/%node/revisions/%/delete']['access callback'] = '_workbench_moderation_revision_access';
// Provide a container administration menu item, if one doesn't already exist.
if (!isset($items['admin/config/workbench'])) {
......@@ -414,27 +415,38 @@ function _workbench_moderation_access($op, $node) {
}
/**
* Wrapper function for the 'revert' operation of _node_revision_access().
* Wrapper for the 'revert' and 'delete' operations of _node_revision_access().
*
* Drupal core's "current revision" of a node is the version in {node}; for
* Workbench Moderation, latest revision in {node_revision} is the current
* revision. For nodes with a published revision, Workbench Moderation keeps
* that revision in {node}, whether or not it is the current revision.
*/
function _workbench_moderation_revert_access($node, $op = 'revert') {
function _workbench_moderation_revision_access($node, $op) {
// Normal behavior for unmoderated nodes.
if (!workbench_moderation_node_type_moderated($node->type)) {
return _node_revision_access($node, $op);
}
// Prevent reverting to the current revision.
// Prevent reverting to or deleting the current revision.
if ($node->workbench_moderation['current']->vid == $node->workbench_moderation['my_revision']->vid) {
return FALSE;
}
// Temporarily give the node an impossible revision.
// _node_revision_access() keeps access check results in a static variable
// indexed by revision only, not by op. Thus, subsequent checks on the same
// vid for different ops yield the same result, regardless of permissions.
// Setting a fake vid here allows us to store different static results per op.
$tmp = $node->vid;
$node->vid = -1;
switch ($op) {
case 'update':
$node->vid = -1;
break;
case 'delete':
$node->vid = -2;
break;
}
// Check access.
$access = _node_revision_access($node, $op);
......@@ -568,11 +580,10 @@ function workbench_moderation_views_default_views() {
*/
function workbench_moderation_node_presave($node) {
global $user;
// Set the published status when a node is set to live
// Is this a node that is controlled by content moderation?
if (isset($node->workbench_moderation_state_new)) {
// Is the new state live or is there an existing published revision?
if ($node->workbench_moderation_state_new == workbench_moderation_state_published() || !empty($node->workbench_moderation['published']->nid)) {
// If the new moderation state is published, or if this revision is the
// published revision, set the node status to published.
if ($node->workbench_moderation_state_new == workbench_moderation_state_published() || (!empty($node->workbench_moderation['published']) && $node->vid == $node->workbench_moderation['published']->vid)) {
$node->status = 1;
}
else {
......@@ -779,29 +790,31 @@ function workbench_moderation_form_alter(&$form, $form_state, $form_id) {
);
}
// Move the Revision log under publishing to make things pretty
$form['options']['log'] = $form['revision_information']['log'];
$form['options']['log']['#title'] = t('Moderation notes');
// Unset the old placement of the Revision log.
unset($form['revision_information']['log']);
// Always create new revisions for nodes that are moderated
$form['revision_information']['revision'] = array(
'#type' => 'value',
'#value' => TRUE,
);
// Log the proper user name or anonymous name.
if (user_is_anonymous()) {
$logged_name = variable_get('anonymous', t('Anonymous'));
}
else {
$logged_name = $user->name;
}
$action = !empty($form['#node']->nid) ? t('Edited') : t('Created');
$form['options']['log']['#default_value'] = t('!action by @user.', array('!action' => $action, '@user' => $logged_name));
// Set a default revision log message.
$logged_name = (user_is_anonymous() ? variable_get('anonymous', t('Anonymous')) : $user->name);
$logged_action = !empty($form['#node']->nid) ? t('Edited') : t('Created');
$form['revision_information']['log']['#default_value'] = t('!action by @user.', array('!action' => $logged_action, '@user' => $logged_name));
// Always create new revisions for nodes that are moderated
$form['revision_information']['revision']['#default_value'] = TRUE;
// Do not allow users to change the revision status
$form['revision_information']['#access'] = FALSE;
// Move the revision log into the publishing options to make things pretty.
if ($form['options']['#access']) {
$form['options']['log'] = $form['revision_information']['log'];
$form['options']['log']['#title'] = t('Moderation notes');
// Unset the old placement of the Revision log.
unset($form['revision_information']['log']);
// User has no ability to choose if this content is published or not. If the
// moderation status is live, then it will be published, otherwise not.
// The revision information section should now be empty.
$form['revision_information']['#access'] = FALSE;
}
// Users can not choose to publish content; content can only be published by
// setting the content's moderation state to "Published".
$form['options']['status']['#access'] = FALSE;
$form['actions']['submit']['#submit'][] = 'workbench_moderation_node_form_submit';
workbench_moderation_messages('edit', $form['#node']);
......@@ -1389,9 +1402,17 @@ function workbench_moderation_moderate($node, $state) {
if ($new_revision->current) {
$node->workbench_moderation['current'] = $new_revision;
}
// Handle the published revision.
if ($new_revision->published) {
// If we're moderating a revision to the published state, mark the new
// revision as the published revision.
$node->workbench_moderation['published'] = $new_revision;
}
elseif (isset($node->workbench_moderation['published']) && $new_revision->vid == $node->workbench_moderation['published']->vid && $new_revision->from_state == workbench_moderation_state_published()) {
// If we're moderating the published revision to a non-published state,
// remove the workbench moderation 'published' property.
unset($node->workbench_moderation['published']);
}
// If we're moderating an unpublished revision and there is an existing
// published revision, make sure that the published revision is live.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment