You are here

protected function FilterDateTimeTest::_testBetween in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Tests/Views/FilterDateTimeTest.php \Drupal\datetime\Tests\Views\FilterDateTimeTest::_testBetween()

Test between operations.

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

File

core/modules/datetime/src/Tests/Views/FilterDateTimeTest.php, line 110
Contains \Drupal\datetime\Tests\Views\FilterDateTimeTest.

Class

FilterDateTimeTest
Tests the Drupal\datetime\Plugin\views\filter\Date handler.

Namespace

Drupal\datetime\Tests\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';
  $view->filter[$field]->value['max'] = '2002-01-01';
  $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);
}