Drupal's Simpletest does not iterate over element of type 'button' to check to see if it matches the "submit" value set.

consider this test

  function testButtonForm() {
      $edit = array();
      $edit['name'] = $this->randomName(8);
      $edit["pass"] = $this->randomName(16);
      $this->drupalPost('user/login', $edit, t('Log in'));
  }

For the HTML

  <form method="post"> 
...
  <input type="text" id="edit-name" name="name" value="" size="60" maxlength="60" class="form-text required">
  <input type="password" id="edit-pass" name="pass" size="60" maxlength="128" class="form-text required">
  <button type="submit" id="edit-submit" name="op" value="Log in" class="btn form-submit btn-primary">Log in</button>
...
</form>

returns the following under Drush

  Test mytest->testButtonForm() failed: Found the Log in button                                           [error]
  Test mytest->testButtonForm() failed: Found the requested form fields at user/login                [error]

but if I add 'button' to this xpath then it works

  protected function handleForm(&$post, &$edit, &$upload, $submit, $form) {
    // Retrieve the form elements.
    $elements = $form->xpath('.//input[not(@disabled)]|.//textarea[not(@disabled)]|.//select[not(@disabled)]|.//button[not(@disabled)]');
...

not sure if i'm doing something wrong? patch supplied

Comments

sun’s picture

Status: Active » Closed (works as designed)

That's because BUTTON elements do not submit a form.

dgtlmoon’s picture

Status: Closed (works as designed) » Active

Incorrect, it's my understanding that

type=submit means that it submits the form

http://www.w3.org/wiki/HTML/Elements/button#Submit_Button_state

Submit Button state
Represents a button for submitting a form.
If the element has a form owner, the element must submit the form owner from the button element. [Example A]

Furthermore;

http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.5

name = cdata [CI] This attribute assigns the control name.
value = cdata [CS] This attribute assigns the initial value to the button.
type = submit|button|reset [CI] This attribute declares the type of the button. Possible values:
submit: Creates a submit button. This is the default value.
reset: Creates a reset button.
button: Creates a push button.

http://www.w3.org/TR/REC-html40/interact/forms.html#submit-button

buttons
Authors may create three types of buttons:
submit buttons: When activated, a submit button submits a form. A form may contain more than one submit button.
...

States clearly "submit button submits a form"

dgtlmoon’s picture

bump

wodenx’s picture

Status: Active » Needs review
StatusFileSize
new807 bytes

Rerolled to apply cleanly to current head. Many themes render 'submit' form elements as buttons.

dgtlmoon’s picture

Status: Needs review » Reviewed & tested by the community

Works here, thanks

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

Hm, seems like <button> might be valid for this but rarely used (and buggy in some browsers)?

In any case, this would need to go into Drupal 8 first.

Tim Asplin’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
StatusFileSize
new807 bytes

Some themes, namely Bootstrap rewite 'input type submit' as 'button', had this issue so attached patch for 7.x

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev

Status: Needs review » Needs work

The last submitted patch, 7: 1481148-7-simpletest-button-submit-d7.patch, failed testing.

dgtlmoon’s picture

Patch from #4 (D7) still applying fine - This issue affects any builds with HTML5 (Bootstrap theme etc)

idebr’s picture

Status: Needs work » Needs review
StatusFileSize
new838 bytes

The button is a valid form element, per http://www.w3.org/TR/html4/interact/forms.html#h-17.5

Buttons created with the BUTTON element function just like buttons created with the INPUT element, but they offer richer rendering possibilities: the BUTTON element may have content. For example, a BUTTON element that contains an image functions like and may resemble an INPUT element whose type is set to "image", but the BUTTON element type allows content.

In themes, the <button> allows for much more advanced styling compared to <input />. Simpletest should facilitate this element as a valid form element.

dgtlmoon’s picture

Status: Needs review » Reviewed & tested by the community

Your patch works fine for me

dgtlmoon’s picture

Status: Reviewed & tested by the community » Needs review
martijn houtman’s picture

StatusFileSize
new807 bytes

Tested and working fine here on D7. Here's a patch.

Status: Needs review » Needs work

The last submitted patch, 15: 1481148-15.patch, failed testing.

idebr’s picture

Status: Needs work » Needs review
StatusFileSize
new838 bytes

@Martijn Houtman Issues that apply to Drupal 7 as well as Drupal 8 are being fixed in Drupal 8 first. The testbot will test patches against the version indicated in the issue metadata, so the 7 version you added caused the testbot to fail. Feel free to supply a backported version, but please add '-do-not-test.patch' at the end so the patch is not picked up by the testbot.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The current user login form does not use the button type for its submit button. But the form api reference says it is allowed to use the button type as a submit button.

The patch looks good to me and it get RTBC from me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

We should be testing this or using this somewhere.

martijn houtman’s picture

@idebr: Thanks for your remark, I did not know this, but it makes absolute sense. I will make sure to do this next time.

@alexpott: I ran into this error while testing our user register form on a site where we override the theme_button function to output a [button] rather than an [input type=button], for styling reasons. This could be used for writing a test?

function theme_button($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'submit';
  element_set_attributes($element, array('id', 'name', 'value'));

  $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
  if (!empty($element['#attributes']['disabled'])) {
    $element['#attributes']['class'][] = 'form-button-disabled';
  }

  return '<button' . drupal_attributes($element['#attributes']) . ' >' . $element['#attributes']['value'] . '</button>';
}
idebr’s picture

dgtlmoon’s picture

Version: 8.0.x-dev » 7.x-dev

Perhaps we can first get a resolve in Drupal 7? that would save a *lot* of people a lot debugging time, I have to disagree with a D8 port first on this one

dgtlmoon’s picture

StatusFileSize
new807 bytes
dgtlmoon’s picture

Status: Needs work » Needs review
paulgrand’s picture

Status: Needs review » Reviewed & tested by the community

Tested and verified, mainly apparent on sites using bootstrap theme (or indeed any other theme employing button tags for submit actions.

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Reviewed & tested by the community » Needs work

Not sure why this keeps getting bumped back to Drupal 7. It needs to be committed to Drupal 8 first; then the backport can go into Drupal 7 after that.

dgtlmoon’s picture

Status: Needs work » Needs review
StatusFileSize
new842 bytes

Same patch applies but different directory structure in D8, this issue is causes a lot of timeloss before we remember to search this queue, lots of advanced themes are using instead

dgtlmoon’s picture

StatusFileSize
new838 bytes

Tidied up excessive whitespace

The last submitted patch, 27: 1481148-button-is-also-a-submit-D8.patch, failed testing.

daffie’s picture

Status: Needs review » Needs work

There are still tests needed for this patch. See the comment #19 from alexpott.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Component: simpletest.module » phpunit

Triaging issues in simpletest.module as part of the Bug Smash Initiative to determine if they should be in the Simpletest Project or core.

This looks like it a Phpunit issue, changing component.

quietone’s picture

Project: Drupal core » SimpleTest
Version: 8.9.x-dev » 8.x-3.x-dev
Component: phpunit » Code

Came across and had another look. I think I am mistaken, it should be in the Simpletest module.