Newer
Older
<?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('drafty', 'workbench_moderation'));
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// 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'));
}
}