public function MathfieldTokenTestCase::testMathfieldAdvancedTokens in Math Field 7
Tests advanced tokens in math expression fields.
File
- ./
mathfield.test, line 258 - Tests for mathfield.module.
Class
- MathfieldTokenTestCase
- Test tokens in math expression fields.
Code
public function testMathfieldAdvancedTokens() {
// Create a multivalue integer field.
$this
->createField('field_multiple', 'Multiple', 'number_integer', 4);
// Find the root of the 2nd item in a multivalue field.
$a = abs($this
->randInteger());
$result_a = number_format(sqrt($a), 2, '.', '');
$this
->createMathExpressionField('field_adv_a', 'Advanced A', 'sqrt([field_multiple:1])');
// Use the 1st item in a multivalue field in a custom function (square).
$b = $this
->randInteger();
$result_b = number_format(pow($b, 2), 2, '.', '');
$this
->createMathExpressionField('field_adv_b', 'Advanced B', 'f(x) = x^2; f([field_multiple:value])');
// Double the 3rd item in a multivalue field.
$c = $this
->randInteger();
$result_c = number_format($c * 2, 2, '.', '');
$this
->createMathExpressionField('field_adv_c', 'Advanced C', '[field_multiple:2:value] * 2');
// Create a new math node.
$edit = array();
$edit['title'] = $this
->randomName(8);
$edit["field_multiple[und][0][value]"] = $b;
$edit["field_multiple[und][1][value]"] = $a;
$edit["field_multiple[und][2][value]"] = $c;
$this
->drupalPost('node/add/math', $edit, t('Save'));
$this
->assertText($result_a, 'Evaluated a math expression using an advanced tokens in the form [$field_name:$delta].');
$this
->assertText($result_b, 'Evaluated a math expression using an advanced tokens in the form [$field_name:$column].');
$this
->assertText($result_c, 'Evaluated a math expression using an advanced tokens in the form [$field_name:$delta:$column].');
}