You are here

function DateRepeatFormTest::createDateField in Date 8

1 call to DateRepeatFormTest::createDateField()
DateRepeatFormTest::testDateRepeatForm in date_repeat/lib/Drupal/date_repeat/Tests/DateRepeatFormTest.php

File

date_repeat/lib/Drupal/date_repeat/Tests/DateRepeatFormTest.php, line 462
Test Date Repeat form.

Class

DateRepeatFormTest

Namespace

Drupal\date_repeat\Tests

Code

function createDateField($type, $widget, $display_all_day = FALSE) {
  $edit = array();
  $edit['fields[_add_new_field][label]'] = 'Test';
  $edit['fields[_add_new_field][field_name]'] = 'test';
  $edit['fields[_add_new_field][weight]'] = '-4';
  $edit['fields[_add_new_field][type]'] = $type;
  $edit['fields[_add_new_field][widget_type]'] = $widget;
  $label = $edit['fields[_add_new_field][label]'];
  $field_edit = array();
  $field_edit['field[settings][repeat]'] = 1;
  $instance_edit = array();
  switch ($widget) {
    case 'select':
    case 'popup':
      $instance_edit['instance[widget][settings][year_range][years_back]'] = '-5';
      $instance_edit['instance[widget][settings][year_range][years_forward]'] = '+5';
      break;
  }
  if ($display_all_day) {
    $instance_edit['instance[widget][settings][display_all_day]'] = TRUE;
  }

  // First step : 'Add new field' on the 'Manage fields' page.
  $this
    ->drupalPost('admin/structure/types/manage/date/fields', $edit, t('Save'));
  $this
    ->assertRaw(t('These settings apply to the %label field everywhere it is used.', array(
    '%label' => $label,
  )), t('Field settings page was displayed.'));

  // Second step : 'Field settings' form.
  $this
    ->drupalPost(NULL, $field_edit, t('Save field settings'));
  $this
    ->assertRaw(t('Updated field %label field settings.', array(
    '%label' => $label,
  )), t('Redirected to instance and widget settings page.'));

  // Third step : 'Instance settings' form.
  $this
    ->drupalPost(NULL, $instance_edit, t('Save settings'));
  $this
    ->assertRaw(t('Saved %label configuration.', array(
    '%label' => $label,
  )), t('Redirected to "Manage fields" page.'));

  // Check that the field appears in the overview form.
  $this
    ->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
}