function FilterDateTest::_testOffset

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::_testOffset()
  2. 10 core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::_testOffset()
  3. 11.x core/modules/views/tests/src/Functional/Handler/FilterDateTest.php \Drupal\Tests\views\Functional\Handler\FilterDateTest::_testOffset()

Test the general offset functionality.

1 call to FilterDateTest::_testOffset()
FilterDateTest::testDateFilter in core/modules/views/tests/src/Functional/Handler/FilterDateTest.php
Runs other test methods.

File

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

Class

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

Namespace

Drupal\Tests\views\Functional\Handler

Code

protected function _testOffset() {
    $view = Views::getView('test_filter_date_between');
    // Test offset for simple operator.
    $view->initHandlers();
    $view->filter['created']->operator = '>';
    $view->filter['created']->value['type'] = 'offset';
    $view->filter['created']->value['value'] = '+1 hour';
    $view->executeDisplay('default');
    $expected_result = [
        [
            'nid' => $this->nodes[3]
                ->id(),
        ],
    ];
    $this->assertIdenticalResultset($view, $expected_result, $this->map);
    $view->destroy();
    // Test offset for between operator.
    $view->initHandlers();
    $view->filter['created']->operator = 'between';
    $view->filter['created']->value['type'] = 'offset';
    $view->filter['created']->value['max'] = '+2 days';
    $view->filter['created']->value['min'] = '+1 hour';
    $view->executeDisplay('default');
    $expected_result = [
        [
            'nid' => $this->nodes[3]
                ->id(),
        ],
    ];
    $this->assertIdenticalResultset($view, $expected_result, $this->map);
}

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