You are here

protected function DurationFieldFunctionalTest::createDefaultSetup in Duration Field 8.2

Same name and namespace in other branches
  1. 3.0.x tests/src/Functional/DurationFieldFunctionalTest.php \Drupal\Tests\duration_field\Functional\DurationFieldFunctionalTest::createDefaultSetup()

Sets up a date.

7 calls to DurationFieldFunctionalTest::createDefaultSetup()
DurationFieldFunctionalTest::testHumanReadableDate in tests/src/Functional/DurationFieldFunctionalTest.php
Tests human readable date field formatter.
DurationFieldFunctionalTest::testHumanReadableFormatter in tests/src/Functional/DurationFieldFunctionalTest.php
Tests the Human Friendly duration field formatter outputs correct data.
DurationFieldFunctionalTest::testRawValue in tests/src/Functional/DurationFieldFunctionalTest.php
Tests the raw value field formatter.
DurationFieldFunctionalTest::testTimeDate in tests/src/Functional/DurationFieldFunctionalTest.php
Tests the date part of the time formatter.
DurationFieldFunctionalTest::testTimeFormatter in tests/src/Functional/DurationFieldFunctionalTest.php
Tests the Time Format duration field formatter outputs correct data.

... See full list

File

tests/src/Functional/DurationFieldFunctionalTest.php, line 223

Class

DurationFieldFunctionalTest
Functional tests for the Duration Field module.

Namespace

Drupal\Tests\duration_field\Functional

Code

protected function createDefaultSetup($granularity = [
  'y',
  'm',
  'd',
  'h',
  'i',
  's',
]) {
  $this->adminUser = $this
    ->createUser([], 'Admin User', TRUE);
  $admin_role = $this
    ->createAdminRole();
  $this->adminUser
    ->addRole($admin_role);
  $this
    ->drupalLogin($this->adminUser);
  $this->contentType = $this
    ->createContentType([
    'type' => 'test_type',
    'name' => 'Test Type',
  ]);
  $this
    ->drupalGet('admin/structure/types/manage/test_type/fields/add-field');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->selectSelectOption('#edit-new-storage-type', 'duration');
  $this
    ->fillTextValue('#edit-label', 'Duration');
  $this
    ->fillTextValue('#edit-field-name', 'duration');
  $this
    ->click('#edit-submit');
  $this
    ->assertSession()
    ->addressMatches('/^\\/admin\\/structure\\/types\\/manage\\/test_type\\/fields\\/node.test_type.field_duration\\/storage$/');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->click('#edit-submit');
  $this
    ->assertSession()
    ->addressMatches('/^\\/admin\\/structure\\/types\\/manage\\/test_type\\/fields\\/node.test_type.field_duration$/');
  $this
    ->assertStatusCodeEquals(200);
  $check = array_diff([
    'y',
    'm',
    'd',
    'h',
    'i',
    's',
  ], $granularity);
  foreach ($check as $field) {
    $this
      ->checkCheckbox('#edit-settings-granularity-' . $field);
  }
  foreach ($granularity as $field) {
    $this
      ->assertCheckboxChecked('#edit-settings-granularity-' . $field);
  }
  $this
    ->click('#edit-submit');
  $this
    ->assertSession()
    ->addressMatches('/^\\/admin\\/structure\\/types\\/manage\\/test_type\\/fields$/');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->assertElementExistsXpath('//table[@id="field-overview"]//td[text()="Duration"]');
  $this
    ->drupalGet('node/add/test_type');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->assertSession()
    ->addressMatches('/^\\/node\\/add\\/test_type$/');
  foreach ($granularity as $field) {
    $this
      ->assertElementExists('input#edit-field-duration-0-duration-' . $field . '[type="number"]');
  }
}