public function DefaultViewsTest::testDefaultViews

Same name in this branch
  1. 8.x drupal/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php \Drupal\views\Tests\DefaultViewsTest::testDefaultViews()
  2. 8.x drupal/core/modules/views_ui/lib/Drupal/views_ui/Tests/DefaultViewsTest.php \Drupal\views_ui\Tests\DefaultViewsTest::testDefaultViews()

Test that all Default views work as expected.

File

drupal/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php, line 116
Definition of Drupal\views\Tests\DefaultViewsTest.

Class

DefaultViewsTest
Tests for views default views.

Namespace

Drupal\views\Tests

Code

public function testDefaultViews() {

  // Get all default views.
  $controller = $this->container
    ->get('plugin.manager.entity')
    ->getStorageController('view');
  $views = $controller
    ->load();
  foreach ($views as $name => $view_storage) {
    $view = $view_storage
      ->get('executable');
    $view
      ->initDisplay();
    foreach ($view->storage
      ->get('display') as $display_id => $display) {
      $view
        ->setDisplay($display_id);

      // Add any args if needed.
      if (array_key_exists($name, $this->viewArgMap)) {
        $view
          ->preExecute($this->viewArgMap[$name]);
      }
      $this
        ->assert(TRUE, format_string('View @view will be executed.', array(
        '@view' => $view->storage
          ->id(),
      )));
      $view
        ->execute();
      $tokens = array(
        '@name' => $name,
        '@display_id' => $display_id,
      );
      $this
        ->assertTrue($view->executed, format_string('@name:@display_id has been executed.', $tokens));
      $count = count($view->result);
      $this
        ->assertTrue($count > 0, format_string('@count results returned', array(
        '@count' => $count,
      )));
      $view
        ->destroy();
    }
  }
}