public function WebformSubmissionTestCase::testWebformSubmissionRequiredComponents in Webform 7.4
Same name and namespace in other branches
- 6.3 tests/submission.test \WebformSubmissionTestCase::testWebformSubmissionRequiredComponents()
- 7.3 tests/submission.test \WebformSubmissionTestCase::testWebformSubmissionRequiredComponents()
Test that required fields with no default value can't be submitted as-is.
File
- tests/
WebformSubmissionTestCase.test, line 182
Class
- WebformSubmissionTestCase
- Webform module submission tests.
Code
public function testWebformSubmissionRequiredComponents() {
$this
->drupalLogin($this->webform_users['admin']);
$this
->webformReset();
// Create the Webform test node, and set all components to be required
// with no default value.
$node = $this
->webformForm();
$node = node_load($node->nid);
foreach ($node->webform['components'] as &$component) {
$component['value'] = '';
$component['required'] = '1';
}
node_save($node);
// Submit the webform with no data. We should get a message that all the
// components are required. The exceptions are hidden fields, which can't be
// made required, and date fields, which default to the current date when no
// default value is provided; therefore, we don't expect a message for
// those.
$this
->drupalPost('node/' . $node->nid, array(), 'Submit', array(), array(), 'webform-client-form-' . $node->nid);
foreach ($node->webform['components'] as $component) {
if ($component['type'] != 'hidden' && $component['type'] != 'date') {
$this
->assertText(t('!name field is required.', array(
'!name' => $component['name'],
)));
}
}
$this
->drupalLogout();
}