Unverified Commit 7237ed32 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3069050 by voleger, mikelutz: Properly deprecate FormattedDateDiff::getMaxAge()

parent 105e5b5e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -63,10 +63,13 @@ public function getCacheMaxAge() {
   * @return int
   *   The maximum time in seconds that this object may be cached.
   *
   * @deprecated in Drupal 8.1.9 and will be removed before Drupal 9.0.0. Use
   * @deprecated in drupal:8.1.9 and is removed from drupal:9.0.0. Use
   *   \Drupal\Core\Datetime\FormattedDateDiff::getCacheMaxAge() instead.
   *
   * @see https://www.drupal.org/node/2783545
   */
  public function getMaxAge() {
    @trigger_error(__NAMESPACE__ . '\FormattedDateDiff::getMaxAge() is deprecated in drupal:8.1.9 and is removed from drupal:9.0.0. Use \Drupal\Core\Datetime\FormattedDateDiff::getCacheMaxAge() instead. See https://www.drupal.org/node/2783545', E_USER_DEPRECATED);
    return $this->getCacheMaxAge();
  }

+13 −1
Original line number Diff line number Diff line
@@ -421,7 +421,19 @@ public function testFormattedDateDiff() {
    $build = [];
    CacheableMetadata::createFromObject($object)->applyTo($build);
    $this->assertEquals($max_age, $build['#cache']['max-age']);
    // Test the BC layer.
  }

  /**
   * Tests FormattedDateDiff.
   *
   * @covers \Drupal\Core\Datetime\FormattedDateDiff::getMaxAge
   * @group legacy
   * @expectedDeprecation Drupal\Core\Datetime\FormattedDateDiff::getMaxAge() is deprecated in drupal:8.1.9 and is removed from drupal:9.0.0. Use \Drupal\Core\Datetime\FormattedDateDiff::getCacheMaxAge() instead. See https://www.drupal.org/node/2783545
   */
  public function testLegacyMaxAgeFormattedDateDiff() {
    $string = '10 minutes';
    $max_age = 60;
    $object = new FormattedDateDiff($string, $max_age);
    $this->assertSame($object->getCacheMaxAge(), $object->getMaxAge());
  }