You are here

public function ArgumentDateTimeTest::testDatetimeArgumentYear in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/datetime/tests/src/Kernel/Views/ArgumentDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\ArgumentDateTimeTest::testDatetimeArgumentYear()

Test year argument.

See also

\Drupal\datetime\Plugin\views\argument\YearDate

File

core/modules/datetime/tests/src/Kernel/Views/ArgumentDateTimeTest.php, line 53

Class

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

Namespace

Drupal\Tests\datetime\Kernel\Views

Code

public function testDatetimeArgumentYear() {
  $view = Views::getView('test_argument_datetime');

  // The 'default' display has the 'year' argument.
  $view
    ->setDisplay('default');
  $this
    ->executeView($view, [
    '2000',
  ]);
  $expected = [];
  $expected[] = [
    'nid' => $this->nodes[0]
      ->id(),
  ];
  $this
    ->assertIdenticalResultset($view, $expected, $this->map);
  $view
    ->destroy();
  $view
    ->setDisplay('default');
  $this
    ->executeView($view, [
    '2002',
  ]);
  $expected = [];
  $expected[] = [
    'nid' => $this->nodes[2]
      ->id(),
  ];
  $this
    ->assertIdenticalResultset($view, $expected, $this->map);
  $view
    ->destroy();
  $view
    ->setDisplay('default');
  $this
    ->executeView($view, [
    '2003',
  ]);
  $expected = [];
  $expected[] = [
    'nid' => $this->nodes[3]
      ->id(),
  ];
  $this
    ->assertIdenticalResultset($view, $expected, $this->map);
  $view
    ->destroy();

  // Tests different system timezone with the same nodes.
  $this
    ->setSiteTimezone('America/Vancouver');
  $view
    ->setDisplay('default');
  $this
    ->executeView($view, [
    '2002',
  ]);
  $expected = [];

  // Only the 3rd node is returned here since UTC 2002-01-01T00:00:00 is still
  // in 2001 for this user timezone.
  $expected[] = [
    'nid' => $this->nodes[3]
      ->id(),
  ];
  $this
    ->assertIdenticalResultset($view, $expected, $this->map);
  $view
    ->destroy();
}