You are here

private function UCXFTestCase::createFieldHelper in Extra Fields Checkout Pane 7

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

Create a new field

Parameters

int $type:

array $edit:

Return value

string The name of the field

1 call to UCXFTestCase::createFieldHelper()
UCXFTestCase::createAddressField in ./uc_extra_fields_pane.test
Create a new address field

File

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

Class

UCXFTestCase
Base class for all Extra Fields Pane test cases.

Code

private function createFieldHelper($type, $edit) {
  global $db_prefix;
  $edit += array(
    'ucxf[label]' => $this
      ->randomName(10),
    'ucxf[db_name]' => drupal_strtolower($this
      ->randomName(32 - 5 - drupal_strlen($db_prefix) - 1)),
    'ucxf[description]' => $this
      ->randomString(10),
    'ucxf[value_type]' => $type,
    'ucxf[required]' => TRUE,
  );
  switch ($type) {
    case UCXF_Field::UCXF_WIDGET_TYPE_SELECT:
      $edit += array(
        'ucxf[value]' => " |Please select\noption1|Option 1\noption2|Option 2",
      );
      break;
    case UCXF_Field::UCXF_WIDGET_TYPE_CONSTANT:
      $edit += array(
        'ucxf[value]' => 'A constant, ' . $this
          ->randomString(10),
      );
      break;
    case UCXF_Field::UCXF_WIDGET_TYPE_PHP:
      $edit += array(
        'ucxf[value]' => '<?php return "A string"; ?>',
      );
      break;
    case UCXF_Field::UCXF_WIDGET_TYPE_PHP_SELECT:
      $edit += array(
        'ucxf[value]' => '<?php return array("" => "Please select", "option1" => "PHP Option 1", "option2" => "PHP Option 2"); ?>',
      );
      break;
    default:
      $edit += array(
        'ucxf[value]' => '',
      );
      break;
  }

  // Post the form at the current path.
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertText(t('Field saved'), t('The field is saved.'));

  // Return machine name of field.
  return 'ucxf_' . $edit['ucxf[db_name]'];
}