You are here

function PaymentTestPaymentLineItemFormElementWebTestCase::testValidation in Payment 7

Test validation.

File

tests/payment_test/tests/PaymentTestPaymentLineItemFormElementWebTestCase.test, line 104
Contains class PaymentTestPaymentLineItemFormElementWebTestCase.

Class

PaymentTestPaymentLineItemFormElementWebTestCase
Tests the payment_line_item form element.

Code

function testValidation() {

  // Test valid values.
  $this
    ->drupalPost('payment_test-form-element-payment-line-item', $this->PaymentLineItemData, t('Submit'));
  $this
    ->assertUrl('user', array(), 'Valid values trigger form submission.');

  // Test leaving some elements empty.
  $values = array(
    'line_item[container_0][description]' => '',
  ) + $this->PaymentLineItemData;
  $this
    ->drupalPost('payment_test-form-element-payment-line-item', $values, t('Submit'));
  $this
    ->assertRaw(t('%title is required, or leave all fields for this line item empty.', array(
    '%title' => t('Description'),
  )), "Partially filling in a line item's element throws a validation error.");

  // Test a non-integer quantity.
  $values = array(
    'line_item[container_0][quantity]' => $this
      ->randomName(2),
  );
  $this
    ->drupalPost('payment_test-form-element-payment-line-item', $values, t('Submit'));
  $this
    ->assertText(t('Quantity should be a number.'), 'A non-number quantity throws a validation error.');

  // Test a non-numeric tax rate.
  $values = array(
    'line_item[container_0][tax_rate]' => $this
      ->randomName(2),
  );
  $this
    ->drupalPost('payment_test-form-element-payment-line-item', $values, t('Submit'));
  $this
    ->assertFieldByXPath('//input[@id="edit-line-item-container-0-tax-rate" and contains(@class, "error")]', NULL, 'A non-numeric tax rate throws a validation error.');

  // Test a negative tax rate.
  $values = array(
    'line_item[container_0][tax_rate]' => '-10',
  );
  $this
    ->drupalPost('payment_test-form-element-payment-line-item', $values, t('Submit'));
  $this
    ->assertFieldByXPath('//input[@id="edit-line-item-container-0-tax-rate" and contains(@class, "error")]', NULL, 'A negative tax rate throws a validation error.');

  // Test a float tax rate that uses a period.
  $values = array(
    'line_item[container_0][tax_rate]' => '19.6',
  );
  $this
    ->drupalPost('payment_test-form-element-payment-line-item', $values, t('Submit'));
  $this
    ->assertFieldByXPath('//input[@id="edit-line-item-container-0-tax-rate" and not(contains(@class, "error"))]', NULL, 'A float tax rate that includes a period is valid.');

  // Test a float tax rate that uses a comma.
  $values = array(
    'line_item[container_0][tax_rate]' => '19,6',
  );
  $this
    ->drupalPost('payment_test-form-element-payment-line-item', $values, t('Submit'));
  $this
    ->assertFieldByXPath('//input[@id="edit-line-item-container-0-tax-rate" and not(contains(@class, "error"))]', NULL, 'A float tax rate that includes a comma is valid.');
}