Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am trying to write the test case for my custom ajax functionality in Drupal 7. I am firing the event on click in my .js file but the test case gets a fail.

In my .tpl.php template file I have the following code:

<a href="javasctipt:void(0)" id="myFirstEvent">Click Here</a>

In the Js file I am getting the event as follows:

$('#myFirstEvent').live('click', function())
$.ajax({
        cache: false,
        url: Drupal.settings.basePath + '?q=mymodule/add',
        data: {page: page, sort: sort, order: order},
        dataType: 'text',
        error: function(request, status, error) {
            alert(status);
        },
        success: function(data, status, request) {
            /**Function definition goes here**/

}

In my custom.test file I have the following:

$edit = array();
$this>drupalGet("myform/add");
$this->drupalPost('myform/add', $edit, 'myFirstEvent');
$this->assertResponse(200, 'Success');

But I am not getting the success screen (Green Color) after I execute my test cases.

share|improve this question
    
this module may help you –  Serjas Oct 22 '12 at 11:27
    
Serjas can figure our this problem? –  Ravindra Singh Oct 22 '12 at 13:24
    
first of all you have to wrap entire jquery code inside (function($) { // your code here }) (jQuery); –  Serjas Oct 23 '12 at 5:24
    
Serjas did you worked on (.test) file for functionality testing in drupal modules? –  Ravindra Singh Oct 23 '12 at 9:44

1 Answer 1

You cannot test custom javascript with simpletest because it simply ignores them. Simpletest can simulate the ajax behavior (via xpath) only if you add that to the form with the #ajax property. http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#ajax

To test custom js you might want to have a look at Selenium.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.