diff --git a/includes/webform.emails.inc b/includes/webform.emails.inc index 0babfaf3..ffd7e9d0 100644 --- a/includes/webform.emails.inc +++ b/includes/webform.emails.inc @@ -206,7 +206,6 @@ function webform_emails_form_status_save($form, &$form_state) { */ function webform_email_edit_form($form, $form_state, $node, $email = array(), $clone = FALSE) { module_load_include('inc', 'webform', 'includes/webform.components'); - $form['#attached']['library'][] = array('webform', 'admin'); $form['#attached']['js'][] = array('data' => array('webform' => array('revertConfirm' => t('Are you sure you want to revert any changes to your template back to the default?'))), 'type' => 'setting'); @@ -682,6 +681,7 @@ function webform_email_load($eid, $nid) { if ($eid == 'new') { $email = array( 'email' => '', + 'cc' => '', 'subject' => 'default', 'from_name' => 'default', 'from_address' => 'default', diff --git a/tests/WebformTestCase.test b/tests/WebformTestCase.test index caf662b5..52145f6d 100644 --- a/tests/WebformTestCase.test +++ b/tests/WebformTestCase.test @@ -64,6 +64,7 @@ public function setUp($added_modules = array()) { $permissions['admin'] = array( 'access content', 'administer nodes', + 'edit webform components', 'create webform content', 'edit any webform content', 'access all webform results', diff --git a/webform.info b/webform.info index 05c50fd5..6ff2a9da 100644 --- a/webform.info +++ b/webform.info @@ -34,6 +34,7 @@ files[] = views/webform_plugin_row_submission_view.inc files[] = tests/WebformComponentsTestCase.test files[] = tests/WebformConditionalsTestCase.test +files[] = tests/WebformEmailTestCase.test files[] = tests/WebformGeneralTestCase.test files[] = tests/WebformPermissionsTestCase.test files[] = tests/WebformSubmissionTestCase.test diff --git a/tests/WebformEmailTestCase.test b/tests/WebformEmailTestCase.test new file mode 100644 index 00000000..74690d28 --- /dev/null +++ b/tests/WebformEmailTestCase.test @@ -0,0 +1,102 @@ + t('Webform email handling'), + 'description' => t('Check how emails are handled.'), + 'group' => t('Webform'), + ); + } + + /** + * Test the email form. + */ + public function testEmailForm() { + // Some values to use on the forms. + $to_address = $this->randomName() . '@example.com'; + $cc_address = $this->randomName() . '@example.com'; + + // Login. + $this->drupalLogin($this->webform_users['admin']); + $this->webformReset(); + + // Load the emails settings page, confirm it exists as expected. + $node = $this->webformForm(); + $this->drupalGet('node/' . $node->nid . '/webform/emails'); + $this->assertResponse(200); + $this->assertText(t('Currently not sending e-mails, add an e-mail recipient below.')); + $this->assertFieldByName('status'); + $this->assertFieldByName('email_option', 'custom'); + $this->assertFieldByName('email_custom'); + $this->assertFieldByName('email_option', 'component'); + $this->assertFieldbyName('email_component'); + $this->assertFieldbyName('op', t('Add')); + + // Create a new email submission. + $edit = array( + 'status' => TRUE, + 'email_option' => 'custom', + 'email_custom' => $to_address, + ); + $this->drupalPost(NULL, $edit, t('Add')); + $this->assertResponse(200); + + // Confirm the form fields exist as expected. + $this->assertText(t('E-mail to address')); + $this->assertFieldByName('email_option', 'custom'); + $this->assertFieldByName('email_custom', $to_address); + $this->assertFieldByName('email_option', 'component'); + $this->assertFieldByName('email_component'); + $this->assertText(t('Email address to send a Carbon Copy (CC)')); + $this->assertFieldByName('cc_option', 'custom'); + $this->assertFieldByName('cc_custom', ''); + $this->assertFieldByName('cc_option', 'component'); + $this->assertFieldByName('cc_component'); + $this->assertFieldByName('status'); + $this->assertText(t('E-mail subject')); + $this->assertFieldByName('subject_option', 'default'); + $this->assertFieldByName('subject_option', 'custom'); + $this->assertFieldByName('subject_custom'); + $this->assertFieldByName('subject_option', 'component'); + $this->assertFieldByName('subject_component'); + $this->assertText(t('E-mail from address')); + $this->assertFieldByName('from_address_option', 'default'); + $this->assertFieldByName('from_address_option', 'custom'); + $this->assertFieldByName('from_address_custom'); + $this->assertFieldByName('from_address_option', 'component'); + $this->assertFieldByName('from_address_component'); + $this->assertText(t('E-mail from name')); + $this->assertFieldByName('from_name_option', 'custom'); + $this->assertFieldByName('from_name_custom'); + $this->assertFieldByName('from_name_option', 'component'); + $this->assertFieldByName('from_name_component'); + $this->assertText(t('E-mail template')); + $this->assertText(t('An e-mail template can customize the display of e-mails.')); + $this->assertFieldByName('template_option'); + $this->assertFieldByName('template'); + $this->assertText(t('The selected components will be included in the [submission:values] token. Individual values may still be printed if explicitly specified as a [submission:values:?] in the template.')); + + // Fill in some values. + $edit = array( + // The 'to' address is already filled in, so just check the 'cc'. + 'cc_option' => 'custom', + 'cc_custom' => $cc_address, + ); + $this->drupalPost(NULL, $edit, t('Save e-mail settings')); + $this->assertResponse(200); + + // Confirm the form saved correctly. + $this->assertText(t('Email settings added.')); + $this->assertText($to_address); + $this->assertText('CC: ' . $cc_address); + } + +}