You are here

function CurrencySignFormElementWebTestCase::testValidation in Currency 7.2

Test validation.

File

currency/tests/CurrencySignFormElementWebTestCase.test, line 35
Contains class CurrencySignFormElementWebTestCase.

Class

CurrencySignFormElementWebTestCase
Tests the currency_amount form element.

Code

function testValidation() {
  $path = 'currency_test-form-element-currency-sign';

  // Test an empty sign.
  $values = array(
    'sign[sign]' => '',
  );
  $this
    ->drupalPost($path, $values, t('Submit'));
  $this
    ->assertUrl('user');
  $this
    ->assertRaw("\$form_state['sign'] = ''");

  // Test a suggested sign.
  $values = array(
    'sign[sign]' => '¤',
  );
  $this
    ->drupalPost($path, $values, t('Submit'));
  $this
    ->assertUrl('user');
  $this
    ->assertRaw("\$form_state['sign'] = '¤'");

  // Test a custom sign.
  $values = array(
    'sign[sign]' => CURRENCY_SIGN_FORM_ELEMENT_CUSTOM_VALUE,
    'sign[sign_custom]' => 'foobar',
  );
  $this
    ->drupalPost($path, $values, t('Submit'));
  $this
    ->assertUrl('user');
  $this
    ->assertRaw("\$form_state['sign'] = 'foobar'");
  $this
    ->drupalGet($path . '//foobar');
  $this
    ->assertRaw('<option value="' . CURRENCY_SIGN_FORM_ELEMENT_CUSTOM_VALUE . '" selected="selected">');
  $this
    ->assertRaw('<option value="' . CURRENCY_SIGN_FORM_ELEMENT_CUSTOM_VALUE . '" selected="selected">');

  // Check if the sign element is set to a custom value.
  $this
    ->assertFieldByXPath("//select[@name='sign[sign]']/option[@value='" . CURRENCY_SIGN_FORM_ELEMENT_CUSTOM_VALUE . "' and @selected='selected']");

  // Check if the custom sign input element has the custom sign as its value.
  $this
    ->assertFieldByXPath("//input[@name='sign[sign_custom]' and @value='foobar']");

  // Test a custom currency.
  $values = array(
    'sign[sign]' => '',
  );
  $this
    ->drupalPost($path . '/ZZZ', $values, t('Submit'));
  $this
    ->assertUrl('user');
  $this
    ->assertRaw("\$form_state['sign'] = ''");
}