function DateTest::testFormatInterval

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testFormatInterval()
  2. 10 core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testFormatInterval()
  3. 11.x core/tests/Drupal/Tests/Core/Datetime/DateTest.php \Drupal\Tests\Core\Datetime\DateTest::testFormatInterval()

Tests the formatInterval method.

@dataProvider providerTestFormatInterval

@covers ::formatInterval

File

core/tests/Drupal/Tests/Core/Datetime/DateTest.php, line 97

Class

DateTest
@coversDefaultClass \Drupal\Core\Datetime\DateFormatter @group Datetime

Namespace

Drupal\Tests\Core\Datetime

Code

public function testFormatInterval($interval, $granularity, $expected, $langcode = NULL) {
    // Mocks a simple formatPlural implementation.
    $this->stringTranslation
        ->expects($this->any())
        ->method('translateString')
        ->willReturnCallback(function (TranslatableMarkup $arg) {
        return $arg->getUntranslatedString();
    });
    // Check if the granularity is specified.
    if ($granularity) {
        $result = $this->dateFormatter
            ->formatInterval($interval, $granularity, $langcode);
    }
    else {
        $result = $this->dateFormatter
            ->formatInterval($interval);
    }
    $this->assertEquals(new TranslatableMarkup($expected, [], [
        'langcode' => $langcode,
    ], $this->stringTranslation), $result);
}

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