You are here

public function UCXFCheckoutTestCase::testSanitizing in Extra Fields Checkout Pane 7

Same name and namespace in other branches
  1. 6.2 uc_extra_fields_pane.test \UCXFCheckoutTestCase::testSanitizing()

Test if field values are properly sanitized.

File

./uc_extra_fields_pane.test, line 792
Automated tests for Extra Fields Pane

Class

UCXFCheckoutTestCase
Checkout testcase

Code

public function testSanitizing() {

  // Login as admin.
  $this
    ->drupalLogin($this->adminUser);

  // Create address fields.
  $textfield_edit = array(
    'ucxf[label]' => '<em>textField</em>',
    'ucxf[db_name]' => 'ucxf_textfield',
    'ucxf[description]' => '<script>/*textField*/</script>',
    'ucxf[value]' => "<em>default</em>\n",
  );
  $selectfield_edit = array(
    'ucxf[label]' => '<em>selectField</em>',
    'ucxf[db_name]' => 'ucxf_selectfield',
    'ucxf[description]' => '<script>/*selectField*/</script>',
    'ucxf[value]' => "<script>/*selectFieldOptionKey*/</script>|<em>selectFieldOptionLabel</em>\n",
  );
  $constantfield_edit = array(
    'ucxf[label]' => '<em>constantField</em>',
    'ucxf[db_name]' => 'ucxf_constantfield',
    'ucxf[description]' => '<script>/*constantField*/</script>',
    'ucxf[value]' => '<em>constantFieldValue</em>',
  );
  $checkbox_edit = array(
    'ucxf[label]' => '<em>checkboxField</em>',
    'ucxf[db_name]' => 'ucxf_checkboxfield',
    'ucxf[description]' => '<script>/*checkboxField*/</script>',
  );
  $this->textField = $this
    ->createAddressField(UCXF_Field::UCXF_WIDGET_TYPE_TEXTFIELD, $textfield_edit);
  $this->selectField = $this
    ->createAddressField(UCXF_Field::UCXF_WIDGET_TYPE_SELECT, $selectfield_edit);
  $this->constantField = $this
    ->createAddressField(UCXF_Field::UCXF_WIDGET_TYPE_CONSTANT, $constantfield_edit);
  $this->checkboxField = $this
    ->createAddressField(UCXF_Field::UCXF_WIDGET_TYPE_CHECKBOX, $checkbox_edit);

  // Go to checkout as anonymous user.
  $this
    ->drupalLogout();
  $this
    ->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
  $all_fields = UCXF_FieldList::getAllFields();
  $address_fields = UCXF_FieldList::getAllAddressFields();
  $this
    ->drupalPost('cart', array(), 'Checkout');

  // Ensure all output is properly sanitized.
  // Field labels.
  $this
    ->assertNoRaw('<em>textField</em>');
  $this
    ->assertNoRaw('<em>selectField</em>');
  $this
    ->assertNoRaw('<em>constantField</em>');
  $this
    ->assertNoRaw('<em>checkboxField</em>');

  // Field descriptions.
  $this
    ->assertNoRaw('<script>/*textField*/</script>');
  $this
    ->assertNoRaw('<script>/*selectField*/</script>');
  $this
    ->assertNoRaw('<script>/*constantField*/</script>');
  $this
    ->assertNoRaw('<script>/*checkboxField*/</script>');

  // Constant value.
  $this
    ->assertNoRaw('<em>constantFieldValue</em>');

  // Generate value for the text and select field.
  $values = array(
    'ucxf_textfield' => '<em>default</em>',
    'ucxf_selectfield' => '<script>/*selectFieldOptionKey*/</script>',
  );

  // Fill in checkout form.
  $delivery_values = $this
    ->getEditValues($address_fields, array(
    'panes',
    'delivery',
    'address',
  ), $values, 'delivery_');
  $billing_values = $this
    ->getEditValues($address_fields, array(
    'panes',
    'billing',
    'address',
  ), $values, 'billing_');
  $edit = array_merge($delivery_values['form_values'], $billing_values['form_values']);
  $edit = $this
    ->populateCheckoutForm($edit);
  $this
    ->drupalPost('cart/checkout', $edit, t('Review order'));

  // Ensure all output is properly sanitized.
  // Field labels.
  $this
    ->assertNoRaw('<em>textField</em>');
  $this
    ->assertNoRaw('<em>selectField</em>');
  $this
    ->assertNoRaw('<em>constantField</em>');
  $this
    ->assertNoRaw('<em>checkboxField</em>');

  // Values.
  $this
    ->assertNoRaw('<em>default</em>');
  $this
    ->assertNoRaw('<em>selectFieldOptionLabel</em>');
  $this
    ->assertNoRaw('<em>constantFieldValue</em>');
}