This took a while to track down.
If you use the SimpleTest internal browser to click a link with a query string - for example the test in http://drupal.org/node/248436#comment-834256 you get a php warning like this in your testing report:
Unexpected PHP error [sprintf() [function.sprintf]: Too few arguments] severity [E_WARNING] in [/modules/simpletest/test_case.php line 272]
Thanks to chx and Freso who helped me work out that it wasn't my .test causing the problem.
Here's clickLink() from drupal_web_test_case.php, it has it's own internal assertion which appears to be where the problem is.
function clickLink($label, $index = 0) {
$url_before = $this->getUrl();
$ret = FALSE;
if ($this->parse()) {
$urls = $this->elements->xpath('//a[text()="'. $label .'"]');
if (isset($urls[$index])) {
$url_target = $this->getAbsoluteUrl($urls[$index]['href']);
$curl_options = array(CURLOPT_URL => $url_target);
$ret = $this->curlExec($curl_options);
}
$this->assertTrue($ret, t('Clicked link !label (!url_target) from !url_before', array('!label' => $label, '!url_target' => $url_target, '!url_before' => $url_before)), t('Browser'));
}
return $ret;
}
Comments
Comment #1
catchsee also: http://drupal.org/node/260495
Comment #2
boombatower commentedDecided to give this a wirl and found that the query strings contain
%20whichsprintfthinks is are arguments. Just required that all the urls be decoded before being sent to sprintf.Comment #3
catchRemoves the exceptions in statistics.test and all other tests using clickLink() still pass.
Comment #4
boombatower commentedBump, still applies after batch API with fuzz. Re-rolled to remove fuzz.
Comment #5
dries commentedI ran all tests with and without this patch, and it doesn't seem to make a difference. The same amount of tests fail/pass.
Comment #6
catchOn my system, I now get no exceptions (since Batch API went in) - so I'm wondering if this was fixed in another issue somewhere.
Comment #7
boombatower commentedThis is still an issue that can occur since the urls can have %20 and such. sprintf interprets the % a a variable and tries to insert it.
The only possibility would be if the urls are now decoded somewhere else, which I will check into.
Comment #8
boombatower commentedDoesn't appear that the urls are decoded anywhere. Based on that I would say this still applies, not sure why the test doesn't give exception. Was it changed?
Comment #9
catchThis no longer applies cleanly. The test wasn't changed so I'm not sure where else it got fixed. Downgrading to normal, might be unreproducable now.
Comment #10
boombatower commentedWell, it doesn't give warnings for the old reason as that does seem to be fixed, rather interesting. I think that is due to the reporting moving to Drupal code instead of SimpleTest library.
Eitherway this patch makes the clickLink method use drupalGet instead of its own cURL request which outputs assertions and such.
It throws notice when no link is found, which it shouldn't, fixed that.
Comment #11
boombatower commentedThis a slightly updated version of the above patch, with comment update as well.
Since the original bug has been fixed with new framework the scope has changed.
Ran blog.test which has a call to clickLink which and it works fine.
Comment #12
webchickIt appears this needs tests in simpletest.test. I couldn't quite follow the logic of what exact bugs this change fixes. It would be much easier with a test case. And that way, we know if we broke it again later.
Comment #13
boombatower commentedThis no longer fixes anything, merely change clickLink() to use drupalGet() and cleans code.
It used to fix a bug, but when changed from the SimpleTest PHP library that bug was removed.
The clickLink function is used in several tests so it confirms it works, as it was never broken. Just it should use drupalGet for consistency.
Can add tests, but I think they are unnecessary?
Comment #14
webchickOK cool. I get it now. Thanks, committed.
Comment #15
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.