You are here

public function YamlFormElementExtrasTest::testBuildElements in YAML Form 8

Tests building of custom elements.

File

src/Tests/YamlFormElementExtrasTest.php, line 24

Class

YamlFormElementExtrasTest
Tests for form (render) element extras.

Namespace

Drupal\yamlform\Tests

Code

public function testBuildElements() {
  $this
    ->drupalGet('yamlform/test_element_extras');

  /**************************************************************************/

  // text_format

  /**************************************************************************/

  // Check that formats and tips are removed and/or hidden.
  $this
    ->assertRaw('<div class="filter-wrapper js-form-wrapper form-wrapper" data-drupal-selector="edit-text-format-format" style="display: none" id="edit-text-format-format">');
  $this
    ->assertRaw('<div class="filter-help js-form-wrapper form-wrapper" data-drupal-selector="edit-text-format-format-help" style="display: none" id="edit-text-format-format-help">');

  /**************************************************************************/

  // counter

  /**************************************************************************/
  $this
    ->assertRaw('<input data-counter-type="character" data-counter-limit="10" class="js-yamlform-counter yamlform-counter form-text" data-drupal-selector="edit-counter-characters" type="text" id="edit-counter-characters" name="counter_characters" value="" size="60" maxlength="255" />');
  $this
    ->assertRaw('<textarea data-counter-type="word" data-counter-limit="3" data-counter-message="word(s) left. This is a custom message" class="js-yamlform-counter yamlform-counter form-textarea resize-vertical" data-drupal-selector="edit-counter-words" id="edit-counter-words" name="counter_words" rows="5" cols="60"></textarea>');

  /**************************************************************************/

  // creditcard_number

  /**************************************************************************/

  // Check basic creditcard_number.
  $this
    ->assertRaw('<label for="edit-creditcard-number-basic">Credit card number basic</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-creditcard-number-basic" type="text" id="edit-creditcard-number-basic" name="creditcard_number_basic" value="" size="16" maxlength="16" class="form-textfield form-creditcard-number" />');

  /**************************************************************************/

  // email_multiple

  /**************************************************************************/

  // Check basic email_multiple.
  $this
    ->assertRaw('<label for="edit-email-multiple-basic">Multiple email addresses (basic)</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-email-multiple-basic" aria-describedby="edit-email-multiple-basic--description" type="text" id="edit-email-multiple-basic" name="email_multiple_basic" value="" size="60" class="form-textfield form-email-multiple" />');
  $this
    ->assertRaw('Multiple email addresses may be separated by commas.');

  /**************************************************************************/

  // email_confirm

  /**************************************************************************/

  // Check basic email_confirm.
  $this
    ->assertRaw('<div data-drupal-selector="edit-email-confirm-basic" id="edit-email-confirm-basic" class="js-form-wrapper form-wrapper">');
  $this
    ->assertRaw('<div class="js-form-item form-item js-form-type-email form-type-email js-form-item-email-confirm-basic-mail-1 form-item-email-confirm-basic-mail-1">');
  $this
    ->assertRaw('<label for="edit-email-confirm-basic-mail-1">Email confirm basic</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-email-confirm-basic-mail-1" class="yamlform-email form-email" type="email" id="edit-email-confirm-basic-mail-1" name="email_confirm_basic[mail_1]" value="" size="60" maxlength="254" />');
  $this
    ->assertRaw('<div class="js-form-item form-item js-form-type-email form-type-email js-form-item-email-confirm-basic-mail-2 form-item-email-confirm-basic-mail-2">');
  $this
    ->assertRaw('<label for="edit-email-confirm-basic-mail-2">Confirm email</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-email-confirm-basic-mail-2" class="yamlform-email-confirm form-email" type="email" id="edit-email-confirm-basic-mail-2" name="email_confirm_basic[mail_2]" value="" size="60" maxlength="254" />');

  // Check advanced email_confirm w/ custom label.
  $this
    ->assertRaw('<div data-drupal-selector="edit-email-confirm-advanced" aria-describedby="edit-email-confirm-advanced--description" id="edit-email-confirm-advanced" class="js-form-wrapper form-wrapper">');
  $this
    ->assertRaw('<div class="js-form-item form-item js-form-type-email form-type-email js-form-item-email-confirm-advanced-mail-1 form-item-email-confirm-advanced-mail-1">');
  $this
    ->assertRaw('<label for="edit-email-confirm-advanced-mail-1">Email confirm advanced</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-email-confirm-advanced-mail-1" aria-describedby="edit-email-confirm-advanced-mail-1--description" class="yamlform-email form-email" type="email" id="edit-email-confirm-advanced-mail-1" name="email_confirm_advanced[mail_1]" value="" size="60" maxlength="254" placeholder="Enter email address" />');
  $this
    ->assertRaw('<div id="edit-email-confirm-advanced-mail-1--description" class="description">');
  $this
    ->assertRaw('Please make sure to review your email address');
  $this
    ->assertRaw('<div class="js-form-item form-item js-form-type-email form-type-email js-form-item-email-confirm-advanced-mail-2 form-item-email-confirm-advanced-mail-2">');
  $this
    ->assertRaw('<label for="edit-email-confirm-advanced-mail-2">Please confirm your email address</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-email-confirm-advanced-mail-2" aria-describedby="edit-email-confirm-advanced-mail-2--description" class="yamlform-email-confirm form-email" type="email" id="edit-email-confirm-advanced-mail-2" name="email_confirm_advanced[mail_2]" value="" size="60" maxlength="254" placeholder="Enter confirmation email address" />');
  $this
    ->assertRaw('<div id="edit-email-confirm-advanced-mail-2--description" class="description">');
  $this
    ->assertRaw('Please make sure to review your confirmation email address');

  /**************************************************************************/

  // signature

  /**************************************************************************/
  $this
    ->assertRaw('<input data-drupal-selector="edit-signature-basic" aria-describedby="edit-signature-basic--description" type="hidden" name="signature_basic" value="" class="js-yamlform-signature form-yamlform-signature" /><div class="js-yamlform-signature-pad yamlform-signature-pad">');
  $this
    ->assertRaw('<input type="submit" name="op" value="Reset" class="button js-form-submit form-submit" />');
  $this
    ->assertRaw('<canvas></canvas>');
  $this
    ->assertRaw('</div>');
  $this
    ->assertRaw('<div id="edit-signature-basic--description" class="description">');
  $this
    ->assertRaw('Sign above');

  /**************************************************************************/

  // toggle

  /**************************************************************************/

  // Check basic toggle.
  $this
    ->assertRaw('<div class="js-form-item form-item js-form-type-yamlform-toggle form-type-yamlform-toggle js-form-item-toggle-basic form-item-toggle-basic">');
  $this
    ->assertRaw('<input data-drupal-selector="edit-toggle-basic" type="checkbox" id="edit-toggle-basic" name="toggle_basic" value="1" class="form-checkbox" />');
  $this
    ->assertRaw('<div class="js-yamlform-toggle yamlform-toggle toggle toggle-medium toggle-light" data-toggle-height="24" data-toggle-width="48" data-toggle-text-on="" data-toggle-text-off=""></div>');
  $this
    ->assertRaw('<label for="edit-toggle-basic" class="option">Basic toggle</label>');

  // Check advanced toggle.
  $this
    ->assertRaw('<div class="js-form-item form-item js-form-type-yamlform-toggle form-type-yamlform-toggle js-form-item-toggle-advanced form-item-toggle-advanced">');
  $this
    ->assertRaw('<label for="edit-toggle-advanced">Advanced toggle</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-toggle-advanced" type="checkbox" id="edit-toggle-advanced" name="toggle_advanced" value="1" class="form-checkbox" />');
  $this
    ->assertRaw('<div class="js-yamlform-toggle yamlform-toggle toggle toggle-large toggle-iphone" data-toggle-height="36" data-toggle-width="108" data-toggle-text-on="Yes" data-toggle-text-off="No"></div>');

  // Check basic toggles.
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-toggles-basic" id="edit-toggles-basic--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');
  $this
    ->assertRaw('<span class="fieldset-legend">Basic toggles</span>');
  $this
    ->assertRaw('<div id="edit-toggles-basic" class="yamlform-options-display-one-column form-checkboxes"><div class="js-form-item form-item js-form-type-yamlform-toggle form-type-yamlform-toggle js-form-item-toggles-basic-one form-item-toggles-basic-one">');
  $this
    ->assertRaw('<input data-drupal-selector="edit-toggles-basic-one" type="checkbox" id="edit-toggles-basic-one" name="toggles_basic[one]" value="one" class="form-checkbox" /><div class="js-yamlform-toggle yamlform-toggle toggle toggle-medium toggle-light" data-toggle-height="24" data-toggle-width="48" data-toggle-text-on="" data-toggle-text-off=""></div>');
  $this
    ->assertRaw('<label for="edit-toggles-basic-one" class="option">One</label>');

  // Check advanced toggles.
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-toggles-advanced" id="edit-toggles-advanced--wrapper" class="fieldgroup form-composite js-form-item form-item js-form-wrapper form-wrapper">');
  $this
    ->assertRaw('<span class="fieldset-legend">Advanced toggles</span>');
  $this
    ->assertRaw('<div id="edit-toggles-advanced" class="yamlform-options-display-one-column form-checkboxes"><div class="js-form-item form-item js-form-type-yamlform-toggle form-type-yamlform-toggle js-form-item-toggles-advanced-one form-item-toggles-advanced-one">');
  $this
    ->assertRaw('<input data-drupal-selector="edit-toggles-advanced-one" type="checkbox" id="edit-toggles-advanced-one" name="toggles_advanced[one]" value="one" class="form-checkbox" /><div class="js-yamlform-toggle yamlform-toggle toggle toggle-large toggle-iphone" data-toggle-height="36" data-toggle-width="108" data-toggle-text-on="Yes" data-toggle-text-off="No"></div>');

  /**************************************************************************/

  // rating

  /**************************************************************************/

  // Check basic.
  $this
    ->assertRaw('<label for="edit-rating-basic">Rating basic</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-rating-basic" type="range" id="edit-rating-basic" name="rating_basic" value="0" step="1" min="0" max="5" class="form-yamlform-rating" />');
  $this
    ->assertRaw('<div class="rateit svg rateit-medium" data-rateit-min="0" data-rateit-max="5" data-rateit-step="1" data-rateit-resetable="false" data-rateit-readonly="false" data-rateit-backingfld="#edit-rating-basic" data-rateit-value="" data-rateit-starheight="24" data-rateit-starwidth="24">');

  // Check advanced.
  $this
    ->assertRaw('<label for="edit-rating-advanced">Rating advanced</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-rating-advanced" type="range" id="edit-rating-advanced" name="rating_advanced" value="0" step="0.1" min="0" max="10" class="form-yamlform-rating" />');
  $this
    ->assertRaw('<div class="rateit svg rateit-large" data-rateit-min="0" data-rateit-max="10" data-rateit-step="0.1" data-rateit-resetable="true" data-rateit-readonly="false" data-rateit-backingfld="#edit-rating-advanced" data-rateit-value="" data-rateit-starheight="32" data-rateit-starwidth="32">');

  /**************************************************************************/

  // contact (composite element)

  /**************************************************************************/

  // Check form contact basic.
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-contact-basic" id="edit-contact-basic--wrapper" class="fieldgroup form-composite js-yamlform-contact yamlform-contact required js-form-item form-item js-form-wrapper form-wrapper" required="required" aria-required="true">');
  $this
    ->assertNoRaw('<span class="fieldset-legend js-form-required form-required">Contact basic</span>');
  $this
    ->assertRaw('<label for="edit-contact-basic-name" class="js-form-required form-required">Name</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-contact-basic-name" type="text" id="edit-contact-basic-name" name="contact_basic[name]" value="John Smith" size="60" maxlength="128" class="form-text required" required="required" aria-required="true" />');

  // Check custom name title, description, and required.
  $this
    ->assertRaw('<label for="edit-contact-advanced-name" class="js-form-required form-required">Custom contact name</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-contact-advanced-name" aria-describedby="edit-contact-advanced-name--description" type="text" id="edit-contact-advanced-name" name="contact_advanced[name]" value="John Smith" size="60" maxlength="128" class="form-text required" required="required" aria-required="true" />');
  $this
    ->assertRaw('Custom contact name description');

  // Check custom state type and not required.
  $this
    ->assertRaw('<label for="edit-contact-advanced-state-province">State/Province</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-contact-advanced-state-province" type="text" id="edit-contact-advanced-state-province" name="contact_advanced[state_province]" value="New Jersey" size="60" maxlength="128" class="form-text" />');

  // Check custom country access.
  $this
    ->assertNoRaw('edit-contact-advanced-country');

  /**************************************************************************/

  // creditcard (composite element)

  /**************************************************************************/
  $this
    ->assertRaw('<fieldset data-drupal-selector="edit-creditcard" id="edit-creditcard--wrapper" class="fieldgroup form-composite js-yamlform-creditcard yamlform-creditcard js-form-item form-item js-form-wrapper form-wrapper">');
  $this
    ->assertNoRaw('<span class="fieldset-legend">Credit Card</span>');
  $this
    ->assertRaw('The credit card element is experimental and insecure because it stores submitted information as plain text.');
  $this
    ->assertRaw('<label for="edit-creditcard-name">Name on Card</label>');
  $this
    ->assertRaw('<input data-drupal-selector="edit-creditcard-name" type="text" id="edit-creditcard-name" name="creditcard[name]" value="John Smith" size="60" maxlength="128" class="form-text" />');
  $this
    ->assertRaw('<select data-drupal-selector="edit-creditcard-expiration-month" id="edit-creditcard-expiration-month" name="creditcard[expiration_month]" class="form-select">');

  /**************************************************************************/

  // table

  /**************************************************************************/
  $this
    ->assertRaw('<table class="js-form-wrapper responsive-enabled" data-drupal-selector="edit-table" id="edit-table" data-striping="1">');
  $this
    ->assertRaw('<th>First Name</th>');
  $this
    ->assertRaw('<th>Last Name</th>');
  $this
    ->assertRaw('<th>Gender</th>');
  $this
    ->assertRaw('<tr data-drupal-selector="edit-table-1" class="odd">');
  $this
    ->assertRaw('<td><div class="js-form-item form-item js-form-type-textfield form-type-textfield js-form-item-table__1__first-name form-item-table__1__first-name form-no-label">');
  $this
    ->assertRaw('<input data-drupal-selector="edit-table-1-first-name" type="text" id="edit-table-1-first-name" name="table__1__first_name" value="John" size="20" maxlength="255" class="form-text" />');
}