You are here

public function FacetsDateHandlerTest::testGetDateGap in Facets 8

Tests for ::getDateGap method.

File

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

Class

FacetsDateHandlerTest
Unit test for Date Handler Service.

Namespace

Drupal\Tests\facets\Unit\Utility

Code

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

  // Cannot convert to timestamp.
  $this
    ->assertFalse($fd
    ->getDateGap(static::TIMESTAMP, static::TIMESTAMP));

  // The min. gap is MONTH but the result is larger.
  $this
    ->assertEquals($fd::FACETS_DATE_YEAR, $fd
    ->getDateGap('1983-03-03T20:43:04Z', '1987-11-26T20:43:04Z', $fd::FACETS_DATE_MONTH));

  // The gap is YEAR.
  $this
    ->assertEquals($fd::FACETS_DATE_YEAR, $fd
    ->getDateGap('1983-03-03T20:43:04Z', '1987-11-26T20:43:04Z'));

  // The gap is MONTH.
  $this
    ->assertEquals($fd::FACETS_DATE_MONTH, $fd
    ->getDateGap('1983-03-03T20:43:04Z', '1983-11-26T20:43:04Z'));

  // The gap is DAY.
  $this
    ->assertEquals($fd::FACETS_DATE_DAY, $fd
    ->getDateGap('1983-03-03T20:43:04Z', '1983-03-26T20:43:04Z'));

  // The gap is HOUR.
  $this
    ->assertEquals($fd::FACETS_DATE_HOUR, $fd
    ->getDateGap('1983-03-03T20:43:04Z', '1983-03-03T21:44:04Z'));

  // The gap is MINUTE.
  $this
    ->assertEquals($fd::FACETS_DATE_MINUTE, $fd
    ->getDateGap('1983-03-03T20:43:04Z', '1983-03-03T20:44:04Z'));

  // The gap is SECOND.
  $this
    ->assertEquals($fd::FACETS_DATE_SECOND, $fd
    ->getDateGap('1983-03-03T20:43:04Z', '1983-03-03T20:43:55Z'));
}