function FilterDateTest::testExposedOffsetDefaultAppliedOnPageLoad

Same name and namespace in other branches
  1. main core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::testExposedOffsetDefaultAppliedOnPageLoad()

Tests an exposed date filter with an offset default value.

Verify that results are filtered on page load without requiring form submission.

File

core/modules/views/tests/src/Functional/Handler/FilterDateTest.php, line 370

Class

FilterDateTest
Tests the core Drupal\views\Plugin\views\filter\Date handler.

Namespace

Drupal\Tests\views\Functional\Handler

Code

public function testExposedOffsetDefaultAppliedOnPageLoad() : void {
  $this->drupalLogin($this->drupalCreateUser([
    'administer views',
  ]));
  // Expose the filter with operator > and default offset "now".
  $this->drupalGet('admin/structure/views/nojs/handler/test_filter_date_between/default/filter/created');
  $this->submitForm([], 'Expose filter');
  $edit = [
    'options[operator]' => '>',
    'options[value][type]' => 'offset',
    'options[value][value]' => 'now',
  ];
  $this->submitForm($edit, 'Apply');
  // Add a page display and save.
  $this->drupalGet('admin/structure/views/view/test_filter_date_between/edit');
  $this->submitForm([], 'Add Page');
  $this->drupalGet('admin/structure/views/nojs/display/test_filter_date_between/page_1/path');
  $this->submitForm([
    'path' => 'exposed-offset-default',
  ], 'Apply');
  $this->submitForm([], 'Save');
  // On page load (no form submission), only the future node should appear.
  $this->drupalGet('exposed-offset-default');
  $results = $this->cssSelect('.view-content .field-content');
  $this->assertCount(1, $results);
  $this->assertEquals($this->nodes[3]
    ->id(), $results[0]->getText());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.