function ViewExecutableTest::testInitMethods

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testInitMethods()
  2. 10 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testInitMethods()
  3. 11.x core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testInitMethods()

Tests the initDisplay() and initHandlers() methods.

File

core/modules/views/tests/src/Kernel/ViewExecutableTest.php, line 119

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\Tests\views\Kernel

Code

public function testInitMethods() {
    $view = Views::getView('test_destroy');
    $view->initDisplay();
    $this->assertInstanceOf(DefaultDisplay::class, $view->display_handler);
    $this->assertInstanceOf(DefaultDisplay::class, $view->displayHandlers
        ->get('default'));
    $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->assertGreaterThan(0, count($view->{$type}), new FormattableMarkup('Make sure a %type instance got instantiated.', [
            '%type' => $type,
        ]));
    }
    // initHandlers() should create display handlers automatically as well.
    $this->assertInstanceOf(DefaultDisplay::class, $view->display_handler);
    $this->assertInstanceOf(DefaultDisplay::class, $view->displayHandlers
        ->get('default'));
    $view_hash = spl_object_hash($view);
    $display_hash = spl_object_hash($view->display_handler);
    // Test the initStyle() method.
    $view->initStyle();
    $this->assertInstanceOf(DefaultStyle::class, $view->style_plugin);
    // Test the plugin has been invited 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->assertInstanceOf(Sql::class, $view->query);
    $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->assertInstanceOf(DefaultDisplay::class, $display_plugin);
    $this->assertInstanceOf(DefaultDisplay::class, $view->display_handler);
    $this->assertIdentical($display_plugin, $view->getDisplay(), 'The same display plugin instance was returned.');
    $style_plugin = $view->getStyle();
    $this->assertInstanceOf(DefaultStyle::class, $style_plugin);
    $this->assertInstanceOf(DefaultStyle::class, $view->style_plugin);
    $this->assertIdentical($style_plugin, $view->getStyle(), 'The same style plugin instance was returned.');
    $pager_plugin = $view->getPager();
    $this->assertInstanceOf(PagerPluginBase::class, $pager_plugin);
    $this->assertInstanceOf(PagerPluginBase::class, $view->pager);
    $this->assertIdentical($pager_plugin, $view->getPager(), 'The same pager plugin instance was returned.');
    $query_plugin = $view->getQuery();
    $this->assertInstanceOf(QueryPluginBase::class, $query_plugin);
    $this->assertInstanceOf(QueryPluginBase::class, $view->query);
    $this->assertIdentical($query_plugin, $view->getQuery(), 'The same query plugin instance was returned.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.