Beispiel #1
0
 /**
  * Tests the formatDiff method.
  *
  * @dataProvider providerTestFormatDiff
  *
  * @covers ::formatDiff
  */
 public function testformatDiff($expected, $timestamp1, $timestamp2, $options = array())
 {
     // Mocks a simple formatPlural implementation.
     $this->stringTranslation->expects($this->any())->method('formatPlural')->with($this->anything(), $this->anything(), $this->anything(), array(), array('langcode' => isset($options['langcode']) ? $options['langcode'] : NULL))->will($this->returnCallback(function ($count, $one, $multiple) {
         return $count == 1 ? $one : str_replace('@count', $count, $multiple);
     }));
     // Mocks a simple translate implementation.
     $this->stringTranslation->expects($this->any())->method('translate')->with($this->anything())->will($this->returnCallback(function ($string, $args, $options) {
         return $string;
     }));
     $this->assertEquals($expected, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
 }
Beispiel #2
0
 /**
  * Tests the formatDiff method.
  *
  * @dataProvider providerTestFormatDiff
  *
  * @covers ::formatDiff
  */
 public function testformatDiff($expected, $max_age, $timestamp1, $timestamp2, $options = array())
 {
     // Mocks a simple translateString implementation.
     $this->stringTranslation->expects($this->any())->method('translateString')->willReturnCallback(function (TranslatableMarkup $arg) {
         return $arg->getUntranslatedString();
     });
     if (isset($options['langcode'])) {
         $expected_markup = new TranslatableMarkup($expected, [], ['langcode' => $options['langcode']], $this->stringTranslation);
     } else {
         $expected_markup = new TranslatableMarkup($expected, [], [], $this->stringTranslation);
     }
     $this->assertEquals($expected_markup, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
     $options['return_as_object'] = TRUE;
     $expected_object = new FormattedDateDiff($expected, $max_age);
     $this->assertEquals($expected_object, $this->dateFormatter->formatDiff($timestamp1, $timestamp2, $options));
 }