Posted by Dries on November 22, 2009 at 9:38am
5 followers
| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | simpletest.module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | boombatower |
| Status: | needs work |
| Issue tags: | Needs Documentation |
Issue Summary
Extend the simpletest framework, and by extension the XML-RPC backend, with an assertXmlrpc() function similar to assertMail(). The function would allow tests to inspect the outgoing XML-RPC messages. This would be very useful for modules like Mollom -- see this related issue: #245682: Enable use of Mollom for any form.
Comments
#1
Fixing the title.
#2
Fixing component.
First step would be to stuff some drupal_alter()s and hook invocations into
- http://api.drupal.org/api/function/xmlrpc_server/7
- http://api.drupal.org/api/function/_xmlrpc/7
heh, both are mostly unchanged since Drupal 4.7... :)
uhm. "mostly"? Entirely, it seems.
#3
After ponding this with my PIFR tests and I finally implemented a test for PIFT. During the writing of the test I realized that XML-RPC does not fit the mold like assertMail() does. It would be rather difficult to properly test XML-RPC without being able to specified responses and such which would require a somewhat large API within SimpleTest. Since XML-RPC already provides everything we need it seems that is the best solution, mock modules ftw.
What I did was create pifr_xmlrpc in the tests directory of PIFT. The module implements the portion of the XML-RPC API that PIFT interacts with. I then enable the module during testing and implement a rudimentary version of the API that provides easy to test results.
For example the API returns the test IDs assigned to tests...the pifr_xmlrpc implementation simply starts from 1 and counts up every time. This makes it easy to create assertions based on that.
I also simulate a test result retrieval by allowing my test to set the XML-RPC response for the related method.
The main benefit of this over straight calling of the XML-RPC methods is that you can simular all conditions around the XML-RPC calls, like cron being the mechanism to start the XML-RPC. My current PIFR tests simply invoke some XML-RPC calls manually, but obviously this is a better way of testing them.
Considering the numerous ways an XML-RPC API may be used and the simplicity of the PIFT mock module I think we should document this as the official way for testing XML-RPC. Take a look:
I will be writing a test for PIFR XML-RPC in the near future.
#4
Suppose this would be more appropriate.
#5
If anything do we want core testing system to come with pifr_xmlrpc_call() and _clear() type functions kinda like SimpleTest has for storing e-mail? That and we could hook into the XML-RPC system so that the testing system automatically catches all the responses instead of sending them out...many times you'll still need to make mock module to run against.
#6
Found a bug working on this #875342: drupal_http_request() should pick up X-Drupal-Assertion-* HTTP headers.
#7
Requires the patch from the issue in #6.
#8
The last submitted patch, 639608-assertXmlrpc.patch, failed testing.
#9
Yep, needs other patch.
#10
Rerolled so we can test before judging the intrinsic value.
#11
The last submitted patch, 639608-assertXmlrpc-10.patch, failed testing.