function DiscoveryTestBase::testDiscoveryInterface

Tests getDefinitions() and getDefinition().

File

drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/DiscoveryTestBase.php, line 44
Definition of Drupal\system\Tests\Plugin\Discovery\DiscoveryTestBase.

Class

DiscoveryTestBase
Tests that plugins are correctly discovered.

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 unneccessary here.
  $this
    ->assertEqual($this->discovery
    ->getDefinitions(), $this->expectedDefinitions);

  // Ensure that getDefinition() returns the expected definition.
  foreach ($this->expectedDefinitions as $id => $definition) {
    $this
      ->assertIdentical($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'), NULL, 'NULL returned as the definition of a non-existing plugin.');
}