public function YamlFormElementExtrasTest::testProcessingElements in YAML Form 8
Tests value processing for custom elements.
File
- src/
Tests/ YamlFormElementExtrasTest.php, line 189
Class
- YamlFormElementExtrasTest
- Tests for form (render) element extras.
Namespace
Drupal\yamlform\TestsCode
public function testProcessingElements() {
/**************************************************************************/
// counter
/**************************************************************************/
// Check counter validation error.
$edit = [
'counter_characters' => '01234567890',
'counter_words' => 'one two three four',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw('counter_characters</em> must be less than 10 characters.');
$this
->assertRaw('counter_words</em> must be less than 3 words.');
// Check counter validation passes.
$edit = [
'counter_characters' => '0123456789',
'counter_words' => 'one two three',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertNoRaw('counter_characters</em> must be less than 10 characters.');
$this
->assertNoRaw('counter_words</em> must be less than 3 words.');
/**************************************************************************/
// table
/**************************************************************************/
$this
->drupalPostForm('yamlform/test_element_extras', [], t('Submit'));
$this
->assertRaw('table__1__first_name: John');
$this
->assertRaw('table__1__last_name: Smith');
$this
->assertRaw('table__1__gender: Male');
$this
->assertRaw('table__2__first_name: Jane');
$this
->assertRaw('table__2__last_name: Doe');
$this
->assertRaw('table__2__gender: Female');
/**************************************************************************/
// creditcard_number
/**************************************************************************/
// Check invalid credit card number.
$edit = [
'creditcard_number_basic' => 'not value',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw('The credit card number is not valid.');
// Check valid credit card number.
$edit = [
'creditcard_number_basic' => '4111111111111111',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertNoRaw('The credit card number is not valid.');
// Check valid AmEx (15 digit).
$edit = [
'creditcard_number_basic' => '378282246310005',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertNoRaw('The credit card number is not valid.');
/**************************************************************************/
// email_multiple
/**************************************************************************/
// Check invalid second email address.
$edit = [
'email_multiple_basic' => 'example@example.com, Not a valid email address',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw('The email address <em class="placeholder">Not a valid email address</em> is not valid.');
// Check invalid token email address.
$edit = [
'email_multiple_basic' => 'example@example.com, [token]',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw('The email address <em class="placeholder">[token]</em> is not valid.');
// Check valid second email address.
$edit = [
'email_multiple_basic' => 'example@example.com, other@other.com',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw("email_multiple_basic: 'example@example.com, other@other.com'");
// Check valid token email address (via #allow_tokens).
$edit = [
'email_multiple_advanced' => 'example@example.com, [token]',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw("email_multiple_advanced: 'example@example.com, [token]'");
/**************************************************************************/
// email_confirm
/**************************************************************************/
// Check invalid email addresses.
$edit = [
'email_confirm_advanced[mail_1]' => 'Not a valid email address',
'email_confirm_advanced[mail_2]' => 'Not a valid email address, again',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw('The email address <em class="placeholder">Not a valid email address</em> is not valid.');
$this
->assertRaw('The email address <em class="placeholder">Not a valid email address, again</em> is not valid.');
// Check non-matching email addresses.
$edit = [
'email_confirm_advanced[mail_1]' => 'example01@example.com',
'email_confirm_advanced[mail_2]' => 'example02@example.com',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw('The specified email addresses do not match.');
// Check matching email addresses.
$edit = [
'email_confirm_advanced[mail_1]' => 'example@example.com',
'email_confirm_advanced[mail_2]' => 'example@example.com',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertNoRaw('<li class="messages__item">The specified email addresses do not match.</li>');
$this
->assertRaw('email_confirm_advanced: example@example.com');
// Check empty confirm email address.
$edit = [
'email_confirm_advanced[mail_1]' => '',
'email_confirm_advanced[mail_2]' => '',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertNoRaw('<li class="messages__item">Confirm Email field is required.</li>');
/**************************************************************************/
// rating
/**************************************************************************/
$edit = [
'rating_basic' => '4',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw("rating_basic: '4'");
/**************************************************************************/
// markup
/**************************************************************************/
$this
->drupalGet('yamlform/test_element_markup');
$this
->assertRaw('<p>This is normal markup</p>');
$this
->assertRaw('<p>This is only displayed on the form view.</p>');
$this
->assertNoRaw('<p>This is only displayed on the submission view.</p>');
$this
->assertRaw('<p>This is displayed on the both the form and submission view.</p>');
$this
->drupalPostForm('yamlform/test_element_markup', [], t('Preview'));
$this
->assertNoRaw('<p>This is normal markup</p>');
$this
->assertNoRaw('<p>This is only displayed on the form view.</p>');
$this
->assertRaw('<p>This is only displayed on the submission view.</p>');
$this
->assertRaw('<p>This is displayed on the both the form and submission view.</p>');
/**************************************************************************/
// contact (composite element)
/**************************************************************************/
// Check composite value.
$this
->drupalPostForm('yamlform/test_element_extras', [], t('Submit'));
$this
->assertRaw("contact_basic:\n name: 'John Smith'\n company: Acme\n email: example@example.com\n phone: 123-456-7890\n address: '100 Main Street'\n address_2: 'PO BOX 999'\n city: 'Hill Valley'\n state_province: 'New Jersey'\n postal_code: 11111-1111\n country: 'United States'");
// Check validate required composite elements.
$edit = [
'contact_basic[name]' => '',
];
$this
->drupalPostForm('yamlform/test_element_extras', $edit, t('Submit'));
$this
->assertRaw('Name field is required.');
/**************************************************************************/
// creditcard (composite element)
/**************************************************************************/
// Check composite value.
$this
->drupalPostForm('yamlform/test_element_extras', [], t('Submit'));
$this
->assertRaw("creditcard:\n name: 'John Smith'\n type: VI\n number: '4111111111111111'\n civ: '111'\n expiration_month: '1'\n expiration_year: '2025'");
}