You are here

public function DateRecurViewsOccurrenceFilterTest::testDateRecurFilterAbsoluteMonth in Recurring Dates Field 8.2

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

Tests date recur filter plugin.

File

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

Class

DateRecurViewsOccurrenceFilterTest
Tests the results of 'date_recur_occurrences_filter' filter plugin.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testDateRecurFilterAbsoluteMonth() {

  // Testing around September 2014.
  $entity1 = $this
    ->createEntity();
  $entity1->{$this->fieldName} = [
    [
      // Before Sept 2014.
      'value' => '2014-08-12T23:00:00',
      'end_value' => '2014-08-13T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity1
    ->save();
  $entity2 = $this
    ->createEntity();
  $entity2->{$this->fieldName} = [
    [
      // Intersecting start of Sept 2014.
      'value' => '2014-08-29T23:00:00',
      'end_value' => '2014-09-02T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity2
    ->save();
  $entity3 = $this
    ->createEntity();
  $entity3->{$this->fieldName} = [
    [
      // Within Sept 2014.
      'value' => '2014-09-12T23:00:00',
      'end_value' => '2014-09-13T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity3
    ->save();
  $entity4 = $this
    ->createEntity();
  $entity4->{$this->fieldName} = [
    [
      // Intersecting end of Sept 2014.
      'value' => '2014-09-29T23:00:00',
      'end_value' => '2014-10-02T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity4
    ->save();
  $entity5 = $this
    ->createEntity();
  $entity5->{$this->fieldName} = [
    [
      // After Sept 2014.
      'value' => '2014-10-12T23:00:00',
      'end_value' => '2014-10-13T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity5
    ->save();
  $entity6 = $this
    ->createEntity();
  $entity6->{$this->fieldName} = [
    [
      // Covering entirety of Sept 2014.
      'value' => '2014-08-12T23:00:00',
      'end_value' => '2014-10-13T07:00:00',
      'rrule' => 'FREQ=DAILY;COUNT=1',
      'infinite' => '0',
      'timezone' => 'Australia/Sydney',
    ],
  ];
  $entity6
    ->save();
  $exposedIdentifier = 'dr_occurrences';
  $filterOptions = [
    'operator' => '=',
    'value' => '',
    'value_granularity' => 'month',
    'exposed' => TRUE,
    'expose' => [
      'identifier' => $exposedIdentifier,
      'operator' => 'dr_occurrences_op',
      'use_operator' => FALSE,
      'required' => FALSE,
    ],
  ];

  // Input values are in the users timezone.
  $this
    ->assertFilter([
    $exposedIdentifier => '2014-07',
  ], [], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2014-08',
  ], [
    [
      'id' => $entity1
        ->id(),
    ],
    [
      'id' => $entity2
        ->id(),
    ],
    [
      'id' => $entity6
        ->id(),
    ],
  ], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2014-09',
  ], [
    [
      'id' => $entity2
        ->id(),
    ],
    [
      'id' => $entity3
        ->id(),
    ],
    [
      'id' => $entity4
        ->id(),
    ],
    [
      'id' => $entity6
        ->id(),
    ],
  ], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2014-10',
  ], [
    [
      'id' => $entity4
        ->id(),
    ],
    [
      'id' => $entity5
        ->id(),
    ],
    [
      'id' => $entity6
        ->id(),
    ],
  ], $filterOptions);
  $this
    ->assertFilter([
    $exposedIdentifier => '2014-11',
  ], [], $filterOptions);
}