You are here

public function DiscoveryTraitTest::testHasDefinition in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php \Drupal\Tests\Component\Plugin\Discovery\DiscoveryTraitTest::testHasDefinition()

@covers ::hasDefinition @dataProvider providerHasDefinition

File

core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php, line 131

Class

DiscoveryTraitTest
@group Plugin @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryTrait

Namespace

Drupal\Tests\Component\Plugin\Discovery

Code

public function testHasDefinition($expected, $plugin_id) {
  $trait = $this
    ->getMockBuilder('Drupal\\Component\\Plugin\\Discovery\\DiscoveryTrait')
    ->setMethods([
    'getDefinition',
  ])
    ->getMockForTrait();

  // Set up our mocked getDefinition() to return TRUE for 'valid' and FALSE
  // for 'not_valid'.
  $trait
    ->expects($this
    ->once())
    ->method('getDefinition')
    ->will($this
    ->returnValueMap([
    [
      'valid',
      FALSE,
      TRUE,
    ],
    [
      'not_valid',
      FALSE,
      FALSE,
    ],
  ]));

  // Call hasDefinition().
  $this
    ->assertSame($expected, $trait
    ->hasDefinition($plugin_id));
}