You are here

public function DurationFieldFunctionalTest::testHumanReadableFormatter 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::testHumanReadableFormatter()

Tests the Human Friendly duration field formatter outputs correct data.

File

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

Class

DurationFieldFunctionalTest
Functional tests for the Duration Field module.

Namespace

Drupal\Tests\duration_field\Functional

Code

public function testHumanReadableFormatter() {
  $this
    ->createDefaultSetup();
  $this
    ->fillTextValue('#edit-title-0-value', 'Dummy Title');
  $this
    ->fillTextValue('#edit-field-duration-0-duration-y', 1);
  $this
    ->fillTextValue('#edit-field-duration-0-duration-m', 2);
  $this
    ->fillTextValue('#edit-field-duration-0-duration-d', 3);
  $this
    ->fillTextValue('#edit-field-duration-0-duration-h', 4);
  $this
    ->fillTextValue('#edit-field-duration-0-duration-i', 5);
  $this
    ->fillTextValue('#edit-field-duration-0-duration-s', 6);
  $this
    ->click('input[name="op"]');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->assertTextExists('1 year 2 months 3 days 4 hours 5 minutes 6 seconds');
  $this
    ->setHumanReadableOptions('short');
  $this
    ->drupalGet('/node/1');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->assertTextExists('1 yr 2 mo 3 days 4 hr 5 min 6 s');
  $this
    ->setHumanReadableOptions('full', 'hyphen');
  $this
    ->drupalGet('/node/1');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->assertTextExists('1 year - 2 months - 3 days - 4 hours - 5 minutes - 6 seconds');
  $this
    ->setHumanReadableOptions('full', 'comma');
  $this
    ->drupalGet('/node/1');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->assertTextExists('1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds');
  $this
    ->setHumanReadableOptions('full', 'newline');
  $this
    ->drupalGet('/node/1');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->assertTextExists('1 year2 months3 days4 hours5 minutes6 seconds');
}