You are here

public function MultiformTestCase::testRequiredFields in Multiple forms 7.2

Same name and namespace in other branches
  1. 7 tests/multiform.test \MultiformTestCase::testRequiredFields()

Check required fields.

File

tests/multiform.test, line 76
@author Kálmán Hosszu - http://drupal.org/user/267481

Class

MultiformTestCase
@file

Code

public function testRequiredFields() {
  $first_text = array(
    'multiform[multiform_test2_1][required_text_1]' => 'test1 value',
  );
  $second_text = array(
    'multiform[multiform_test2_2][required_text_2]' => 'test2 value',
  );

  // No required fields.
  $this
    ->drupalPost('multiform-test/2', array(), 'save');
  $this
    ->assertText('test1 field is required.');
  $this
    ->assertText('test2 field is required.');
  $this
    ->assertNoText('multiform_test2_1multiform_test2_submit_button');
  $this
    ->assertNoText('multiform_test2_2multiform_test2_submit_button');

  // Send all required fields.
  $this
    ->drupalPost(NULL, array_merge($first_text, $second_text), 'save');
  $this
    ->assertText('multiform_test2_1multiform_test2_submit_button');
  $this
    ->assertText('multiform_test2_2multiform_test2_submit_button');
  $this
    ->assertNoText('test1 field is required.');
  $this
    ->assertNoText('test2 field is required.');
  $first_text_empty = array(
    'multiform[multiform_test2_1][required_text_1]' => '',
  );
  $second_text_empty = array(
    'multiform[multiform_test2_2][required_text_2]' => '',
  );

  // Send first form's required field.
  $this
    ->drupalPost(NULL, array_merge($first_text, $second_text_empty), 'save');
  $this
    ->assertNoText('multiform_test2_1multiform_test2_submit_button');
  $this
    ->assertText('test2 field is required.');

  // Send second form's required field.
  $this
    ->drupalPost(NULL, array_merge($first_text_empty, $second_text), 'save');
  $this
    ->assertNoText('multiform_test2_2multiform_test2_submit_button');
  $this
    ->assertText('test1 field is required.');
}