You are here

public function DateTest::testFormatInterval in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 96
Contains \Drupal\Tests\Core\Datetime\DateTest.

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('formatPlural')
    ->with($this
    ->anything(), $this
    ->anything(), $this
    ->anything(), array(), array(
    'langcode' => $langcode,
  ))
    ->will($this
    ->returnCallback(function ($count, $one, $multiple) {
    return $count == 1 ? $one : str_replace('@count', $count, $multiple);
  }));

  // Check if the granularity is specified.
  if ($granularity) {
    $result = $this->dateFormatter
      ->formatInterval($interval, $granularity, $langcode);
  }
  else {
    $result = $this->dateFormatter
      ->formatInterval($interval);
  }
  $this
    ->assertEquals($expected, $result);
}