You are here

protected function DateTimeFieldTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/datetime/src/Tests/DateTimeFieldTest.php \Drupal\datetime\Tests\DateTimeFieldTest::setUp()

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

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

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.

Overrides WebTestBase::setUp

File

core/modules/datetime/src/Tests/DateTimeFieldTest.php, line 59
Contains \Drupal\datetime\Tests\DateTimeFieldTest.

Class

DateTimeFieldTest
Tests Datetime field functionality.

Namespace

Drupal\datetime\Tests

Code

protected function setUp() {
  parent::setUp();

  // Set an explicit site timezone, and disallow per-user timezones.
  $this
    ->config('system.date')
    ->set('timezone.user.configurable', 0)
    ->set('timezone.default', 'Asia/Tokyo')
    ->save();
  $web_user = $this
    ->drupalCreateUser(array(
    'access content',
    'view test entity',
    'administer entity_test content',
    'administer entity_test form display',
    'administer content types',
    'administer node fields',
  ));
  $this
    ->drupalLogin($web_user);

  // Create a field with settings to validate.
  $field_name = Unicode::strtolower($this
    ->randomMachineName());
  $this->fieldStorage = entity_create('field_storage_config', array(
    'field_name' => $field_name,
    'entity_type' => 'entity_test',
    'type' => 'datetime',
    'settings' => array(
      'datetime_type' => 'date',
    ),
  ));
  $this->fieldStorage
    ->save();
  $this->field = entity_create('field_config', array(
    'field_storage' => $this->fieldStorage,
    'bundle' => 'entity_test',
    'required' => TRUE,
  ));
  $this->field
    ->save();
  entity_get_form_display($this->field
    ->getTargetEntityTypeId(), $this->field
    ->getTargetBundle(), 'default')
    ->setComponent($field_name, array(
    'type' => 'datetime_default',
  ))
    ->save();
  $this->defaultSettings = array(
    'timezone_override' => '',
  );
  $this->displayOptions = array(
    'type' => 'datetime_default',
    'label' => 'hidden',
    'settings' => array(
      'format_type' => 'medium',
    ) + $this->defaultSettings,
  );
  entity_get_display($this->field
    ->getTargetEntityTypeId(), $this->field
    ->getTargetBundle(), 'full')
    ->setComponent($field_name, $this->displayOptions)
    ->save();
}