You are here

public function MathfieldTestCase::createMathExpressionField in Math Field 7

Create a math expression field and instance.

Parameters

string $field_name: The name of the field to create.

string $label: The field label.

string $expression: The math expression to evaluate.

string $widget: The form widget. 'mathfield_text' or 'mathfield_readonly'.

8 calls to MathfieldTestCase::createMathExpressionField()
MathfieldListTestCase::testMathfieldRadioList in ./mathfield.test
Tests using values from radio button groups in a math expression.
MathfieldListTestCase::testMathfieldSelectList in ./mathfield.test
Tests using values from select lists in a math expression.
MathfieldTokenTestCase::testMathfieldAdvancedTokens in ./mathfield.test
Tests advanced tokens in math expression fields.
MathfieldTokenTestCase::testMathfieldBasicTokens in ./mathfield.test
Tests basic tokens in math expression fields.
MathfieldTokenTestCase::testMathfieldDefaultTokens in ./mathfield.test
Tests using another math field as a tokens in a math expression.

... See full list

File

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

Class

MathfieldTestCase
Base class for testing the mathfield module.

Code

public function createMathExpressionField($field_name, $label, $expression, $widget = 'mathfield_text') {

  // Create the field.
  $field = array(
    'field_name' => $field_name,
    'type' => 'mathfield',
    'cardinality' => 1,
    'settings' => array(
      'expression' => $expression,
    ),
  );
  $field = field_create_field($field);

  // Create the instance.
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'node',
    'bundle' => 'math',
    'label' => $label,
    'weight' => mt_rand(0, 127),
    'widget' => array(
      'type' => $widget,
      'label' => $label,
    ),
    'display' => array(
      'default' => array(
        'type' => 'number_decimal',
        'settings' => array(
          'thousand_separator' => '',
          'decimal_separator' => '.',
          'scale' => 2,
        ),
      ),
    ),
  );
  field_create_instance($instance);
}