You are here

protected function FilterDateTest::_testBetween in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Tests/Handler/FilterDateTest.php \Drupal\views\Tests\Handler\FilterDateTest::_testBetween()

Tests the filter operator between/not between.

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

File

core/modules/views/src/Tests/Handler/FilterDateTest.php, line 90
Contains \Drupal\views\Tests\Handler\FilterDateTest.

Class

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

Namespace

Drupal\views\Tests\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'] = format_date(150000, 'custom', 'Y-m-d H:s');
  $view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
  $view
    ->executeDisplay('default');
  $expected_result = array(
    array(
      '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'] = format_date(250000, 'custom', 'Y-m-d H:s');
  $view
    ->executeDisplay('default');
  $expected_result = array(
    array(
      'nid' => $this->nodes[0]
        ->id(),
    ),
    array(
      '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'] = format_date(150000, 'custom', 'Y-m-d H:s');
  $view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
  $view
    ->executeDisplay('default');
  $expected_result = array(
    array(
      'nid' => $this->nodes[0]
        ->id(),
    ),
    array(
      'nid' => $this->nodes[2]
        ->id(),
    ),
    array(
      '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'] = format_date(150000, 'custom', 'Y-m-d H:s');
  $view
    ->executeDisplay('default');
  $expected_result = array(
    array(
      'nid' => $this->nodes[1]
        ->id(),
    ),
    array(
      'nid' => $this->nodes[2]
        ->id(),
    ),
    array(
      'nid' => $this->nodes[3]
        ->id(),
    ),
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->map);
}