You are here

function FilterDateTest::testBetween in Views (for Drupal 7) 8.3

Tests the filter operator between/not between.

File

lib/Drupal/views/Tests/Handler/FilterDateTest.php, line 79
Definition of Drupal\views\Tests\Handler\FilterDateTest.

Class

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

Namespace

Drupal\views\Tests\Handler

Code

function testBetween() {
  $saved_view = $this
    ->createViewFromConfig('test_filter_date_between');

  // Test between with min and max.
  $view = $this
    ->getView($saved_view);
  $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]->nid,
    ),
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->map);

  // Test between with just max.
  $view = $this
    ->getView($saved_view);
  $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]->nid,
    ),
    array(
      'nid' => $this->nodes[1]->nid,
    ),
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->map);

  // Test not between with min and max.
  $view = $this
    ->getView($saved_view);
  $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]->nid,
    ),
    array(
      'nid' => $this->nodes[2]->nid,
    ),
    array(
      'nid' => $this->nodes[3]->nid,
    ),
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->map);

  // Test not between with just max.
  $view = $this
    ->getView($saved_view);
  $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]->nid,
    ),
    array(
      'nid' => $this->nodes[2]->nid,
    ),
    array(
      'nid' => $this->nodes[3]->nid,
    ),
  );
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->map);
}