Loading tests/workbench_moderation.files.test 0 → 100644 +104 −0 Changes for tests/workbench_moderation.files.test: 104 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Tests for using file fields with workbench_moderation.module. */ class WorkbenchModerationFilesTestCase extends FileFieldTestCase { protected $content_type; protected $moderator_user; function setUp() { parent::setUp(); module_enable(array('workbench_moderation')); // Create a new content type and enable moderation on it. $type = $this->drupalCreateContentType(); $this->content_type = $type->name; variable_set('node_options_' . $this->content_type, array('revision', 'moderation')); // Add a file field to the new content type. $this->field_name = strtolower($this->randomName()); $this->createFileField($this->field_name, $this->content_type); $this->moderator_user = $this->drupalCreateUser(array( 'access content', 'access administration pages', 'administer site configuration', 'administer users', 'administer permissions', 'administer content types', 'administer nodes', 'bypass node access', 'view revisions', 'revert revisions', "edit any {$this->content_type} content", 'view moderation history', 'view moderation messages', 'bypass workbench moderation', )); $this->drupalLogin($this->moderator_user); } public static function getInfo() { return array( 'name' => 'Workbench Moderation file attachments', 'description' => 'Test moderation on nodes with with file attachments.', 'group' => 'Workbench Moderation', ); } function testModeratedFileField() { // Create a new node with an uploaded file. $file = $this->getTestFile('text'); $edit = array( 'title' => $this->randomName(), 'files[' . $this->field_name . '_' . LANGUAGE_NONE . '_0]' => drupal_realpath($file->uri), ); $this->drupalPost("node/add/{$this->content_type}", $edit, t('Save')); // Get the new node. $node = $this->drupalGetNodeByTitle($edit['title']); $nid = $node->nid; // Publish the node via the moderation form. $moderate = array('state' => workbench_moderation_state_published()); $this->drupalPost("node/{$nid}/moderation", $moderate, t('Apply')); // Update the node; remove the first file and add a second file. $file = $this->getTestFile('text'); $edit = array( 'title' => $this->randomName(10) . '_second', 'files[' . $this->field_name . '_' . LANGUAGE_NONE . '_0]' => drupal_realpath($file->uri), ); $this->drupalPost("node/$nid/edit", array(), t('Remove')); $this->drupalPost(NULL, $edit, t('Save')); // Load the published node. $published = node_load($nid, NULL, TRUE); // Check for a published revision. $this->assertTrue(isset($published->workbench_moderation['published']), t('Workbench moderation has published revision')); // Load the draft revision. $draft = clone $published; $draft = workbench_moderation_node_current_load($draft); // Check that the draft revision is different from the published revision. $this->assertNotEqual($published->vid, $draft->vid, t('Workbench moderation loads second revision')); // Check that the original file is present on the published revision. $published_file = (object) $published->{$this->field_name}[LANGUAGE_NONE][0]; $this->assertFileExists($published_file, t('File is present on published revision')); // Check that the second file is present on the draft revision. $draft_file = (object) $draft->{$this->field_name}[LANGUAGE_NONE][0]; $this->assertFileExists($draft_file, t('File is present on draft revision')); $this->assertNotEqual($published_file->uri, $draft_file->uri, t('File on published revision is different from file on draft revision')); } } workbench_moderation.info +4 −0 Changes for workbench_moderation.info: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,8 +2,12 @@ name = Workbench Moderation description = Provides content moderation services package = Workbench core = 7.x configure = admin/config/workbench/moderation files[] = workbench_moderation.module files[] = includes/workbench_moderation_handler_filter_state.inc files[] = includes/workbench_moderation_handler_field_links.inc files[] = includes/workbench_moderation_handler_filter_moderated_type.inc files[] = includes/workbench_moderation_handler_filter_user_can_moderate.inc files[] = tests/workbench_moderation.files.test workbench_moderation.module +3 −0 Changes for workbench_moderation.module: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -631,6 +631,9 @@ function workbench_moderation_node_update($node) { // Apply moderation changes if this is a new revision or if the moderation // state has changed. if (!empty($node->revision) || $node->workbench_moderation_state_current != $node->workbench_moderation_state_new) { // Update attached fields. field_attach_update('node', $node); // Moderate the node. workbench_moderation_moderate($node, $node->workbench_moderation_state_new); } Loading Loading
tests/workbench_moderation.files.test 0 → 100644 +104 −0 Changes for tests/workbench_moderation.files.test: 104 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * @file * Tests for using file fields with workbench_moderation.module. */ class WorkbenchModerationFilesTestCase extends FileFieldTestCase { protected $content_type; protected $moderator_user; function setUp() { parent::setUp(); module_enable(array('workbench_moderation')); // Create a new content type and enable moderation on it. $type = $this->drupalCreateContentType(); $this->content_type = $type->name; variable_set('node_options_' . $this->content_type, array('revision', 'moderation')); // Add a file field to the new content type. $this->field_name = strtolower($this->randomName()); $this->createFileField($this->field_name, $this->content_type); $this->moderator_user = $this->drupalCreateUser(array( 'access content', 'access administration pages', 'administer site configuration', 'administer users', 'administer permissions', 'administer content types', 'administer nodes', 'bypass node access', 'view revisions', 'revert revisions', "edit any {$this->content_type} content", 'view moderation history', 'view moderation messages', 'bypass workbench moderation', )); $this->drupalLogin($this->moderator_user); } public static function getInfo() { return array( 'name' => 'Workbench Moderation file attachments', 'description' => 'Test moderation on nodes with with file attachments.', 'group' => 'Workbench Moderation', ); } function testModeratedFileField() { // Create a new node with an uploaded file. $file = $this->getTestFile('text'); $edit = array( 'title' => $this->randomName(), 'files[' . $this->field_name . '_' . LANGUAGE_NONE . '_0]' => drupal_realpath($file->uri), ); $this->drupalPost("node/add/{$this->content_type}", $edit, t('Save')); // Get the new node. $node = $this->drupalGetNodeByTitle($edit['title']); $nid = $node->nid; // Publish the node via the moderation form. $moderate = array('state' => workbench_moderation_state_published()); $this->drupalPost("node/{$nid}/moderation", $moderate, t('Apply')); // Update the node; remove the first file and add a second file. $file = $this->getTestFile('text'); $edit = array( 'title' => $this->randomName(10) . '_second', 'files[' . $this->field_name . '_' . LANGUAGE_NONE . '_0]' => drupal_realpath($file->uri), ); $this->drupalPost("node/$nid/edit", array(), t('Remove')); $this->drupalPost(NULL, $edit, t('Save')); // Load the published node. $published = node_load($nid, NULL, TRUE); // Check for a published revision. $this->assertTrue(isset($published->workbench_moderation['published']), t('Workbench moderation has published revision')); // Load the draft revision. $draft = clone $published; $draft = workbench_moderation_node_current_load($draft); // Check that the draft revision is different from the published revision. $this->assertNotEqual($published->vid, $draft->vid, t('Workbench moderation loads second revision')); // Check that the original file is present on the published revision. $published_file = (object) $published->{$this->field_name}[LANGUAGE_NONE][0]; $this->assertFileExists($published_file, t('File is present on published revision')); // Check that the second file is present on the draft revision. $draft_file = (object) $draft->{$this->field_name}[LANGUAGE_NONE][0]; $this->assertFileExists($draft_file, t('File is present on draft revision')); $this->assertNotEqual($published_file->uri, $draft_file->uri, t('File on published revision is different from file on draft revision')); } }
workbench_moderation.info +4 −0 Changes for workbench_moderation.info: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,8 +2,12 @@ name = Workbench Moderation description = Provides content moderation services package = Workbench core = 7.x configure = admin/config/workbench/moderation files[] = workbench_moderation.module files[] = includes/workbench_moderation_handler_filter_state.inc files[] = includes/workbench_moderation_handler_field_links.inc files[] = includes/workbench_moderation_handler_filter_moderated_type.inc files[] = includes/workbench_moderation_handler_filter_user_can_moderate.inc files[] = tests/workbench_moderation.files.test
workbench_moderation.module +3 −0 Changes for workbench_moderation.module: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -631,6 +631,9 @@ function workbench_moderation_node_update($node) { // Apply moderation changes if this is a new revision or if the moderation // state has changed. if (!empty($node->revision) || $node->workbench_moderation_state_current != $node->workbench_moderation_state_new) { // Update attached fields. field_attach_update('node', $node); // Moderate the node. workbench_moderation_moderate($node, $node->workbench_moderation_state_new); } Loading