Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\views\Kernel;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\views\Views;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests that an instance of all views plugins can be created.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group views
|
Chris@0
|
11 */
|
Chris@0
|
12 class PluginInstanceTest extends ViewsKernelTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * All views plugin types.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 protected $pluginTypes = [
|
Chris@0
|
20 'access',
|
Chris@0
|
21 'area',
|
Chris@0
|
22 'argument',
|
Chris@0
|
23 'argument_default',
|
Chris@0
|
24 'argument_validator',
|
Chris@0
|
25 'cache',
|
Chris@0
|
26 'display_extender',
|
Chris@0
|
27 'display',
|
Chris@0
|
28 'exposed_form',
|
Chris@0
|
29 'field',
|
Chris@0
|
30 'filter',
|
Chris@0
|
31 'join',
|
Chris@0
|
32 'pager',
|
Chris@0
|
33 'query',
|
Chris@0
|
34 'relationship',
|
Chris@0
|
35 'row',
|
Chris@0
|
36 'sort',
|
Chris@0
|
37 'style',
|
Chris@0
|
38 'wizard',
|
Chris@0
|
39 ];
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * An array of plugin definitions, keyed by plugin type.
|
Chris@0
|
43 *
|
Chris@0
|
44 * @var array
|
Chris@0
|
45 */
|
Chris@0
|
46 protected $definitions;
|
Chris@0
|
47
|
Chris@0
|
48 protected function setUp($import_test_views = TRUE) {
|
Chris@0
|
49 parent::setUp();
|
Chris@0
|
50
|
Chris@0
|
51 $this->definitions = Views::getPluginDefinitions();
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * Confirms that there is plugin data for all views plugin types.
|
Chris@0
|
56 */
|
Chris@0
|
57 public function testPluginData() {
|
Chris@0
|
58 // Check that we have an array of data.
|
Chris@0
|
59 $this->assertTrue(is_array($this->definitions), 'Plugin data is an array.');
|
Chris@0
|
60
|
Chris@0
|
61 // Check all plugin types.
|
Chris@0
|
62 foreach ($this->pluginTypes as $type) {
|
Chris@0
|
63 $this->assertTrue(array_key_exists($type, $this->definitions), format_string('Key for plugin type @type found.', ['@type' => $type]));
|
Chris@0
|
64 $this->assertTrue(is_array($this->definitions[$type]) && !empty($this->definitions[$type]), format_string('Plugin type @type has an array of plugins.', ['@type' => $type]));
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@0
|
67 // Tests that the plugin list has not missed any types.
|
Chris@0
|
68 $diff = array_diff(array_keys($this->definitions), $this->pluginTypes);
|
Chris@0
|
69 $this->assertTrue(empty($diff), 'All plugins were found and matched.');
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 /**
|
Chris@0
|
73 * Tests creating instances of every views plugin.
|
Chris@0
|
74 *
|
Chris@0
|
75 * This will iterate through all plugins from _views_fetch_plugin_data().
|
Chris@0
|
76 */
|
Chris@0
|
77 public function testPluginInstances() {
|
Chris@0
|
78 foreach ($this->definitions as $type => $plugins) {
|
Chris@0
|
79 // Get a plugin manager for this type.
|
Chris@0
|
80 $manager = $this->container->get("plugin.manager.views.$type");
|
Chris@0
|
81 foreach ($plugins as $id => $definition) {
|
Chris@0
|
82 // Get a reflection class for this plugin.
|
Chris@0
|
83 // We only want to test true plugins, i.e. They extend PluginBase.
|
Chris@0
|
84 $reflection = new \ReflectionClass($definition['class']);
|
Chris@0
|
85 if ($reflection->isSubclassOf('Drupal\views\Plugin\views\PluginBase')) {
|
Chris@0
|
86 // Create a plugin instance and check what it is. This is not just
|
Chris@0
|
87 // good to check they can be created but for throwing any notices for
|
Chris@0
|
88 // method signatures etc. too.
|
Chris@0
|
89 $instance = $manager->createInstance($id);
|
Chris@0
|
90 $this->assertTrue($instance instanceof $definition['class'], format_string('Instance of @type:@id created', ['@type' => $type, '@id' => $id]));
|
Chris@0
|
91 }
|
Chris@0
|
92 }
|
Chris@0
|
93 }
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@0
|
96 }
|