public function MathfieldListTestCase::testMathfieldRadioList in Math Field 7
Tests using values from radio button groups in a math expression.
File
- ./
mathfield.test, line 395 - Tests for mathfield.module.
Class
- MathfieldListTestCase
- Test list fields in math expressions.
Code
public function testMathfieldRadioList() {
// Create some float radio buttons.
$this
->createField('field_a', 'A', 'list_float', 1, 'options_buttons');
$this
->createField('field_b', 'B', 'list_float', 1, 'options_buttons');
// 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 radio button group.');
}