function HookDiscoveryTest::testGetDefinitions

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

Tests the getDefinitions() method with some plugins.

See also

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

File

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

Class

HookDiscoveryTest
@coversDefaultClass \Drupal\Core\Plugin\Discovery\HookDiscovery @group Plugin

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testGetDefinitions() {
    $this->moduleHandler
        ->expects($this->once())
        ->method('getImplementations')
        ->with('test_plugin')
        ->will($this->returnValue([
        'hook_discovery_test',
        'hook_discovery_test2',
    ]));
    $this->moduleHandler
        ->expects($this->at(1))
        ->method('invoke')
        ->with('hook_discovery_test', 'test_plugin')
        ->will($this->returnValue($this->hookDiscoveryTestTestPlugin()));
    $this->moduleHandler
        ->expects($this->at(2))
        ->method('invoke')
        ->with('hook_discovery_test2', 'test_plugin')
        ->will($this->returnValue($this->hookDiscoveryTest2TestPlugin()));
    $definitions = $this->hookDiscovery
        ->getDefinitions();
    $this->assertCount(3, $definitions);
    $this->assertEquals($definitions['test_id_1']['class'], 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Apple');
    $this->assertEquals($definitions['test_id_2']['class'], 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Orange');
    $this->assertEquals($definitions['test_id_3']['class'], 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Cherry');
    // Ensure that the module was set.
    $this->assertEquals($definitions['test_id_1']['provider'], 'hook_discovery_test');
    $this->assertEquals($definitions['test_id_2']['provider'], 'hook_discovery_test');
    $this->assertEquals($definitions['test_id_3']['provider'], 'hook_discovery_test2');
}

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