You are here

public function MathfieldListTestCase::testMathfieldSelectList in Math Field 7

Tests using values from select lists in a math expression.

File

./mathfield.test, line 365
Tests for mathfield.module.

Class

MathfieldListTestCase
Test list fields in math expressions.

Code

public function testMathfieldSelectList() {

  // Create some basic integer select lists.
  $this
    ->createField('field_a', 'A', 'list_integer', 1, 'options_select');
  $this
    ->createField('field_b', 'B', 'list_integer', 1, 'options_select');

  // Select a random value for each field.
  $a_field = field_info_field('field_a');
  $a = array_rand($a_field['settings']['allowed_values']);
  $b_field = field_info_field('field_b');
  $b = array_rand($b_field['settings']['allowed_values']);

  // Create the Math Expression.
  $result = number_format($a + $b, 2, '.', '');
  $this
    ->createMathExpressionField('field_result', 'Result', '[field_a] + [field_b]');

  // Create a new math node.
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);
  $edit["field_a[und]"] = $a;
  $edit["field_b[und]"] = $b;
  $this
    ->drupalPost('node/add/math', $edit, t('Save'));
  $this
    ->assertText($result, 'Evaluated a math expression using values from a select list.');
}