You are here

public function DefaultViewsTest::testArchiveView in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Tests/DefaultViewsTest.php \Drupal\views\Tests\DefaultViewsTest::testArchiveView()

Tests the archive view.

File

core/modules/views/src/Tests/DefaultViewsTest.php, line 166
Contains \Drupal\views\Tests\DefaultViewsTest.

Class

DefaultViewsTest
Tests the default views provided by views.

Namespace

Drupal\views\Tests

Code

public function testArchiveView() {

  // 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 = array(
    'created' => 280299600,
  );
  $this
    ->drupalCreateNode($node);
  $this
    ->drupalCreateNode($node);
  $node = array(
    'created' => 282891600,
  );
  $this
    ->drupalCreateNode($node);
  $node = array(
    'created' => 285570000,
  );
  $this
    ->drupalCreateNode($node);
  $view = Views::getView('archive');
  $view
    ->setDisplay('page_1');
  $this
    ->executeView($view);
  $columns = array(
    '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', REQUEST_TIME - 3600);
  $expected_result = array(
    array(
      'nid' => 1,
      'created_year_month' => $created_year_month,
      'num_records' => 11,
    ),
    array(
      'nid' => 15,
      'created_year_month' => 197901,
      'num_records' => 1,
    ),
    array(
      'nid' => 14,
      'created_year_month' => 197812,
      'num_records' => 1,
    ),
    array(
      '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
    ->assertResponse(200);
}