You are here

public function ViewExecutableTest::testInitMethods in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/ViewExecutableTest.php \Drupal\views\Tests\ViewExecutableTest::testInitMethods()

Tests the initDisplay() and initHandlers() methods.

File

core/modules/views/src/Tests/ViewExecutableTest.php, line 113
Contains \Drupal\views\Tests\ViewExecutableTest.

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\views\Tests

Code

public function testInitMethods() {
  $view = Views::getView('test_destroy');
  $view
    ->initDisplay();
  $this
    ->assertTrue($view->display_handler instanceof DefaultDisplay, 'Make sure a reference to the current display handler is set.');
  $this
    ->assertTrue($view->displayHandlers
    ->get('default') instanceof DefaultDisplay, 'Make sure a display handler is created for each display.');
  $view
    ->destroy();
  $view
    ->initHandlers();

  // Check for all handler types.
  $handler_types = array_keys(ViewExecutable::getHandlerTypes());
  foreach ($handler_types as $type) {

    // The views_test integration doesn't have relationships.
    if ($type == 'relationship') {
      continue;
    }
    $this
      ->assertTrue(count($view->{$type}), format_string('Make sure a %type instance got instantiated.', array(
      '%type' => $type,
    )));
  }

  // initHandlers() should create display handlers automatically as well.
  $this
    ->assertTrue($view->display_handler instanceof DefaultDisplay, 'Make sure a reference to the current display handler is set.');
  $this
    ->assertTrue($view->displayHandlers
    ->get('default') instanceof DefaultDisplay, 'Make sure a display handler is created for each display.');
  $view_hash = spl_object_hash($view);
  $display_hash = spl_object_hash($view->display_handler);

  // Test the initStyle() method.
  $view
    ->initStyle();
  $this
    ->assertTrue($view->style_plugin instanceof DefaultStyle, 'Make sure a reference to the style plugin is set.');

  // Test the plugin has been inited and view have references to the view and
  // display handler.
  $this
    ->assertEqual(spl_object_hash($view->style_plugin->view), $view_hash);
  $this
    ->assertEqual(spl_object_hash($view->style_plugin->displayHandler), $display_hash);

  // Test the initQuery method().
  $view
    ->initQuery();
  $this
    ->assertTrue($view->query instanceof Sql, 'Make sure a reference to the query is set');
  $this
    ->assertEqual(spl_object_hash($view->query->view), $view_hash);
  $this
    ->assertEqual(spl_object_hash($view->query->displayHandler), $display_hash);
  $view
    ->destroy();

  // Test the plugin  get methods.
  $display_plugin = $view
    ->getDisplay();
  $this
    ->assertTrue($display_plugin instanceof DefaultDisplay, 'An instance of DefaultDisplay was returned.');
  $this
    ->assertTrue($view->display_handler instanceof DefaultDisplay, 'The display_handler property has been set.');
  $this
    ->assertIdentical($display_plugin, $view
    ->getDisplay(), 'The same display plugin instance was returned.');
  $style_plugin = $view
    ->getStyle();
  $this
    ->assertTrue($style_plugin instanceof DefaultStyle, 'An instance of DefaultStyle was returned.');
  $this
    ->assertTrue($view->style_plugin instanceof DefaultStyle, 'The style_plugin property has been set.');
  $this
    ->assertIdentical($style_plugin, $view
    ->getStyle(), 'The same style plugin instance was returned.');
  $pager_plugin = $view
    ->getPager();
  $this
    ->assertTrue($pager_plugin instanceof PagerPluginBase, 'An instance of PagerPluginBase was returned.');
  $this
    ->assertTrue($view->pager instanceof PagerPluginBase, 'The pager property has been set.');
  $this
    ->assertIdentical($pager_plugin, $view
    ->getPager(), 'The same pager plugin instance was returned.');
  $query_plugin = $view
    ->getQuery();
  $this
    ->assertTrue($query_plugin instanceof QueryPluginBase, 'An instance of QueryPluginBase was returned.');
  $this
    ->assertTrue($view->query instanceof QueryPluginBase, 'The query property has been set.');
  $this
    ->assertIdentical($query_plugin, $view
    ->getQuery(), 'The same query plugin instance was returned.');
}