function TimestampFormatterWithTimeDiffTest::getFormatDiffTestCases

Same name in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffTest.php \Drupal\FunctionalJavascriptTests\Core\Field\TimestampFormatterWithTimeDiffTest::getFormatDiffTestCases()

Provides test cases for unit testing Drupal.timeDiff.format().

Return value

array[] A list of test cases, each representing parameters to be passed to the JavaScript function.

1 call to TimestampFormatterWithTimeDiffTest::getFormatDiffTestCases()
TimestampFormatterWithTimeDiffTest::testTimestampFormatterWithTimeDiff in core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffTest.php
Tests the 'timestamp' formatter when is used with time difference setting.

File

core/tests/Drupal/FunctionalJavascriptTests/Core/Field/TimestampFormatterWithTimeDiffTest.php, line 167

Class

TimestampFormatterWithTimeDiffTest
Tests the 'timestamp' formatter when is used with time difference setting.

Namespace

Drupal\FunctionalJavascriptTests\Core\Field

Code

protected function getFormatDiffTestCases() : array {
    return [
        'normal, granularity: 2' => [
            'from' => '2010-02-11T10:00:00+00:00',
            'to' => '2010-02-16T14:00:00+00:00',
            'options' => [
                'granularity' => 2,
                'strict' => TRUE,
            ],
            'expected_value' => [
                'day' => 5,
                'hour' => 4,
            ],
            'expected_formatted_value' => '5 days 4 hours',
        ],
        'inverted, strict' => [
            'from' => '2010-02-16T14:00:00+00:00',
            'to' => '2010-02-11T10:00:00+00:00',
            'options' => [
                'granularity' => 2,
                'strict' => TRUE,
            ],
            'expected_value' => [
                'second' => 0,
            ],
            'expected_formatted_value' => '0 seconds',
        ],
        'inverted, strict (strict passed explicitly)' => [
            'from' => '2010-02-16T14:00:00+00:00',
            'to' => '2010-02-11T10:00:00+00:00',
            'options' => [
                'granularity' => 2,
                'strict' => TRUE,
            ],
            'expected_value' => [
                'second' => 0,
            ],
            'expected_formatted_value' => '0 seconds',
        ],
        'inverted, non-strict' => [
            'from' => '2010-02-16T14:00:00+00:00',
            'to' => '2010-02-11T10:00:00+00:00',
            'options' => [
                'granularity' => 2,
            ],
            'expected_value' => [
                'day' => 5,
                'hour' => 4,
            ],
            'expected_formatted_value' => '5 days 4 hours',
        ],
        'normal, max granularity' => [
            'from' => '2010-02-02T10:30:45+00:00',
            'to' => '2011-06-24T11:37:02+00:00',
            'options' => [
                'granularity' => 7,
                'strict' => TRUE,
            ],
            'expected_value' => [
                'year' => 1,
                'month' => 4,
                'week' => 3,
                'day' => 1,
                'hour' => 1,
                'minute' => 6,
                'second' => 17,
            ],
            'expected_formatted_value' => '1 year 4 months 3 weeks 1 day 1 hour 6 minutes 17 seconds',
        ],
        "'1 hour 0 minutes 1 second' is '1 hour'" => [
            'from' => '2010-02-02T10:30:45+00:00',
            'to' => '2010-02-02T11:30:46+00:00',
            'options' => [
                'granularity' => 3,
                'strict' => TRUE,
            ],
            'expected_value' => [
                'hour' => 1,
            ],
            'expected_formatted_value' => '1 hour',
        ],
        "'1 hour 0 minutes' is '1 hour'" => [
            'from' => '2010-02-02T10:30:45+00:00',
            'to' => '2010-02-02T11:30:45+00:00',
            'options' => [
                'granularity' => 2,
                'strict' => TRUE,
            ],
            'expected_value' => [
                'hour' => 1,
            ],
            'expected_formatted_value' => '1 hour',
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.