You are here

function DiscoveryTestBase::testDiscoveryInterface in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Plugin/Discovery/DiscoveryTestBase.php \Drupal\system\Tests\Plugin\Discovery\DiscoveryTestBase::testDiscoveryInterface()

Tests getDefinitions() and getDefinition().

File

core/modules/system/src/Tests/Plugin/Discovery/DiscoveryTestBase.php, line 45
Contains \Drupal\system\Tests\Plugin\Discovery\DiscoveryTestBase.

Class

DiscoveryTestBase
Base class for plugin discovery tests.

Namespace

Drupal\system\Tests\Plugin\Discovery

Code

function testDiscoveryInterface() {

  // Ensure that getDefinitions() returns the expected definitions.
  // For the arrays to be identical (instead of only equal), they must be
  // sorted equally, which seems unnecessary here.
  // The discovered definitions may contain circular references; use a custom
  // assertion message to prevent var_export() from getting called.
  $this
    ->assertEqual($this->discovery
    ->getDefinitions(), $this->expectedDefinitions, 'Expected definitions found.');

  // Ensure that getDefinition() returns the expected definition.
  foreach ($this->expectedDefinitions as $id => $definition) {
    $this
      ->assertDefinitionIdentical($this->discovery
      ->getDefinition($id), $definition);
  }

  // Ensure that an empty array is returned if no plugin definitions are found.
  $this
    ->assertIdentical($this->emptyDiscovery
    ->getDefinitions(), array(), 'array() returned if no plugin definitions are found.');

  // Ensure that NULL is returned as the definition of a non-existing plugin.
  $this
    ->assertIdentical($this->emptyDiscovery
    ->getDefinition('non_existing', FALSE), NULL, 'NULL returned as the definition of a non-existing plugin.');
}