Drupal 6 SimpleTest does not post hidden fields

10th Mar 2010 // By Chris // Drupal Planet

We recently came across and fixed a problem (not really a bug) with SimpleTest for Drupal 6 that prevents the alteration of hidden values on a form field.

Suppose you have a form with some elaborate controls and you are using jQuery to, for example, register button clicks, and set the value of a hidden input on the form. This is becoming more commonplace as jQuery continues its rise to stardom and allows more aesthetically appealing forms. It turns out that SimpleTest 6.x-2.9 will not allow you to change the value of a hidden form field and then submit the form. Instead, it will complain that it could not set the form field in question!

There is some more information in the SimpleTest issue queue, although it's not immediately obvious that the issue is concerning hidden form fields. The issue has been fixed in SimpleTest for Drupal 7, because of a change to Drupal core, but it seems unlikely that the core change will make it to Drupal 6, because the philosophy is one of only fixing bugs once the major version has been released.

In order to fix this in your Drupal 6 SimpleTest, you will need to add a single line to the drupal_web_test_case.php file. In SimpleTest 6.x-2.9, this is at line 1607, but this might vary for you. The old code looks like this:

  1. case 'textarea':
  2. case 'password':

You will need to add a case for hidden, as follows:

  1. case 'textarea':
  2. case 'hidden':
  3. case 'password':

Obviously hacking a module like this is never favourable; you'll have to remember you have a hacked file in there, so when you update the module, you will have to change it again. Unfortunately there seems to be no other solution if you want to be able to change the values of hidden form fields using SimpleTest for Drupal 6.

About The Author

Chris's Profile Picture
Chris

Chris Cohen is a seasoned web developer who began in Perl, before moving on to Java, C# and currently PHP and Drupal. He regularly attends DrupalCon and is "Certified to Rock" (certifiedtorock.com).

0

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.

New job vacancies button

Categories

Search