You are here

public function MathfieldTokenTestCase::testMathfieldDefaultTokens in Math Field 7

Tests using another math field as a tokens in a math expression.

File

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

Class

MathfieldTokenTestCase
Test tokens in math expression fields.

Code

public function testMathfieldDefaultTokens() {

  // Create some simple integer fields.
  $this
    ->createField('field_a', 'A', 'number_integer');
  $this
    ->createField('field_b', 'B', 'number_integer');
  $a = $this
    ->randInteger();
  $b = $this
    ->randInteger();
  $result = number_format($a * $b, 2, '.', '');

  // Give field_a a default value.
  $instance = field_info_instance('node', 'field_a', 'math');
  $instance['default_value'][0]['value'] = $a;
  field_update_instance($instance);

  // Create a math expression to multiply the fields.
  $this
    ->createMathExpressionField('field_result', 'Result', '[field_a] * [field_b]');

  // Create a new math node with the default value for field_a.
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);
  $edit["field_b[und][0][value]"] = $b;
  $this
    ->drupalPost('node/add/math', $edit, t('Save'));
  $this
    ->assertText($result, 'Evaluated a math expression using a token with a default value.');
}