1

With SimpleTests, I want to test a form similar to :

  // Textfield :
  $form['fieldset_name']['test'] = array(
    '#type' => 'textfield',
    ...
  );
  // Submit :
  $form['fieldset_name']['submit_button'] = array(
    '#type' => 'submit',
    '#submit' => array('my_module_form_submit'),
    '#value' => 'Submit button',
  );

This form is accessed from 'admin/config/my_module'. So I add the following test in my_module.test :

  function testForm() {
    $path = 'admin/config/my_module';
    $edit['test'] = 'testing field\'s input';
    $this->drupalPost($path, $edit, t('Submit button'));
  }

When I run the test, it fails with these errors :

Failed to set field test to testing field\'s input

Found the Add button (failed)

Where am I wrong ?

  • $edit has to be keyed with field name. Did you check if "test" is the field name for which you are trying to set the value? – Srihitha Narra Jul 10 '12 at 1:38
  • I know that, the problem was related to my configuration setting $this->setup =TRUE, I switched back to normal testing environment tables and it went OK. – B2F Jul 10 '12 at 10:03
1

Permissions would be my first guess.

Enable debug output in the Simpletest settings and then check if your module is installed and you have permissions to visit that page.

  • I used drupalLogin and loaded a user with 'access administration pages', the account is used (its tests pass) but the form's test output same errors. The module is enable and and I used $this->setup = TRUE : is it the problem ?. – B2F Jul 9 '12 at 19:54
  • access administration pages has no magic meaning, it's just a permission as any other, you need to specify the exact permission required by your module. As I said, enable debugging, it should write each requested page into a file and add a link to it so that you can see what the test sees. No idea if it's because of the overriden setUp(), could be, debug output might tell you that. I've commented on your question why I find it a bad idea in general ;) – Berdir Jul 9 '12 at 20:00
  • There is some progress from greggory.hz's question I used profile = testing and a proper environment, now the test seems to work. About debug output, do you mean verbose ? because I see no debug option in settings. – B2F Jul 9 '12 at 20:13
  • Yes, that's the setting I meant. – Berdir Jul 9 '12 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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