You are here

public function MathfieldWidgetTestCase::testMathfieldTextWidget in Math Field 7

File

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

Class

MathfieldWidgetTestCase
Test math field widgets.

Code

public function testMathfieldTextWidget() {
  $this
    ->createField('field_a', 'A', 'number_integer');
  $this
    ->createField('field_b', 'B', 'number_integer');

  // Create a math expression text widget to add the integers.
  $a = $this
    ->randInteger();
  $b = $this
    ->randInteger();
  $result = number_format($a + $b, 2, '.', '');
  $this
    ->createMathExpressionField('field_a_b', 'A + B', '[field_a] + [field_b]');

  // Go to the node add page and make sure the text field exists.
  $this
    ->drupalGet('node/add/math');
  $this
    ->assertFieldByXPath('//input[@type="text" and @name="field_a_b[und][0][value]"]', NULL, 'Math expression text field widget is displayed on the node add form.');

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

  // Make sure the result is displayed on the edit form.
  $this
    ->clickLink(t('Edit'));
  $this
    ->assertFieldByXPath('//input[@type="text" and @name="field_a_b[und][0][value]"]', $result, 'Math expression text field widget is displayed on the edit form.');
}