function WorkbenchModerationFilesTestCase::testModeratedFileField in Workbench Moderation 7
Same name and namespace in other branches
- 7.3 tests/workbench_moderation.files.test \WorkbenchModerationFilesTestCase::testModeratedFileField()
File
- tests/
workbench_moderation.files.test, line 56 - Tests for using file fields with workbench_moderation.module.
Class
- WorkbenchModerationFilesTestCase
- @file Tests for using file fields with workbench_moderation.module.
Code
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'));
}