You are here

protected function DurationFieldAccessTest::createDefaultSetup in Duration Field 8

Sets up a date.

7 calls to DurationFieldAccessTest::createDefaultSetup()
DurationFieldAccessTest::testHumanReadableAll in tests/src/Functional/DurationFieldFunctionalTest.php
Tests human readable values.
DurationFieldAccessTest::testHumanReadableDate in tests/src/Functional/DurationFieldFunctionalTest.php
Tests human readable dates.
DurationFieldAccessTest::testHumanReadableTime in tests/src/Functional/DurationFieldFunctionalTest.php
Test human readable times.
DurationFieldAccessTest::testRawValue in tests/src/Functional/DurationFieldFunctionalTest.php
Tests raw values.
DurationFieldAccessTest::testTimeDate in tests/src/Functional/DurationFieldFunctionalTest.php
Tests the date part of a time.

... See full list

File

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

Class

DurationFieldAccessTest
Functional tests for the Duration Field module.

Namespace

Drupal\Tests\duration_field\Functional

Code

protected function createDefaultSetup($granularity = [
  'year',
  'month',
  'day',
  'hour',
  'minute',
  'second',
]) {
  $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([
    'year',
    'month',
    'day',
    'hour',
    'minute',
    'second',
  ], $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-value-' . $field . '[type="number"]');
  }
}