public function DisplayKernelTest::testGetPlugin in Drupal 8
Same name and namespace in other branches
- 9 core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayKernelTest::testGetPlugin()
Tests the \Drupal\views\Plugin\views\display\DisplayPluginBase::getPlugin() method.
File
- core/
modules/ views/ tests/ src/ Kernel/ Plugin/ DisplayKernelTest.php, line 92
Class
- DisplayKernelTest
- Drupal unit tests for the DisplayPluginBase class.
Namespace
Drupal\Tests\views\Kernel\PluginCode
public function testGetPlugin() {
$view = Views::getView('test_display_defaults');
$view
->initDisplay();
$display_handler = $view->display_handler;
$this
->assertInstanceOf(AccessPluginBase::class, $display_handler
->getPlugin('access'));
$this
->assertInstanceOf(CachePluginBase::class, $display_handler
->getPlugin('cache'));
$this
->assertInstanceOf(ExposedFormPluginInterface::class, $display_handler
->getPlugin('exposed_form'));
$this
->assertInstanceOf(PagerPluginBase::class, $display_handler
->getPlugin('pager'));
$this
->assertInstanceOf(QueryPluginBase::class, $display_handler
->getPlugin('query'));
$this
->assertInstanceOf(RowPluginBase::class, $display_handler
->getPlugin('row'));
$this
->assertInstanceOf(StylePluginBase::class, $display_handler
->getPlugin('style'));
// Test that nothing is returned when an invalid type is requested.
$this
->assertNull($display_handler
->getPlugin('invalid'), 'NULL was returned for an invalid instance');
// Test that nothing was returned for an instance with no 'type' in options.
unset($display_handler->options['access']);
$this
->assertNull($display_handler
->getPlugin('access'), 'NULL was returned for a plugin type with no "type" option');
// Get a plugin twice, and make sure the same instance is returned.
$view
->destroy();
$view
->initDisplay();
$first = spl_object_hash($display_handler
->getPlugin('style'));
$second = spl_object_hash($display_handler
->getPlugin('style'));
$this
->assertIdentical($first, $second, 'The same plugin instance was returned.');
}