Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Geting drupal error messages from a page load in ST browser is very important for debugging tests. Now we can easily do this with xpath. This is initial suggestion what we can do. Suggestions?
Comment | File | Size | Author |
---|---|---|---|
#56 | 243532-follow-up-2.patch | 3.58 KB | c960657 |
#50 | 243532-follow-up-1.patch | 1.11 KB | c960657 |
#46 | 243532-simpletest-errors.patch | 6.5 KB | Damien Tournoud |
#44 | 243532-simpletest-errors.patch | 6.43 KB | Damien Tournoud |
#42 | simpletest-errors.patch | 6.22 KB | Anonymous (not verified) |
Comments
Comment #1
chx CreditAttribution: chx commentedI was thinking on doing something with hook_watchdog (implementing it, getting the original db_prefix in user agent and then re-issuing a watchdog for the original DB) but that would only cover errors that have a watchdog -- drupal_error_handler has one but there are many errors that don't. So, +1 for this solution.
Comment #2
boombatower CreditAttribution: boombatower commentedI made a few changes:
assertDrupalErrors
since get implies that it returns something. (at least that is my interpretation)messages error
instead ofmessages errors
which doesn't work.Any comments?
Comment #3
boombatower CreditAttribution: boombatower commentedMoving.
Comment #4
Dries CreditAttribution: Dries commentedWhen I first read 'assertDrupalErrors()' I thought the function should be called 'assertNoDrupalErrors()'. I thought we wanted to assert that there are _no_ Drupal errors.
This is a useful little function and can probably be called at a million places ... It might actually be better to _always_ fail on these errors unless you specify that you expect errors. Not 100% sure about this one, but it looks better than having to sprinkle a ton of tests with this function?
Comment #5
boombatower CreditAttribution: boombatower commentedI'm not sure I would want to always fail since many times the tests attempt to break things. Having both
assertDrupalErrors
andassertNoDrupalErrors
could be handy, but instead of outputting the errors as failures simply make one pass or fail based on the method that is called.I would vote for changing it to that. Any comments?
Comment #6
boombatower CreditAttribution: boombatower commentedI have re-implemented the idea in this patch.
To test this code you can use the following test function.
Toggle which one of the first two requests is called and check the assertion messages.
Comment #7
Dries CreditAttribution: Dries commentedI think this looks good. It's probably a good idea to check if any of the existing tests could take advantage of these calls. That would validate the suggested API. Ideally, it would simplify some of the existing tests.
Comment #8
boombatower CreditAttribution: boombatower commentedI guess before I got through all the tests and implement this new method it would be good to decide if we want to make this work for messages in general.
Either have two different sets of methods one for errors and one for messages, make the two methods work for both with a flag, or make them always look at either.
The only code that would need to change to make any of that work would be:
Many of the tests check for messages using
assertText
. Allowing this function to be able to check the messages would make that check slightly more sure, but at the same time it doesn't allow for messages to be placed on each of the individual asserts.For example:
Instead that would become apart of a single summary message.
Any comments?
Comment #9
Dries CreditAttribution: Dries commentedbut at the same time it doesn't allow for messages to be placed on each of the individual asserts.
I don't understand what you mean with this. The way that sentence is constructed confuses me. Can you try to rephrase? Thanks.
Comment #10
boombatower CreditAttribution: boombatower commentedIf the new function is used you pass an array of messages to check for and it creates one assertion message. As apposed to:
would be replaced with:
So you would never see message1, message2, etc.
Comment #11
Dries CreditAttribution: Dries commentedI think that is fair as long the error message that is automatically generated is helpful.
Comment #12
boombatower CreditAttribution: boombatower commentedAlso as of #8 do we want to make this work for message (not errors) as well?
Comment #13
Dries CreditAttribution: Dries commentedI think we want to make this work for messages (not errors) as well.
Comment #14
boombatower CreditAttribution: boombatower commentedAlright I thought about the usefulness of the methods for a while and came up with this.
If we decide this is a good set then I will implement them in all the tests.
Comment #15
dropcube CreditAttribution: dropcube commentedI don't know if something like this has been discussed earlier, but what about if we output some data inserted in the HTML output when a simpletest User-Agent is used. The data can be used by tests, which currently only receive the HTML output. The data could be: messages, errors, the current Drupal path (to check if forms redirect properly), the current user, ..., and other that is not possible or is hard to extract from the HTML output. For example:
This way, assert functions does not need to deal with complex XPath expressions, and would appear an accurate version of
$this->assertText(t('The configuration options have been saved.'), ..
to assert if a message has been set.Comment #16
boombatower CreditAttribution: boombatower commentedI think this might be done in addition to a SimpleTest theme.
I have played with the idea and it is the only way to make the tests independent of themes, which they should be. Testing for the theme layer should be separated out.
I think this could fall under that. I haven't gotten around to making a SimpleTest theme, but I think that would be the best way to go about this and be the best way to make assertions without having to worry about HTML.
Things like:
could be possible without xpath (not that xpath is bad, quiet awesome in fact).
Comment #17
dropcube CreditAttribution: dropcube commentedThings like this
$errors = $this->elements->xpath("//div[@class='messages status'] | //div[@class='messages status']");
makes tests dependent of themes. A good approach could be to force Drupal to output a XML response when the simpletest user-agent is used and make the testing system consume XML, instead of the HTML output.The XML response could look like this (and any other data we need to include in the XML):
This way, tests can have access to data that is only available in the testing thread. Note that we still could have the HTML output, to parse forms fields, or whatever.
Comment #18
Damien Tournoud CreditAttribution: Damien Tournoud commentedI don't like the idea of a simpletest theme. After all we are testing a global product (Drupal on Garland), and thus it makes sense to test the behavior of the theme layer too. Moreover, a special theme or a special output will increase the maintenance work.
However, I worked on a way to pull error messaging from the tested site by the way of HTTP headers. This could be applied to messages too. Attached a patch for this general idea.
Comment #19
dropcube CreditAttribution: dropcube commented@Damien: It's not only about error messages, we are in need to have access to other data that is only available in the separate testing thread (request) and that can not be parsed from a HTML output. The idea of HTTP header works well for error messages, but with other complex data it may not.
I am going to create other issue for this.
Comment #20
Damien Tournoud CreditAttribution: Damien Tournoud commented@dropcube, I'm not sure what you mean by "other complex data". We should not have a lot of data to fetch, and we could very well serialize more complex data. But I agree we need a separate issue for that.
Comment #21
dropcube CreditAttribution: dropcube commented@Damien: I mean any data that can be available to make accurate assertions and that was available during the test request.
I have created an issue: #266220: Exposing metadata to tests
Comment #22
boombatower CreditAttribution: boombatower commentedWait on #266220: Exposing metadata to tests to be decided.
Comment #23
moshe weitzman CreditAttribution: moshe weitzman commentedDamien's patch in #18 is very useful, and should not be postponed in favor of vaporware IMO. Perhaps those headers should only be sent if the request came in with the simpletest user agent. Thats a small point though. These sorts of improvements make fixing tests much easier and therefore more people get involved.
We need a little more progress here to decide how this info gets reported back on the results page.
Comment #24
dropcube CreditAttribution: dropcube commentedAgreed in the sense that these sort of improvements make testing easier. However, sending special HTTP headers the data can't be parsed using xpath or XML which are more complete solutions. Moreover, we are not only in need of this data, we will be requiring other more complex set of data.
Comment #25
chx CreditAttribution: chx commentedCurrent fatal error mean all you get is a fatal error on the page which can be checked for one. Other errors are catched by the test if I am not mistaken.
Comment #26
Damien Tournoud CreditAttribution: Damien Tournoud commented@chx: no, other errors are not catch if they occur on the *tested* side. Only exception from the tester side are currently reported. Thus my proposal in #18.
Other than that, I agree we should try to parse fatal errors from the output, too (PHP error handler probably can't catch them).
Comment #27
dropcube CreditAttribution: dropcube commented@chx:
Yes, I agree with Damien, it's about the notices/warnings/errors on the 'tested' thread. Is this what you mean?
Comment #28
Anonymous (not verified) CreditAttribution: Anonymous commentedi'm not convinced either way about #266220: Exposing metadata to tests, but the patch at #18 or something similar would have saved me a chunk of time tonight.
what do we need to get this moving forward?
Comment #29
Anonymous (not verified) CreditAttribution: Anonymous commentedupdated patch at #18, implemented
simpletest_get_severity_as_string($severity)
.running all tests, we get tests where everything passes *and* exceptions are thrown.
Comment #30
Damien Tournoud CreditAttribution: Damien Tournoud commentedI'll like #304924: Extend drupal_error_handler to manage exceptions to get reviewed and go in first.
Comment #31
Damien Tournoud CreditAttribution: Damien Tournoud commentedHere is an updated version of a previous work I did in #304924: Extend drupal_error_handler to manage exceptions. Based on #304924: Extend drupal_error_handler to manage exceptions, you should apply the other one first (the testbot may be angry).
Comment #32
CorniI CreditAttribution: CorniI commentedsubscribe
Comment #33
Damien Tournoud CreditAttribution: Damien Tournoud commentedUpdated the patch to follow #304924.
Comment #34
Damien Tournoud CreditAttribution: Damien Tournoud commentedNow that #304924 is in, here is an updated patch.
Comment #35
moshe weitzman CreditAttribution: moshe weitzman commentedWill assertions ever get very long? There is a limit to the length of http headers. Have a look at how Firephp handles this - http://www.firephp.org/Wiki/Reference/Protocol. They have groovy code to split objects across multiple headers and put them back together on the receiving side. Perhaps this is overkill here.
Comment #37
Damien Tournoud CreditAttribution: Damien Tournoud commented@moshe: as far as I know, there is nothing limiting the length of HTTP headers.
Comment #38
Damien Tournoud CreditAttribution: Damien Tournoud commentedYou will get a lot of notices when running the full suite with that patch.
#321828: maintenance_page not registered correctly in drupal_common_theme() fixes the Simpletest functionality test (that's a D6-7 bug, so treated independently).
Some more D7-specific fixes (Session, Drupal error handler tests) in that new patch.
Comment #39
moshe weitzman CreditAttribution: moshe weitzman commentedThis is one of the most important patches of the year. Finally we have good visibility into the tested side. This RTBC.
Attached is a screenshot which shows notices when running the simpletest test (Damien submitted a separate patch which fixes these).
Comment #40
Anonymous (not verified) CreditAttribution: Anonymous commentedcode looks good, patch applies cleanly.
until the file is committed, you'll need to manually get the
includes/database/log.inc
from that issue to run all tests.ran all tests with the caveat above, all pass, plus 49 exceptions...
7065 passes, 0 fails, 49 exceptions
.Comment #41
moshe weitzman CreditAttribution: moshe weitzman commentedWould be very nice to get some committer feedback on this.
Comment #42
Anonymous (not verified) CreditAttribution: Anonymous commentedbump. rerolled patch to get rid of fuzz, no code changes. running all tests, i get:
7105 passes, 0 fails, and 51 exceptions
once this is in, we can chase down the exceptions.
Comment #43
Dries CreditAttribution: Dries commentedCan we add a code comment to this line:
+ call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1])));
. Thanks.Comment #44
Damien Tournoud CreditAttribution: Damien Tournoud commentedAdded code comments.
Comment #45
Dries CreditAttribution: Dries commentedMuch better. Please also describe
call_user_func_array(array(&$this, 'error')
(e.g. what function is being called).Comment #46
Damien Tournoud CreditAttribution: Damien Tournoud commentedComment #47
Damien Tournoud CreditAttribution: Damien Tournoud commentedHere are the issues that need to get fixed to get back to 0 fails:
Comment #48
Damien Tournoud CreditAttribution: Damien Tournoud commented#329229: SimpleTest does not map PHP errors that occur during curl requests to exceptions. was a duplicate :)
Comment #49
Dries CreditAttribution: Dries commentedReviewed, tested, committed to CVS HEAD. Let's sprint towards fixing those exceptions! Thanks.
Comment #50
c960657 CreditAttribution: c960657 commentedIt doesn't work when $db_prefix != '' (it probably did prior to the checkin for #328719: Module list functionality test fails a few days ago). This is fixed by this small patch.
$GLOBALS['db_prefix'] contains "simpletest\d" on both the tester side and the tested side, but we only need to set headers on the tested side, so it is sufficient to check HTTP_USER_AGENT (on the tester side this error handler isn't used, because Simpletest provides its own error handler than is registered prior to changing $db_prefix).
Comment #51
webchickIt'd be nice to get Damien to look at c960657's fix. Whenever I see HTTP_USER_AGENT I always feel a bit dirty.
A couple things to check:
* Does running tests from the command line still work?
* check if you throw a notice on the test side (not through drupalPost|Get) and see if it reports as exception with patch applied (from boombatower)
Comment #52
c960657 CreditAttribution: c960657 commentedThe HTTP_USER_AGENT approach is also used in include/database/database.inc. But I agree that it is not pretty. This is being addressed in #329177: Get rid of ugly simpletest regexp.. See also #276008: Missing user agent triggers notice.
Comment #53
webchickOk. The last of the test failure fixes went in tonight. I'd like to commit c960657's patch to finish off this issue, but I would still like confirmation from someone who understands this code a bit better than I do that this is the right fix, as well as the items in #51 work.
Comment #54
Damien Tournoud CreditAttribution: Damien Tournoud commented@webchick: the fix is ok.
Since #328719: Module list functionality test fails, we prefix the db_prefix of the tested site with the db_prefix of the testing site.
ie. if you are running the test inside a Drupal installation with $db_prefix = "mysite_", tested sites will be $db_prefix = "mysite_simpletest4647244"
The test on the HTTP_USER_AGENT is exactly the same as in Database::openConnection(), so everything is good here.
We made some work with c960657 to abstract those check into a nice and clean simpletest_id() function in #329177. In the meantime, RTBC, and end that November-make-the-tests-pass-again-frenzy.
Comment #55
webchickOk, awesome. Thanks folks! :D
Committed to HEAD!
Comment #56
c960657 CreditAttribution: c960657 commented_drupal_report_error()
drupal_web_test_case::curlHeaderCallback()
This code assumes, that the third argument for drupal_web_test_case::error(), $caller, is the function name. But actually error() requires an associative array with the keys 'function', 'file' and 'line'.
I discovered this with E_STRICT error reporting enabled.
This patch adds type hinting to error() and _assert() (this would have made debugging this error easier), and makes _drupal_report_error() pass the file name and line number as well. The Doxygen comment for error() is elaborated (based on the comment for _assert()).
(is it okay to reopen the issue for things like this, or should I rather file a new issue?)
Comment #57
Damien Tournoud CreditAttribution: Damien Tournoud commentedWell, this is not the good issue. The broken code was introduced by #328781: Fix horrible things in the error reporting.
Also, if I'm not mistaken we have a test for this, so how come this was not spotted earlier?
Edit: I was mistaken: we have no test for this.
Comment #58
c960657 CreditAttribution: c960657 commentedAh, sorry, I'll post the patch over there instead.