Correct simpletest syntax for selecting taxonomy?

Events happening in the community are now at Drupal community events on www.drupal.org.
starbow's picture

I am trying to functional testing on a custom node creation form, and cannot figure out the correct syntax for selecting the taxonomy terms.

The form in question looks kinda like this:

<select name="edit[taxonomy][14][]" multiple="multiple"  class="form-select" id="edit-taxonomy-14"  size="9"><option value="0">&lt;none&gt;</option><option value="187">British Telecommunications</option><option value="269">Carnegie Mellon University</option><option value="289">ETC</option></select>
<input type="text" maxlength="128" name="edit[first_name]" id="edit-first_name"  size="60" value="" class="form-text" />
<input type="text" maxlength="128" name="edit[last_name]" id="edit-last_name"  size="60" value=""  class="form-text required" />
<input type="submit" name="op" value="Submit"  class="form-submit" />

I have tried each of:

<?php

    $edit
= array();

//    $edit[ 'taxonomy' ] = array( '14' => array('187') );
//Fail: CITRIS -> Create Citris Person -> testCitrisPerson -> [browser] Setting edit[taxonomy]="Array" at [C:\Program Files\xampp\htdocs\upgrade47\sites\default\modules\simpletest\drupal_test_case.php line 46]   

//    $edit[ 'taxonomy][' ] = array( '14' => array('187') );
//Fail: CITRIS -> Create Citris Person -> testCitrisPerson -> [browser] Setting edit[taxonomy][]="Array" at [C:\Program Files\xampp\htdocs\upgrade47\sites\default\modules\simpletest\drupal_test_case.php line 46]   

//    $edit[ 'taxonomy][14' ] = '187';
//Fail: CITRIS -> Create Citris Person -> testCitrisPerson -> [browser] Setting edit[taxonomy][14]="187" at [C:\Program Files\xampp\htdocs\upgrade47\sites\default\modules\simpletest\drupal_test_case.php line 46]

//    $edit[ 'taxonomy][14' ] = array('187');
//Fail: CITRIS -> Create Citris Person -> testCitrisPerson -> [browser] Setting edit[taxonomy][14]="Array" at [C:\Program Files\xampp\htdocs\upgrade47\sites\default\modules\simpletest\drupal_test_case.php line 46]

//    $edit[ 'taxonomy][14][' ] = array( '14' => array('187') );
//Fail: CITRIS -> Create Citris Person -> testCitrisPerson -> [browser] Setting edit[taxonomy][14][]="Array" at [C:\Program Files\xampp\htdocs\upgrade47\sites\default\modules\simpletest\drupal_test_case.php line 46]

//    $edit[ 'taxonomy][14][' ] = '187';
// Exception: CITRIS -> Create Citris Person -> testCitrisPerson -> Unexpected PHP error [Invalid argument supplied for foreach()] severity [E_WARNING] in [C:\Program Files\xampp\htdocs\upgrade47\sites\default\modules\simpletest\simpletest\tag.php line 820]

   
$edit['first_name'] = 'Bob';
   
$edit['last_name'] = $this->randomName(10);
   
$this->drupalPostRequest( 'node/add/citris_person', $edit, 'Submit' );
    die (
"Stop to examine the results - node created, but no term associated");
?>

I found a comment in taxonomy.module.test that multiple select and drupalPostRequest do not get along. So I tried what they had:

<?php
   
// multiple slect box was failing through drupalPostRequest. Use raw POST instead
   
$edit = array('edit[first_name]' => 'Foo', 'edit[last_name]' => $this->randomName(10), 'edit[taxonomy][14][]' => array('187') );
   
$url = url('node/add/citris_person', NULL, NULL, TRUE);
   
$this->post($url, $edit);
    die (
"Stop to examine results - nothing.  Node not created at all");
?>

Any help out there?
thanks,
-tao

Comments

Selenium

starbow's picture

Since posting this I have realized that Selenium is much easier to use for functional testing.

SimpleTest in Drupal 5

Souvent22's picture

Hey guys, I've update the patch for Drupal 5 to including simpletest testing. We wondering if I could get a bit of help reviewing it; also, there seems to be an issue with the Taxonomy nodeapi....for some reason, it will not create the vocab's? It's very strange, the db_query function in the taxonomy function runs, throw no errors, but nothing is in the database? like it's working against a phantom database.
Here's a link to the patch:
http://drupal.org/node/128707

Testing and Quality Assurance

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: