You are here

public function PluginInstanceTest::testPluginInstances in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/PluginInstanceTest.php \Drupal\views\Tests\PluginInstanceTest::testPluginInstances()

Tests creating instances of every views plugin.

This will iterate through all plugins from _views_fetch_plugin_data().

File

core/modules/views/src/Tests/PluginInstanceTest.php, line 82
Contains \Drupal\views\Tests\PluginInstanceTest.

Class

PluginInstanceTest
Tests that an instance of all views plugins can be created.

Namespace

Drupal\views\Tests

Code

public function testPluginInstances() {
  foreach ($this->definitions as $type => $plugins) {

    // Get a plugin manager for this type.
    $manager = $this->container
      ->get("plugin.manager.views.{$type}");
    foreach ($plugins as $id => $definition) {

      // Get a reflection class for this plugin.
      // We only want to test true plugins, i.e. They extend PluginBase.
      $reflection = new \ReflectionClass($definition['class']);
      if ($reflection
        ->isSubclassOf('Drupal\\views\\Plugin\\views\\PluginBase')) {

        // Create a plugin instance and check what it is. This is not just
        // good to check they can be created but for throwing any notices for
        // method signatures etc. too.
        $instance = $manager
          ->createInstance($id);
        $this
          ->assertTrue($instance instanceof $definition['class'], format_string('Instance of @type:@id created', array(
          '@type' => $type,
          '@id' => $id,
        )));
      }
    }
  }
}