Chris@0: definitions = Views::getPluginDefinitions(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Confirms that there is plugin data for all views plugin types. Chris@0: */ Chris@0: public function testPluginData() { Chris@0: // Check that we have an array of data. Chris@0: $this->assertTrue(is_array($this->definitions), 'Plugin data is an array.'); Chris@0: Chris@0: // Check all plugin types. Chris@0: foreach ($this->pluginTypes as $type) { Chris@0: $this->assertTrue(array_key_exists($type, $this->definitions), format_string('Key for plugin type @type found.', ['@type' => $type])); Chris@0: $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: } Chris@0: Chris@0: // Tests that the plugin list has not missed any types. Chris@0: $diff = array_diff(array_keys($this->definitions), $this->pluginTypes); Chris@0: $this->assertTrue(empty($diff), 'All plugins were found and matched.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests creating instances of every views plugin. Chris@0: * Chris@0: * This will iterate through all plugins from _views_fetch_plugin_data(). Chris@0: */ Chris@0: public function testPluginInstances() { Chris@0: foreach ($this->definitions as $type => $plugins) { Chris@0: // Get a plugin manager for this type. Chris@0: $manager = $this->container->get("plugin.manager.views.$type"); Chris@0: foreach ($plugins as $id => $definition) { Chris@0: // Get a reflection class for this plugin. Chris@0: // We only want to test true plugins, i.e. They extend PluginBase. Chris@0: $reflection = new \ReflectionClass($definition['class']); Chris@0: if ($reflection->isSubclassOf('Drupal\views\Plugin\views\PluginBase')) { Chris@0: // Create a plugin instance and check what it is. This is not just Chris@0: // good to check they can be created but for throwing any notices for Chris@0: // method signatures etc. too. Chris@0: $instance = $manager->createInstance($id); Chris@0: $this->assertTrue($instance instanceof $definition['class'], format_string('Instance of @type:@id created', ['@type' => $type, '@id' => $id])); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }