You are here

public function HookDiscoveryTest::testGetDefinitions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 60
Contains \Drupal\Tests\Core\Plugin\Discovery\HookDiscoveryTest.

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(array(
    'hook_discovery_test',
    'hook_discovery_test2',
  )));
  $this->moduleHandler
    ->expects($this
    ->at(1))
    ->method('invoke')
    ->with('hook_discovery_test', 'test_plugin')
    ->will($this
    ->returnValue(hook_discovery_test_test_plugin()));
  $this->moduleHandler
    ->expects($this
    ->at(2))
    ->method('invoke')
    ->with('hook_discovery_test2', 'test_plugin')
    ->will($this
    ->returnValue(hook_discovery_test2_test_plugin()));
  $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');
}