function ArgumentDateTest::testYearMonthHandler

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Handler/ArgumentDateTest.php \Drupal\Tests\views\Kernel\Handler\ArgumentDateTest::testYearMonthHandler()
  2. 10 core/modules/views/tests/src/Kernel/Handler/ArgumentDateTest.php \Drupal\Tests\views\Kernel\Handler\ArgumentDateTest::testYearMonthHandler()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/ArgumentDateTest.php \Drupal\Tests\views\Kernel\Handler\ArgumentDateTest::testYearMonthHandler()

Tests the YearMonth handler.

See also

\Drupal\node\Plugin\views\argument\CreatedYearMonth

File

core/modules/views/tests/src/Kernel/Handler/ArgumentDateTest.php, line 273

Class

ArgumentDateTest
Tests the core date argument handlers.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testYearMonthHandler() {
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 1, 1, 2001),
    ])
        ->condition('id', 3)
        ->execute();
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 4, 1, 2001),
    ])
        ->condition('id', 4)
        ->execute();
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 4, 1, 2001),
    ])
        ->condition('id', 5)
        ->execute();
    $view = Views::getView('test_argument_date');
    $view->setDisplay('embed_5');
    $this->executeView($view, [
        '200001',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 1,
    ];
    $expected[] = [
        'id' => 2,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_5');
    $this->executeView($view, [
        '200101',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 3,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_5');
    $this->executeView($view, [
        '200104',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 4,
    ];
    $expected[] = [
        'id' => 5,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_5');
    $this->executeView($view, [
        '201301',
    ]);
    $expected = [];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
}

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