3 namespace Drupal\Tests\views\Functional\Handler;
5 use Drupal\comment\Tests\CommentTestTrait;
6 use Drupal\Tests\views\Functional\ViewTestBase;
7 use Drupal\views\ViewExecutable;
8 use Drupal\views\Plugin\views\HandlerBase;
9 use Drupal\views\Plugin\views\filter\InOperator;
10 use Drupal\views\Entity\View;
13 * Tests instances of all handlers.
17 class HandlerAllTest extends ViewTestBase {
26 public static $modules = [
47 * Tests most of the handlers.
49 public function testHandlers() {
50 $this->drupalCreateContentType(['type' => 'article']);
51 $this->addDefaultCommentField('node', 'article');
53 $object_types = array_keys(ViewExecutable::getHandlerTypes());
54 foreach ($this->container->get('views.views_data')->get() as $base_table => $info) {
55 if (!isset($info['table']['base'])) {
59 $view = View::create(['base_table' => $base_table]);
60 $view = $view->getExecutable();
62 // @todo The groupwise relationship is currently broken.
63 $exclude[] = 'taxonomy_term_field_data:tid_representative';
64 $exclude[] = 'users_field_data:uid_representative';
66 // Go through all fields and there through all handler types.
67 foreach ($info as $field => $field_info) {
68 // Table is a reserved key for the metainformation.
69 if ($field != 'table' && !in_array("$base_table:$field", $exclude)) {
71 'table' => $base_table,
74 foreach ($object_types as $type) {
75 if (isset($field_info[$type]['id'])) {
77 if ($type == 'filter') {
78 $handler = $this->container->get("plugin.manager.views.$type")->getHandler($item);
79 // Set the value to use for the filter based on the filter type.
80 if ($handler instanceof InOperator) {
81 $options['value'] = [1];
84 $options['value'] = 1;
87 $view->addHandler('default', $type, $base_table, $field, $options);
93 // Go through each step individually to see whether some parts are
100 // Make sure all handlers extend the HandlerBase.
101 foreach ($object_types as $type) {
102 if (isset($view->{$type})) {
103 foreach ($view->{$type} as $handler) {
104 $this->assertTrue($handler instanceof HandlerBase, format_string(
105 '@type handler of class %class is an instance of HandlerBase',
108 '%class' => get_class($handler),