function DiscoveryTestBase::testDiscoveryInterface

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Plugin/Discovery/DiscoveryTestBase.php \Drupal\KernelTests\Core\Plugin\Discovery\DiscoveryTestBase::testDiscoveryInterface()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/Discovery/DiscoveryTestBase.php \Drupal\KernelTests\Core\Plugin\Discovery\DiscoveryTestBase::testDiscoveryInterface()
  3. 10 core/tests/Drupal/KernelTests/Core/Plugin/Discovery/DiscoveryTestBase.php \Drupal\KernelTests\Core\Plugin\Discovery\DiscoveryTestBase::testDiscoveryInterface()

Tests getDefinitions() and getDefinition().

File

core/tests/Drupal/KernelTests/Core/Plugin/Discovery/DiscoveryTestBase.php, line 42

Class

DiscoveryTestBase
Base class for plugin discovery tests.

Namespace

Drupal\KernelTests\Core\Plugin\Discovery

Code

public function testDiscoveryInterface() : void {
    // 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->assertEquals($this->expectedDefinitions, $this->discovery
        ->getDefinitions(), '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->assertSame([], $this->emptyDiscovery
        ->getDefinitions(), 'array() returned if no plugin definitions are found.');
    // Ensure that NULL is returned as the definition of a non-existing plugin.
    $this->assertNull($this->emptyDiscovery
        ->getDefinition('non_existing', FALSE), 'NULL returned as the definition of a non-existing plugin.');
}

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