View source
<?php
namespace Drupal\views\Tests\Plugin;
use Drupal\views\Views;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase;
use Drupal\views\Plugin\views\pager\PagerPluginBase;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\Plugin\views\row\RowPluginBase;
class DisplayKernelTest extends ViewKernelTestBase {
public static $modules = array(
'block',
'node',
'field',
'user',
);
protected $pluginTypes = array(
'access',
'cache',
'query',
'exposed_form',
'pager',
'style',
'row',
);
protected $handlerTypes = array(
'fields',
'sorts',
);
public static $testViews = array(
'test_display_defaults',
);
public function testDefaultOptions() {
$view = Views::getView('test_display_defaults');
$view
->mergeDefaults();
$view
->save();
$view = Views::getView('test_display_defaults');
$view
->initDisplay();
$display_data = $view->storage
->get('display');
foreach ($view->displayHandlers as $id => $display) {
foreach ($this->pluginTypes as $type) {
$options = $display
->getOption($type);
$this
->assertIdentical($display_data[$id]['display_options'][$type]['options'], $options['options']);
}
foreach ($this->handlerTypes as $type) {
$options = $display
->getOption($type);
$this
->assertIdentical($display_data[$id]['display_options'][$type], $options);
}
}
}
public function testGetPlugin() {
$view = Views::getView('test_display_defaults');
$view
->initDisplay();
$display_handler = $view->display_handler;
$this
->assertTrue($display_handler
->getPlugin('access') instanceof AccessPluginBase, 'An access plugin instance was returned.');
$this
->assertTrue($display_handler
->getPlugin('cache') instanceof CachePluginBase, 'A cache plugin instance was returned.');
$this
->assertTrue($display_handler
->getPlugin('exposed_form') instanceof ExposedFormPluginBase, 'An exposed_form plugin instance was returned.');
$this
->assertTrue($display_handler
->getPlugin('pager') instanceof PagerPluginBase, 'A pager plugin instance was returned.');
$this
->assertTrue($display_handler
->getPlugin('query') instanceof QueryPluginBase, 'A query plugin instance was returned.');
$this
->assertTrue($display_handler
->getPlugin('row') instanceof RowPluginBase, 'A row plugin instance was returned.');
$this
->assertTrue($display_handler
->getPlugin('style') instanceof StylePluginBase, 'A style plugin instance was returned.');
$this
->assertNull($display_handler
->getPlugin('invalid'), 'NULL was returned for an invalid instance');
unset($display_handler->options['access']);
$this
->assertNull($display_handler
->getPlugin('access'), 'NULL was returned for a plugin type with no "type" option');
$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.');
}
}