You are here

public function FacetsDateHandlerTest::testGetTimestampGap in Facets 8

Tests for ::getTimestampGap.

File

tests/src/Unit/Utility/FacetsDateHandlerTest.php, line 116

Class

FacetsDateHandlerTest
Unit test for Date Handler Service.

Namespace

Drupal\Tests\facets\Unit\Utility

Code

public function testGetTimestampGap() {
  $fd = $this->handler;

  // The best search gap between two dates must be a year.
  $date_gap = $this->handler
    ->getTimestampGap(static::TIMESTAMP, static::TIMESTAMP + 31536000);
  $this
    ->assertEquals($fd::FACETS_DATE_YEAR, $date_gap);

  // The best search gap between two dates must be a month.
  $date_gap = $this->handler
    ->getTimestampGap(static::TIMESTAMP, static::TIMESTAMP + 86400 * 60);
  $this
    ->assertEquals($fd::FACETS_DATE_MONTH, $date_gap);

  // The best search gap between two dates must be a day.
  $date_gap = $this->handler
    ->getTimestampGap(static::TIMESTAMP, static::TIMESTAMP + 86400);
  $this
    ->assertEquals($fd::FACETS_DATE_DAY, $date_gap);

  // The best search gap between two dates must be an hour.
  $date_gap = $this->handler
    ->getTimestampGap(static::TIMESTAMP, static::TIMESTAMP + 3600);
  $this
    ->assertEquals($fd::FACETS_DATE_HOUR, $date_gap);

  // The best search gap between two dates must be a minute.
  $date_gap = $this->handler
    ->getTimestampGap(static::TIMESTAMP, static::TIMESTAMP + 60);
  $this
    ->assertEquals($fd::FACETS_DATE_MINUTE, $date_gap);

  // The best search gap between two dates must be a second.
  $date_gap = $this->handler
    ->getTimestampGap(static::TIMESTAMP, static::TIMESTAMP + 59);
  $this
    ->assertEquals($fd::FACETS_DATE_SECOND, $date_gap);

  // When passing in a minimum gap it should be respected.
  $date_gap = $this->handler
    ->getTimestampGap(static::TIMESTAMP, static::TIMESTAMP + 3600, $fd::FACETS_DATE_DAY);
  $this
    ->assertEquals($fd::FACETS_DATE_DAY, $date_gap);
}