function FilterDateTest::_testBetween

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

Tests the filter operator between/not between.

1 call to FilterDateTest::_testBetween()
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 129

Class

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

Namespace

Drupal\Tests\views\Functional\Handler

Code

protected function _testBetween() {
    $view = Views::getView('test_filter_date_between');
    // Test between with min and max.
    $view->initHandlers();
    $view->filter['created']->operator = 'between';
    $view->filter['created']->value['min'] = $this->dateFormatter
        ->format(150000, 'custom', 'Y-m-d H:i:s');
    $view->filter['created']->value['max'] = $this->dateFormatter
        ->format(200000, 'custom', 'Y-m-d H:i:s');
    $view->executeDisplay('default');
    $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['created']->operator = 'between';
    $view->filter['created']->value['max'] = $this->dateFormatter
        ->format(200000, 'custom', 'Y-m-d H:i:s');
    $view->executeDisplay('default');
    $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['created']->operator = 'not between';
    $view->filter['created']->value['min'] = $this->dateFormatter
        ->format(100000, 'custom', 'Y-m-d H:i:s');
    $view->filter['created']->value['max'] = $this->dateFormatter
        ->format(200000, 'custom', 'Y-m-d H:i:s');
    $view->executeDisplay('default');
    $expected_result = [
        [
            '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['created']->operator = 'not between';
    $view->filter['created']->value['max'] = $this->dateFormatter
        ->format(200000, 'custom', 'Y-m-d H:i:s');
    $view->executeDisplay('default');
    $expected_result = [
        [
            '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.