You are here

public function DatetimeRangeViewUpdateTest::testViewsPostUpdateDateRangeFilterValues in Drupal 8

Tests that datetime_range filter values are updated properly.

File

core/modules/datetime_range/tests/src/Functional/Update/DatetimeRangeViewUpdateTest.php, line 32

Class

DatetimeRangeViewUpdateTest
Test update of views with datetime_range filters.

Namespace

Drupal\Tests\datetime_range\Functional\Update

Code

public function testViewsPostUpdateDateRangeFilterValues() {

  // Load our pre-update test view.
  $view = View::load('test_datetime_range_filter_values');
  $data = $view
    ->toArray();

  // Check pre-update filter values.
  $filter1 = $data['display']['default']['display_options']['filters']['field_range_value'];
  $this
    ->assertSame('string', $filter1['plugin_id']);

  // Check pre-update filter with operator going to be mapped.
  $filter2 = $data['display']['default']['display_options']['filters']['field_range_end_value'];
  $this
    ->assertSame('string', $filter2['plugin_id']);
  $this
    ->assertSame('', $filter2['value']);
  $this
    ->assertSame('contains', $filter2['operator']);

  // Check pre-update sort values.
  $sort = $data['display']['default']['display_options']['sorts']['field_range_value'];
  $this
    ->assertSame('standard', $sort['plugin_id']);
  $this
    ->runUpdates();

  // Reload and initialize our test view.
  $view = View::load('test_datetime_range_filter_values');
  $data = $view
    ->toArray();

  // Check filter values.
  $filter1 = $data['display']['default']['display_options']['filters']['field_range_value'];
  $this
    ->assertSame('datetime', $filter1['plugin_id']);
  $this
    ->assertSame('2017', $filter1['value']['value']);
  $this
    ->assertSame('=', $filter1['operator']);

  // Check string to datetime operator/value mapping.
  $filter2 = $data['display']['default']['display_options']['filters']['field_range_end_value'];
  $this
    ->assertSame('datetime', $filter2['plugin_id']);
  $this
    ->assertSame('.*', $filter2['value']['value']);
  $this
    ->assertSame('regular_expression', $filter2['operator']);

  // Check sort values.
  $sort = $data['display']['default']['display_options']['sorts']['field_range_value'];
  $this
    ->assertSame('datetime', $sort['plugin_id']);
}