public function WebformWorkflowPermissionsTestCase::testFromTo in Webform Workflow 7
Test permissions for changing a submission's state.
File
- tests/
webform_workflow_permissions.test, line 112 - Workflow permissions tests.
Class
- WebformWorkflowPermissionsTestCase
- @file Workflow permissions tests.
Code
public function testFromTo() {
// Create a webform.
$owner = $this
->drupalCreateUser(array(
'create webform content',
'edit own webform content',
'access own webform results',
));
$node = $this
->createDummyWebform(array(
'uid' => $owner->uid,
));
// Enable workflow for the webform.
$this
->enableWorkflow($node);
// Create a submission.
$submitter = $this
->drupalCreateUser(array(
'access own webform submissions',
));
$submission = $this
->createDummySubmission($node, $submitter);
$submission_path = 'node/' . $node->nid . '/submission/' . $submission->sid;
// Log in as the webform owner.
$this
->drupalLogin($owner);
$this
->drupalGet($submission_path);
$this
->assertText(t('Current state'), "The webform owner can view the submission's state");
$this
->assertNoText(t('New state'), "The webform owner cannot change the submission's state");
// Add two states to the webform.
$state1 = $this
->createDummyState();
$state2 = $this
->createDummyState();
$this
->addStateToWebform($state1, $node);
$this
->addStateToWebform($state2, $node);
$this
->drupalGet($submission_path);
$this
->assertText(t('New state'), "The webform owner can now change the submission's state");
// Log in as the submitter.
$this
->drupalLogin($submitter);
$this
->drupalGet($submission_path);
$this
->assertNoText(t('Current state'), "The submitter cannot view the submission's state");
$this
->assertNoText(t('New state'), "The submitter cannot change the submission's state");
// Set that the submitter should be allowed to view the submission's state.
$data =& $node->webform_workflow->data;
$data['os_view_state'] = 1;
db_update('webform_workflow')
->condition('nid', $node->nid)
->fields(array(
'data' => serialize($data),
))
->execute();
$this
->drupalGet($submission_path);
$this
->assertText(t('Current state'), "The submitter can view the submission's state");
$this
->assertNoText(t('New state'), "The submitter still cannot change the submission's state");
// Set that the submitter should be allowed to change the submission state
// to state 1, but not to state 2.
$state1->permissions['to'][WEBFORM_WORKFLOW_ORIGINAL_SUBMITTER] = WEBFORM_WORKFLOW_ORIGINAL_SUBMITTER;
entity_save('webform_workflow_state', $state1);
$this
->drupalGet($submission_path);
$this
->assertText(t('New state'), "The submitter can now change the submission's state");
$this
->assertRaw('<option value="' . $state1->wsid . '"', "The submitter can now change the submission's state to state 1");
$this
->assertNoRaw('<option value="' . $state2->wsid . '"', "The submitter cannot change the submission's state to state 2");
// Set that the submitter should be allowed to change the submission state
// to state2.
$state2->permissions['to'][WEBFORM_WORKFLOW_ORIGINAL_SUBMITTER] = WEBFORM_WORKFLOW_ORIGINAL_SUBMITTER;
entity_save('webform_workflow_state', $state2);
$this
->drupalGet($submission_path);
$this
->assertRaw('<option value="' . $state2->wsid . '"', "The submitter can now change the submission's state to state 2");
// Set the submission's state to state 1.
webform_workflow_transition($submission, $state1);
// Check that the submitter now cannot change the submission's state.
$this
->drupalGet($submission_path);
$this
->assertText(t('Current state'), "The submitter can still view the submission's state");
$this
->assertNoText(t('New state'), 'The submitter cannot change the submission from state 1');
// Set that the submitter should be allowed to change the submission from
// state 1.
$state1->permissions['from'][WEBFORM_WORKFLOW_ORIGINAL_SUBMITTER] = WEBFORM_WORKFLOW_ORIGINAL_SUBMITTER;
entity_save('webform_workflow_state', $state1);
$this
->drupalGet($submission_path);
$this
->assertText(t('New state'), 'The submitter can now change the submission from state 1');
}