function DefaultViewsTest::testArchiveView
Same name in other branches
- 9 core/modules/views/tests/src/Functional/DefaultViewsTest.php \Drupal\Tests\views\Functional\DefaultViewsTest::testArchiveView()
- 8.9.x core/modules/views/tests/src/Functional/DefaultViewsTest.php \Drupal\Tests\views\Functional\DefaultViewsTest::testArchiveView()
- 11.x core/modules/views/tests/src/Functional/DefaultViewsTest.php \Drupal\Tests\views\Functional\DefaultViewsTest::testArchiveView()
Tests the archive view.
File
-
core/
modules/ views/ tests/ src/ Functional/ DefaultViewsTest.php, line 186
Class
- DefaultViewsTest
- Tests the default views provided by views.
Namespace
Drupal\Tests\views\FunctionalCode
public function testArchiveView() : void {
// Create additional nodes compared to the one in the setup method.
// Create two nodes in the same month, and one in each following month.
$node = [
// Sun, 19 Nov 1978 05:00:00 GMT.
'created' => 280299600,
];
$this->drupalCreateNode($node);
$this->drupalCreateNode($node);
$node = [
// Tue, 19 Dec 1978 05:00:00 GMT.
'created' => 282891600,
];
$this->drupalCreateNode($node);
$node = [
// Fri, 19 Jan 1979 05:00:00 GMT.
'created' => 285570000,
];
$this->drupalCreateNode($node);
$view = Views::getView('archive');
$view->setDisplay('page_1');
$this->executeView($view);
$columns = [
'nid',
'created_year_month',
'num_records',
];
$column_map = array_combine($columns, $columns);
// Create time of additional nodes created in the setup method.
$created_year_month = date('Ym', \Drupal::time()->getRequestTime() - 3600);
$expected_result = [
[
'nid' => 1,
'created_year_month' => $created_year_month,
'num_records' => 11,
],
[
'nid' => 15,
'created_year_month' => 197901,
'num_records' => 1,
],
[
'nid' => 14,
'created_year_month' => 197812,
'num_records' => 1,
],
[
'nid' => 12,
'created_year_month' => 197811,
'num_records' => 2,
],
];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
$view->storage
->setStatus(TRUE);
$view->save();
\Drupal::service('router.builder')->rebuild();
$this->drupalGet('archive');
$this->assertSession()
->statusCodeEquals(200);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.