function HookDiscoveryTest::testGetDefinition

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\HookDiscoveryTest::testGetDefinition()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\HookDiscoveryTest::testGetDefinition()
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\HookDiscoveryTest::testGetDefinition()

Tests the getDefinition method with some plugins.

See also

\Drupal\Core\Plugin\Discovery::getDefinition()

File

core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php, line 89

Class

HookDiscoveryTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Plugin%21Discovery%21HookDiscovery.php/class/HookDiscovery/8.9.x" title="Provides a hook-based plugin discovery class." class="local">\Drupal\Core\Plugin\Discovery\HookDiscovery</a> @group Plugin

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testGetDefinition() {
    $this->moduleHandler
        ->expects($this->exactly(4))
        ->method('getImplementations')
        ->with('test_plugin')
        ->will($this->returnValue([
        'hook_discovery_test',
        'hook_discovery_test2',
    ]));
    $this->moduleHandler
        ->expects($this->any())
        ->method('invoke')
        ->will($this->returnValueMap([
        [
            'hook_discovery_test',
            'test_plugin',
            [],
            $this->hookDiscoveryTestTestPlugin(),
        ],
        [
            'hook_discovery_test2',
            'test_plugin',
            [],
            $this->hookDiscoveryTest2TestPlugin(),
        ],
    ]));
    $this->assertNull($this->hookDiscovery
        ->getDefinition('test_non_existent', FALSE));
    $plugin_definition = $this->hookDiscovery
        ->getDefinition('test_id_1');
    $this->assertEquals($plugin_definition['class'], 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Apple');
    $this->assertEquals($plugin_definition['provider'], 'hook_discovery_test');
    $plugin_definition = $this->hookDiscovery
        ->getDefinition('test_id_2');
    $this->assertEquals($plugin_definition['class'], 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Orange');
    $this->assertEquals($plugin_definition['provider'], 'hook_discovery_test');
    $plugin_definition = $this->hookDiscovery
        ->getDefinition('test_id_3');
    $this->assertEquals($plugin_definition['class'], 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Cherry');
    $this->assertEquals($plugin_definition['provider'], 'hook_discovery_test2');
}

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