You are here

public function DurationServiceTest::getHumanReadableStringFromDateIntervalDataProvider in Duration Field 8.2

Same name and namespace in other branches
  1. 3.0.x tests/src/Unit/Service/DurationServiceTest.php \Drupal\Tests\duration_field\Unit\Service\DurationServiceTest::getHumanReadableStringFromDateIntervalDataProvider()

Data provider for testgetHumanReadableStringFromDateInterval().

File

tests/src/Unit/Service/DurationServiceTest.php, line 193

Class

DurationServiceTest
@coversDefaultClass \Drupal\duration_field\Service\DurationService @group duration_field

Namespace

Drupal\Tests\duration_field\Unit\Service

Code

public function getHumanReadableStringFromDateIntervalDataProvider() {
  return [
    [
      [
        'value' => new DateInterval('P0M'),
        'granularity' => [
          'y' => TRUE,
          'm' => TRUE,
          'd' => TRUE,
          'h' => TRUE,
          'i' => TRUE,
          's' => TRUE,
        ],
      ],
      'Empty',
      'An empty DateInterval correctly outputted a response of "Empty"',
    ],
    [
      [
        'value' => new DateInterval('P1Y'),
        'granularity' => [
          'y' => TRUE,
          'm' => TRUE,
          'd' => TRUE,
          'h' => TRUE,
          'i' => TRUE,
          's' => TRUE,
        ],
      ],
      '1 year',
      'A date interval of P1Y correctly turned into text "1 year"',
    ],
    [
      [
        'value' => new DateInterval('P1Y1M'),
        'granularity' => [
          'y' => FALSE,
          'm' => TRUE,
          'd' => TRUE,
          'h' => TRUE,
          'i' => TRUE,
          's' => TRUE,
        ],
      ],
      '1 month',
      'A date interval of P1Y1M correctly turned into text "1 month", excluding the year as it is not part of the granularity',
    ],
    [
      [
        'value' => new DateInterval('P1Y2M3DT4H5M6S'),
        'granularity' => [
          'y' => TRUE,
          'm' => TRUE,
          'd' => TRUE,
          'h' => TRUE,
          'i' => TRUE,
          's' => TRUE,
        ],
      ],
      '1 year 2 months 3 days 4 hours 5 minutes 6 seconds',
      'A date interval of P1Y2M3DT4H5M6S correctly turned into text "1 year 2 months 3 days 4 hours 5 minutes 6 seconds"',
    ],
  ];
}