public function WebformSubmissionTestCase::testWebformSubmission in Webform 7.4
Same name and namespace in other branches
- 6.3 tests/submission.test \WebformSubmissionTestCase::testWebformSubmission()
- 6.2 tests/submission.test \WebformSubmissionTestCase::testWebformSubmission()
- 7.3 tests/submission.test \WebformSubmissionTestCase::testWebformSubmission()
Test sending a submission and check database integrity.
File
- tests/
WebformSubmissionTestCase.test, line 22
Class
- WebformSubmissionTestCase
- Webform module submission tests.
Code
public function testWebformSubmission() {
$this
->drupalLogin($this->webform_users['admin']);
$this
->webformReset();
$this
->webformSubmissionExecute('sample');
$loggedInUser = $this->loggedInUser;
$this
->drupalLogout();
// Test webform_get_submission_count().
// Counting the anonymous submission doesn't work because
// $_SESSION['webform_submission'] is not populated in testing.
$this
->webformSubmissionExecute('sample');
$count = webform_get_submission_count($this
->webformForm()->nid);
$this
->assertIdentical((int) $count, 2, 'webform_get_submission_count() counts 2 total submissions.');
$count = webform_get_submission_count($this
->webformForm()->nid, $loggedInUser->uid);
$this
->assertIdentical((int) $count, 1, 'webform_get_submission_count() counts 1 submission from loggedInUser.');
// Test _webform_submission_prepare_mail().
$node = node_load($this
->webformForm()->nid);
$submission = webform_get_submissions($node->nid);
$submission = array_pop($submission);
$email = array(
'status' => TRUE,
'html' => FALSE,
'template' => 'default',
'from_address' => 'Test From',
'from_name' => 'from@example.com',
'subject' => 'Test Subject',
'email' => 'to@example.com',
);
variable_set('webform_email_replyto', TRUE);
variable_set('webform_email_address_format', 'long');
variable_set('webform_default_from_name', 'Default "From" Name');
variable_set('webform_default_from_address', 'default-from@example.com');
$prepared_email = _webform_submission_prepare_mail($node, $submission, $email);
$this
->assertIdentical($prepared_email['mail_params']['email']['from'], '"from@example.com via Default \'From\' Name" <default-from@example.com>', 'From address is correctly set in _webform_submission_prepare_mail().');
}