You are here

public function DateEmwTestCase::setUp in Date 7.3

Same name and namespace in other branches
  1. 7.2 tests/DateEmwTestCase.test \DateEmwTestCase::setUp()

Set up a user and a content type with a Date (ISO) field.

Overrides DrupalWebTestCase::setUp

File

tests/DateEmwTestCase.test, line 28
Test Date (ISO) and the Entity Metadata Wrappers play well together.

Class

DateEmwTestCase
Test Date (ISO) and the Entity Metadata Wrappers play well together.

Code

public function setUp(array $modules = array()) {

  // Define the dependencies.
  $modules[] = 'date_api';
  $modules[] = 'date';
  $modules[] = 'field';
  $modules[] = 'field_ui';
  $modules[] = 'entity';
  $modules[] = 'entity_token';
  parent::setUp($modules);

  // Select a specific default timezone, and turn off user-configurable
  // timezone handling.
  variable_set('date_default_timezone', 'Pacific/Honolulu');
  variable_set('configurable_timezones', 0);

  // Create a privileged user and log in with it.
  $this->privileged_user = $this
    ->drupalCreateUser(array(
    'administer site configuration',
    'administer content types',
    'administer nodes',
    'bypass node access',
    'administer fields',
  ));
  $this
    ->drupalLogin($this->privileged_user);

  // Create a content type to which we can add our date fields.
  $edit = array();
  $edit['name'] = 'Story';
  $edit['type'] = 'story';
  $this
    ->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
  $this
    ->assertText('The content type Story has been added.', 'Content type added.');

  // Add each of our date field types.
  $this->date_types = array(
    'date' => 'Date (ISO format)',
    'datetime' => 'Date',
    'datestamp' => 'Date (Unix timestamp)',
  );
  foreach ($this->date_types as $type => $label) {
    $field_name_for_human = 'test_' . $type;

    // Add the field.
    $field = array();
    $field['fields[_add_new_field][label]'] = $label;
    $field['fields[_add_new_field][field_name]'] = $field_name_for_human;
    $field['fields[_add_new_field][type]'] = $type;
    $field['fields[_add_new_field][widget_type]'] = 'date_text';
    $this
      ->drupalPost('admin/structure/types/manage/story/fields', $field, 'Save');
    $this
      ->assertText('These settings apply to the ' . $field['fields[_add_new_field][label]'] . ' field everywhere it is used.', $label . ' field added to content type.');

    // Set the timezone handling to 'none'.
    $field = array();
    $field['field[settings][tz_handling]'] = 'none';
    $this
      ->drupalPost('admin/structure/types/manage/story/fields/field_' . $field_name_for_human, $field, 'Save settings');
    $this
      ->assertText('Saved ' . $label . ' configuration.');
  }
}