function ArgumentDateTimeTest::testDatetimeArgumentYear

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()
  2. 8.9.x core/modules/datetime/tests/src/Kernel/Views/ArgumentDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\ArgumentDateTimeTest::testDatetimeArgumentYear()
  3. 10 core/modules/datetime/tests/src/Kernel/Views/ArgumentDateTimeTest.php \Drupal\Tests\datetime\Kernel\Views\ArgumentDateTimeTest::testDatetimeArgumentYear()

Tests year argument.

See also

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

File

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

Class

ArgumentDateTimeTest
Tests the <a href="/api/drupal/core%21modules%21datetime%21src%21Plugin%21views%21filter%21Date.php/class/Date/11.x" title="Date/time views filter." class="local">Drupal\datetime\Plugin\views\filter\Date</a> handler.

Namespace

Drupal\Tests\datetime\Kernel\Views

Code

public function testDatetimeArgumentYear() : void {
    $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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.