You are here

public function DateRecurViewsOccurrenceFilterTest::testDateRecurFilterAbsoluteYear in Recurring Dates Field 3.1.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/DateRecurViewsOccurrenceFilterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurViewsOccurrenceFilterTest::testDateRecurFilterAbsoluteYear()
  2. 3.x tests/src/Kernel/DateRecurViewsOccurrenceFilterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurViewsOccurrenceFilterTest::testDateRecurFilterAbsoluteYear()
  3. 3.0.x tests/src/Kernel/DateRecurViewsOccurrenceFilterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurViewsOccurrenceFilterTest::testDateRecurFilterAbsoluteYear()

Tests date recur filter plugin.

File

tests/src/Kernel/DateRecurViewsOccurrenceFilterTest.php, line 77

Class

DateRecurViewsOccurrenceFilterTest
Tests the results of 'date_recur_occurrences_filter' filter plugin.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testDateRecurFilterAbsoluteYear() {

  // Testing around 2008.
  $entity1 = $this
    ->createEntity();
  $entity1->{$this->fieldName} = [
    [
      // Before 2008.
      'value' => '2007-12-12T23:00:00',
      'end_value' => '2007-12-13T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity1
    ->save();
  $entity2 = $this
    ->createEntity();
  $entity2->{$this->fieldName} = [
    [
      // Intersecting start of 2008.
      'value' => '2007-12-12T23:00:00',
      'end_value' => '2008-01-13T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity2
    ->save();
  $entity3 = $this
    ->createEntity();
  $entity3->{$this->fieldName} = [
    [
      // Within 2008.
      'value' => '2008-02-12T23:00:00',
      'end_value' => '2008-02-13T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity3
    ->save();
  $entity4 = $this
    ->createEntity();
  $entity4->{$this->fieldName} = [
    [
      // Intersecting end of 2008.
      'value' => '2008-12-30T23:00:00',
      'end_value' => '2009-01-02T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity4
    ->save();
  $entity5 = $this
    ->createEntity();
  $entity5->{$this->fieldName} = [
    [
      // After 2008.
      'value' => '2009-01-02T23:00:00',
      'end_value' => '2009-01-03T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity5
    ->save();
  $entity6 = $this
    ->createEntity();
  $entity6->{$this->fieldName} = [
    [
      // Covering entirety of 2008.
      'value' => '2007-12-02T23:00:00',
      'end_value' => '2009-01-03T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity6
    ->save();
  $exposedIdentifier = $this->fieldName . '_occurrences';
  $filterOptions = [
    'operator' => '=',
    'value' => '',
    'value_granularity' => 'year',
    'exposed' => TRUE,
    'expose' => [
      'identifier' => $exposedIdentifier,
      'operator' => $this->fieldName . '_occurrences_op',
      'use_operator' => FALSE,
      'required' => FALSE,
    ],
  ];

  // Input values are in the users timezone.
  $this
    ->assertFilter([
    $exposedIdentifier => '2006',
  ], [], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2007',
  ], [
    [
      'id' => $entity1
        ->id(),
    ],
    [
      'id' => $entity2
        ->id(),
    ],
    [
      'id' => $entity6
        ->id(),
    ],
  ], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2008',
  ], [
    [
      'id' => $entity2
        ->id(),
    ],
    [
      'id' => $entity3
        ->id(),
    ],
    [
      'id' => $entity4
        ->id(),
    ],
    [
      'id' => $entity6
        ->id(),
    ],
  ], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2009',
  ], [
    [
      'id' => $entity4
        ->id(),
    ],
    [
      'id' => $entity5
        ->id(),
    ],
    [
      'id' => $entity6
        ->id(),
    ],
  ], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2010',
  ], [], $filterOptions);
}