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
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 1481148-button-is-also-a-submit-D8.patch | 838 bytes | dgtlmoon |
Comments
Comment #1
sunThat's because BUTTON elements do not submit a form.
Comment #2
dgtlmoon commentedIncorrect, it's my understanding that
type=submit means that it submits the form
http://www.w3.org/wiki/HTML/Elements/button#Submit_Button_state
Furthermore;
http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.5
http://www.w3.org/TR/REC-html40/interact/forms.html#submit-button
States clearly "submit button submits a form"
Comment #3
dgtlmoon commentedbump
Comment #4
wodenx commentedRerolled to apply cleanly to current head. Many themes render 'submit' form elements as buttons.
Comment #5
dgtlmoon commentedWorks here, thanks
Comment #6
David_Rothstein commentedHm, 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.
Comment #7
Tim Asplin commentedSome themes, namely Bootstrap rewite 'input type submit' as 'button', had this issue so attached patch for 7.x
Comment #8
David_Rothstein commentedComment #11
dgtlmoon commentedPatch from #4 (D7) still applying fine - This issue affects any builds with HTML5 (Bootstrap theme etc)
Comment #12
idebr commentedThe button is a valid form element, per http://www.w3.org/TR/html4/interact/forms.html#h-17.5
In themes, the
<button>allows for much more advanced styling compared to<input />. Simpletest should facilitate this element as a valid form element.Comment #13
dgtlmoon commentedYour patch works fine for me
Comment #14
dgtlmoon commentedComment #15
martijn houtman commentedTested and working fine here on D7. Here's a patch.
Comment #17
idebr commented@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.
Comment #18
daffie commentedThe 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.
Comment #19
alexpottWe should be testing this or using this somewhere.
Comment #20
martijn houtman commented@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?
Comment #21
idebr commentedThis effort might be a duplicate based on what happens in #1671190: Use <button /> form element type instead of <input type="submit" />
Comment #22
dgtlmoon commentedPerhaps 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
Comment #23
dgtlmoon commentedComment #24
dgtlmoon commentedComment #25
paulgrand commentedTested and verified, mainly apparent on sites using bootstrap theme (or indeed any other theme employing button tags for submit actions.
Comment #26
David_Rothstein commentedNot 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.
Comment #27
dgtlmoon commentedSame 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
Comment #28
dgtlmoon commentedTidied up excessive whitespace
Comment #30
daffie commentedThere are still tests needed for this patch. See the comment #19 from alexpott.
Comment #39
quietone commentedTriaging 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.
Comment #40
quietone commentedCame across and had another look. I think I am mistaken, it should be in the Simpletest module.