In Drupal 6's excellent SimpleTest module, a method called drupalPost() allows you to simulate a button press on a form by taking the form's data and using HTTP POST to submit it. But what if you want to POST data to an AJAX callback URL? By default, SimpleTest checks which submit button you have pressed, but of course, when POSTing using AJAX, you probably won't have pressed a button!
Suppose you have a table of email addresses, as illustrated below, and you want your users to be able to remove them. It would be quite inconvenient to make the user check a box, press 'delete' and then wait for the page to refresh. Instead, you can provide an AJAX callback URL that will allow the email address to be removed when the 'remove' button is pressed, without needing to reload the page, making it much easier for your users.

This generally works by having a URL, say /mymodule/delete-email, and having your JavaScript (jQuery in Drupal's case) take care of making a POST request to that URL, the POSTVARS containing perhaps the email address that is to be removed.
Now suppose this is all set up, but we want to write some tests for this functionality. There is no actual form on the page, so SimpleTest quickly runs into issues. We want to use SimpleTest's drupalPost() to make the POST request, but, as mentioned in the documentation, we need to pass a 'submit' parameter that tells SimpleTest to make sure that the appropriate submit form element is on the page, and make sure it has been pressed.
There is no way of having SimpleTest 'ignore' this submit parameter. It absolutely must be provided, and the test will fail unless that particular submit button is found on the form page.
The solution
I dug around for solutions to this problem, and asked in the Drupal IRC channels for help, but nothing was forthcoming, so I decided that the best way forward was to write my own function. In my module, I have written a 'base' class that inherits directly from DrupalWebTestCase, and then all my test classes inherit from this base.
I simply added this method to my base class, thereby making it available to all test classes:
- /**
- * Simplified version of drupalPost() that allows posting to AJAX.
- *
- * This version of the function removes the check on the submit button, so
- * it can be used to POST data to an AJAX callback URL. It does no checking
- * on the result of the POST, so you will need to handle this yourself.
- */
- $action = $this->getAbsoluteUrl($path);
- $post = $edit;
- foreach ($post as $key => $value) {
- // Encode according to application/x-www-form-urlencoded
- // Both names and values needs to be urlencoded.
- }
- $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers));
- // Ensure that any changes to variables in the other thread are picked up.
- $this->refreshVariables();
- $this->pass('simplePost has posted data to ' . $path);
- }
This works very similarly to the way drupalPost() works, except that it does not require the 'submit' parameter to be supplied. Of course, it's a very stripped-down version, without the possibility of uploading files and without some of the more stringent checking done by drupalPost(), but it does work, and allows testing of AJAX callback URLs inside your Drupal tests.
Without this method, I would have resorted to testing only the actual functions in my module, more akin to a unit test, which would not check that the menu callbacks were correctly assigned and that all the access permissions were set up correctly. It's clearly not the ideal way to go about testing AJAX callbacks, so what method have you been using, and how would you improve on this?
Comments
Simpletest in Drupal 7 (features are usually backported, so it might be in D6 already or at least soon) has a method called drupalPostAJAX(), haven't used it myself though, but there are AJAX tests in D7.
Nice information, I was looking for the same thing, hoping it was built into Drupal 6, but couldn't find it either. Your function works well for me.
I noticed your function left out some of the verbose output that drupalPost has. I just added these lines at the end of the function, that I took right from the end of drupalPost.
$this->verbose(
'POST request to: ' . $path .
'Ending URL: ' . $this->getUrl() .
'Fields: ' . highlight_string('<?php ' . var_export($post, TRUE), TRUE) .
'' . $out);
return $out;
This is great but there is an underlying assumption I think that if you use curl in this way you have to let anonymous users have permissions to make the post or find a way to use the session with curl.
Thanks for a great solution to a tricky problem
Correct myself, Drupal's simpletest classes have its own implementation of curl with session support - so this solution is even better than I thought originally.
Just got this working for my module
go here
Excellent Web Hosting Advice For Anyone To Utilize
Maybe you have issues finding a services that is dependable and offers the characteristics that you require. Discovering the right number is difficult as a result of many different available choices. The tips incorporated in this article will give you the advantage of the data of your own friends who definitely have been from the most awful and come out with a web-based host that did the trick eventually.
Upon having selecting your online hosting firm, you need to prefer to make obligations monthly, in contrast to investing in an extended time period. You can't forecast what your business is going to be or what your variety is going to do in the approaching months. If your enterprise expands too large for that variety or your business closes, you may get rid of the money you paid out, except when the hold says normally.
Internet hosting service providers value their reputations, because you can learn a great deal from what end users record. Investigation web hosts to see which possess a dependable standing and a long report of excellent assistance. This can also help you type out those who don't have a great track record.
Specific website hosts will assist you to obtain a reimbursement proportional to the amount of downtime your internet site endures. This will never be a great deal of reimbursement when compared with a decrease in sales through the down time. You should choose a web hosting answer that offers dependable up-time rather than reimbursements for being off-line.
Should your web hosting service gives on-line talks, forums or putting up boards, then utilize them for direct access to details about them. If you can ask about your issues, you may eliminate professional services that won't be right for you. Choosing the right host company is going to be simpler when you affirmed by excellent critiques. Provided you can consult with a present consumer of any firm, they will likely be the best individual to determine specifics of a business you are searching for.
When you are a amateur in web page design, choose a hosting company which offers wonderful customer satisfaction as opposed to a great deal of bells and whistles. When you first begin there are tons of questions that show up in your thoughts about internet hosting, so you're likely to desire a variety which includes fantastic customer care available and able to answer your inquiries. The tech support that you will get coming from a organization with excellent customer support is going to be much more useful to you compared to a package deal of functions you may never use.
Have you been considering web hosting service your internet site using a totally free hosting provider? You will need to maintain your very own back ups of all the your significant data, considering that totally free hosting solutions often have minimum back-up services, if any. As a result, if something disappears, you're out of luck.
Opt for your host based on a selection of criteria instead of generating your final decision based on value by yourself. Abandon your choices available so that you can find what works the best for you. Take a look at all aspects prior to selecting your variety and after that pick a program that is within your budget. Make sure that the number provides every little thing needed.
When choosing a web web hosting service business, it is a good idea to pick one who has brought several honors. If your business has several internet hosting prizes, for example, this can provide a great sensation of the help and repair they provide. Having an prize is an excellent sign that the web hosting company is dependable and possesses a lot of happy buyers. Search for hosts that have gained awards which were given based upon client votes these are generally your best bet.
Ensure you know any straight down occasions your online web hosting service support might have planned. It is right for the maintenance to get scheduled at most monthly. If it's more frequently than that, it can lead to too much downward time for the website.
If moving your website to a different number is something you are considering, make sure to research into no matter if you will end up permitted to move your domain name. Some hosts will keep your web site name if you keep. Then you will need to change your brand, perplexing your while guests.
A lot of internet hosts will give you a number of accessories who go as to what their support, but these features differ from host to hold. Stay with the firms that offer the services you require. By way of example, some characteristics may only be around on greater-listed programs, so be on the lookout for related conditions and terms.
While searching for a web number, perform some more investigation on the web in addition to simply reading through the host's web site and promo components. Head to sites that are unbiased and get no link to your provider, then read through customer reviews there. These testimonials will allow you to understand a quality assistance from other hosts.
Some website hosts use a more substantial host to deliver their offerings for your needs. These companies invest in a prohibit of area about the hosting server at a discount, and convert a profit by leasing space to more compact sites. You can examine out different online hosts underneath the very same business, you might get a much better package by doing this!
Study your commitment carefully, and get the internet host company to clarify any uncertain terminology to you. Service fees and clauses will never be conveniently apparent in the main written text of the agreement. No sales hype will almost certainly position them to you. Consider the total expense of the assistance, including put in place charges and fees and penalties for early cancellation, prior to signing in the dotted collection.
A web variety needs to have several back contacts in the event their main one moves off-line. Ensure the web hosts you are looking at have this. Should your hosting company just has one particular relationship to the net, this can be risky because of the fact that when it goes traditional, your internet site will likely go traditional. Ensure the firm has redundant relationships and this every one of these links is capable of helping your blog.
To conclude, it can be challenging to find the best web host. Because of the large number of elements that must be taken into account, it can be hard to determine which hosting company will probably be suitable. Here are some ideas when choosing a web-based number to suit you and your organization.
Editors, who receive no royalties or expenses and who
are only mymoneymonitor very rarely commissioned by the Society, are encouraged to approach the
Editorial Secretary with a detailed proposal of the text mymoneymonitor they wish to suggest to
the Society early in my money monitor their work; interest may be expressed at that point, but
before any text is accepted for publication the final typescript must be approved
by the Council (a body of some twenty scholars),my money monitor and then assigned a place in the
printing schedule.
Hello My Dear Friends, Users Forum !
The Company In-Disguise . Com
Anonymous Internet Surfing, Anonymous Downloading-Uploading Torrent-P2P, Amonymous WiFI.
In-Disguise . Com - Fully Automatic and Anonymous VPN Service , you don’t have to waste time on:
1 - Search Supports if disconnected from a server, search for a standard installation “OpenVPN client”
spend time for installing downloaded configs to the program.
Subscribe to All Servers of Our Service for 9 Euro; 3 months = 20 Euro; 6 months = 35 Euro; 1 year = 55 Euro.
2 - Unique “VPN Client” is easy to install on all kinds of Operating Systems: MAC / Windows / Linux!!!
Will allow you to switch easily between the VPN servers in USA / DE / UK / IT / NL / LU / EG / PA / RO / MY Continuing
Types of VPN connections included in a single subscription - DoubleVPN and OpenVPN.
3 - Company Takes All Kinds Of Payments in Full Auto Mode!
WebMoney / Visa / Master Card / PayPal / Liberty Reserve / BitCoin / SMS and many others.
Our VPN Service Is Here!
in-disguise . com
ICQ: 6906911
Sincerely, Your Anonymous VPN Service : In-Disguise . Com










