function ArgumentDateTest::testWeekHandler

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

Tests the Week handler.

See also

\Drupal\node\Plugin\views\argument\CreatedWeek

File

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

Class

ArgumentDateTest
Tests the core date argument handlers.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testWeekHandler() {
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 9, 26, 2008),
    ])
        ->condition('id', 1)
        ->execute();
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 2, 29, 2004),
    ])
        ->condition('id', 2)
        ->execute();
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 1, 1, 2000),
    ])
        ->condition('id', 3)
        ->execute();
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 1, 10, 2000),
    ])
        ->condition('id', 4)
        ->execute();
    $this->container
        ->get('database')
        ->update('views_test_data')
        ->fields([
        'created' => gmmktime(0, 0, 0, 2, 1, 2000),
    ])
        ->condition('id', 5)
        ->execute();
    $view = Views::getView('test_argument_date');
    $view->setDisplay('embed_3');
    // Check the week calculation for a leap year.
    // @see http://wikipedia.org/wiki/ISO_week_date#Calculation
    $this->executeView($view, [
        '39',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 1,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_3');
    // Check the week calculation for the 29th of February in a leap year.
    // @see http://wikipedia.org/wiki/ISO_week_date#Calculation
    $this->executeView($view, [
        '09',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 2,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_3');
    // The first jan 2000 was still in the last week of the previous year.
    $this->executeView($view, [
        '52',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 3,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_3');
    $this->executeView($view, [
        '02',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 4,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_3');
    $this->executeView($view, [
        '05',
    ]);
    $expected = [];
    $expected[] = [
        'id' => 5,
    ];
    $this->assertIdenticalResultset($view, $expected, $this->columnMap);
    $view->destroy();
    $view->setDisplay('embed_3');
    $this->executeView($view, [
        '23',
    ]);
    $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.