While FeedAPI development I ran into a nasty situation: FeedAPI has a quickadd block which has a Submit button. Of course, the normal node submitting form has an exactly captioned Submit button. If the block is enabled with the form, my tests were failed because as far as i know, with Simpletest, i cannot decide on which form should be submitted, i can only choose which submit button should be "clicked". But only according to the caption of the button. For a workaround I renamed the block's Submit to Add, but it's not a solution :)
My suggestion is to expand the parameters of drupalPostRequest() with an argument of a form-related value (it could be an optional argument). In this way if the page has multiple forms, the author of automated test can solve the situation.

CommentFileSizeAuthor
#5 dpr-submitbyid.patch1.34 KBRok Žlender

Comments

Rok Žlender’s picture

drupalPostRequest accepts also id or name of the submit button. Check link 123 in drupal_test_case. The order postrequest tries to submit form is:

  1. clickSubmitById($submit)
  2. clickSubmit(t($submit))
  3. clickSubmitByName($submit)
  4. clickImageByName($submit)

I am open to suggestions if this is not a good way to do it.

aron novak’s picture

Status: Active » Fixed

This is perfect.I should RTFM before ask questions :) Thanks for your help!

aron novak’s picture

Status: Fixed » Active
    $ret = $this->_browser->clickSubmit(t($submit))  || $this->_browser->clickSubmitByName($submit) || $this->_browser->clickImageByName($submit);

Well, I tried to pass an id to drupalpostrequest, but I checked the 123. line of drupal_test_case.
Either the id-passed submit did not work and I cannot see in the code the clickSubmitById function call, and even in the whole simpletest package, I could not find such a function.
Thanks for your help.

Rok Žlender’s picture

Hm sorry for misleading you. I wonder which hacked version of simpletest I was looking at when I gave you the answer. Anyway... There is a clickSubmitById function its in browser.php on line 888 in simpletest lib. If you replace line 113 in drupal_test_case.php:

$ret = $this->_browser->clickSubmit(t($submit))  || $this->_browser->clickSubmitByName($submit) || $this->_browser->clickImageByName($submit);

to

$ret = $this->_browser->clickSubmitById($submit) || $this->_browser->clickSubmit(t($submit))  || $this->_browser->clickSubmitByName($submit) || $this->_browser->clickImageByName($submit);

it should do the trick.

Rok Žlender’s picture

StatusFileSize
new1.34 KB

This patch solves your problem and is a nice addition to drupalPostRequest

Rok Žlender’s picture

Status: Active » Needs review
chx’s picture

Status: Needs review » Reviewed & tested by the community

Straightforward and much needed.

Rok Žlender’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

webchick’s picture

Status: Fixed » Patch (to be ported)
Rok Žlender’s picture

Status: Patch (to be ported) » Fixed

Ported.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.