function FilterDateTimeTest::_testBetween

Same name and namespace in other branches
  1. 9 core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTimeTest::_testBetween()
  2. 10 core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTimeTest::_testBetween()
  3. 11.x core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\FilterDateTimeTest::_testBetween()

Test between operations.

1 call to FilterDateTimeTest::_testBetween()
FilterDateTimeTest::testDatetimeFilter in core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php
Test filter operations.

File

core/modules/datetime/tests/src/Kernel/Views/FilterDateTimeTest.php, line 118

Class

FilterDateTimeTest
Tests the <a href="/api/drupal/core%21modules%21datetime%21src%21Plugin%21views%21filter%21Date.php/class/Date/8.9.x" title="Date/time views filter." class="local">Drupal\datetime\Plugin\views\filter\Date</a> handler.

Namespace

Drupal\Tests\datetime\Kernel\Views

Code

protected function _testBetween() {
    $view = Views::getView('test_filter_datetime');
    $field = static::$field_name . '_value';
    // Test between with min and max.
    $view->initHandlers();
    $view->filter[$field]->operator = 'between';
    $view->filter[$field]->value['min'] = '2001-01-01';
    $view->filter[$field]->value['max'] = '2002-01-01';
    $view->setDisplay('default');
    $this->executeView($view);
    $expected_result = [
        [
            'nid' => $this->nodes[1]
                ->id(),
        ],
    ];
    $this->assertIdenticalResultset($view, $expected_result, $this->map);
    $view->destroy();
    // Test between with just max.
    $view->initHandlers();
    $view->filter[$field]->operator = 'between';
    $view->filter[$field]->value['max'] = '2002-01-01';
    $view->setDisplay('default');
    $this->executeView($view);
    $expected_result = [
        [
            'nid' => $this->nodes[0]
                ->id(),
        ],
        [
            'nid' => $this->nodes[1]
                ->id(),
        ],
    ];
    $this->assertIdenticalResultset($view, $expected_result, $this->map);
    $view->destroy();
    // Test not between with min and max.
    $view->initHandlers();
    $view->filter[$field]->operator = 'not between';
    $view->filter[$field]->value['min'] = '2001-01-01';
    // Set maximum date to date of node 1 to test range borders.
    $view->filter[$field]->value['max'] = '2001-10-10T12:12:12';
    $view->setDisplay('default');
    $this->executeView($view);
    $expected_result = [
        [
            'nid' => $this->nodes[0]
                ->id(),
        ],
        [
            'nid' => $this->nodes[2]
                ->id(),
        ],
        [
            'nid' => $this->nodes[3]
                ->id(),
        ],
    ];
    $this->assertIdenticalResultset($view, $expected_result, $this->map);
    $view->destroy();
    // Test not between with just max.
    $view->initHandlers();
    $view->filter[$field]->operator = 'not between';
    $view->filter[$field]->value['max'] = '2001-01-01';
    $view->setDisplay('default');
    $this->executeView($view);
    $expected_result = [
        [
            'nid' => $this->nodes[1]
                ->id(),
        ],
        [
            'nid' => $this->nodes[2]
                ->id(),
        ],
        [
            '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.