function ModuleTest::testViewsFetchPluginNames

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/ModuleTest.php \Drupal\Tests\views\Kernel\ModuleTest::testViewsFetchPluginNames()
  2. 8.9.x core/modules/views/tests/src/Kernel/ModuleTest.php \Drupal\Tests\views\Kernel\ModuleTest::testViewsFetchPluginNames()
  3. 11.x 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 205

Class

ModuleTest
Tests basic functions from the Views module.

Namespace

Drupal\Tests\views\Kernel

Code

public function testViewsFetchPluginNames() : void {
    // 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.