You are here

public function DefaultViewsTest::testDefaultViews in Views (for Drupal 7) 8.3

Same name in this branch
  1. 8.3 lib/Drupal/views/Tests/DefaultViewsTest.php \Drupal\views\Tests\DefaultViewsTest::testDefaultViews()
  2. 8.3 lib/Drupal/views/Tests/UI/DefaultViewsTest.php \Drupal\views\Tests\UI\DefaultViewsTest::testDefaultViews()

Test that all Default views work as expected.

File

lib/Drupal/views/Tests/DefaultViewsTest.php, line 119
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 = entity_get_controller('view');
  $views = $controller
    ->load();
  foreach ($views as $name => $view_storage) {
    $view = new ViewExecutable($view_storage);
    $view
      ->initDisplay();
    foreach ($view->storage->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->name,
      )));
      $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();
    }
  }
}