You are here

public function CCKSelectOtherNumericFieldTest::setUp in CCK Select Other 7.2

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/cck_select_other.test, line 609
CCK Select Other Functional Tests

Class

CCKSelectOtherNumericFieldTest
Assert that select other field widget can be used with non-text fields.

Code

public function setUp() {
  parent::setUp(array(
    'cck_select_other',
  ));
  $this
    ->assertTrue(module_exists('cck_select_other'), t('CCK Select Other module is enabled.'));
  $content_type = strtolower($this
    ->randomName(5));

  /* Setup an admin user */
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'administer content types',
    'administer site configuration',
  ));
  $this
    ->drupalLogin($this->admin_user);

  /* Create a new content type */
  $settings = array(
    'type' => $content_type,
  );
  $this->contentType = $this
    ->drupalCreateContentType($settings);

  /* Create some options for our select other list */
  $this->options = "1\n2\n3\n4\n5\nother|Other";

  /* Create a new field on our content type */
  $field_label = $this
    ->randomName(5);
  $field_name = strtolower($this
    ->randomName(5));
  $bundle_path = 'admin/structure/types/manage/' . $this->contentType->type;
  $edit = array(
    'fields[_add_new_field][label]' => $field_label,
    'fields[_add_new_field][field_name]' => $field_name,
    'fields[_add_new_field][type]' => 'list_integer',
    'fields[_add_new_field][widget_type]' => 'cck_select_other',
  );
  $this
    ->drupalPost($bundle_path . '/fields', $edit, 'Save');
  $edit = array(
    'instance[required]' => TRUE,
    'instance[widget][settings][select_list_options]' => $this->options,
    'field_' . $field_name . '[und][0][select_other_list]' => '_none',
  );
  $this
    ->drupalPost($bundle_path . '/fields/field_' . $field_name, $edit, 'Save settings');
  $this
    ->drupalGet($bundle_path . '/fields/field_' . $field_name);
  $this->test_field = field_info_field('field_' . $field_name);
  $this->test_instance = field_info_instance('node', 'field_' . $field_name, $this->contentType->type);

  /* Setup a web user that can create content */

  // @todo bypass node access seems to be the only thing that does not return 403
  $this->web_user = $this
    ->drupalCreateUser(array(
    'access content',
    'create ' . $this->contentType->type . ' content',
    'delete any ' . $this->contentType->type . ' content',
    'bypass node access',
  ));
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->web_user);
  $settings = array(
    'type' => $this->contentType->type,
  );
  $this->test_node = $this
    ->drupalCreateNode($settings);
  $this
    ->drupalLogout();
  $options_arr = cck_select_other_options($this->test_instance);
  $this
    ->assertEqual(7, count($options_arr), t('There are 6 = %count options set on the field.', array(
    '%count' => count($options_arr),
  )));
}