You are here

public function ModuleTest::testViewsFetchPluginNames in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/ModuleTest.php \Drupal\Tests\views\Kernel\ModuleTest::testViewsFetchPluginNames()

Tests the \Drupal\views\Views::fetchPluginNames() method.

File

core/modules/views/tests/src/Kernel/ModuleTest.php, line 204

Class

ModuleTest
Tests basic functions from the Views module.

Namespace

Drupal\Tests\views\Kernel

Code

public function testViewsFetchPluginNames() {

  // All style plugins should be returned, as we have not specified a type.
  $plugins = Views::fetchPluginNames('style');
  $definitions = $this->container
    ->get('plugin.manager.views.style')
    ->getDefinitions();
  $expected = [];
  foreach ($definitions as $id => $definition) {
    $expected[$id] = $definition['title'];
  }
  asort($expected);
  $this
    ->assertSame(array_keys($expected), array_keys($plugins));

  // Test using the 'test' style plugin type only returns the test_style and
  // mapping_test plugins.
  $plugins = Views::fetchPluginNames('style', 'test');
  $this
    ->assertSame([
    'mapping_test',
    'test_style',
    'test_template_style',
  ], array_keys($plugins));

  // Test a non existent style plugin type returns no plugins.
  $plugins = Views::fetchPluginNames('style', $this
    ->randomString());
  $this
    ->assertSame([], $plugins);
}