function ConfigEntityBaseUnitTest::testAddDependency

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testAddDependency()
  2. 10 core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testAddDependency()
  3. 11.x core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php \Drupal\Tests\Core\Config\Entity\ConfigEntityBaseUnitTest::testAddDependency()

@covers ::addDependency

File

core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php, line 221

Class

ConfigEntityBaseUnitTest
@coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityBase @group Config

Namespace

Drupal\Tests\Core\Config\Entity

Code

public function testAddDependency() {
    $method = new \ReflectionMethod('\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase', 'addDependency');
    $method->setAccessible(TRUE);
    $method->invoke($this->entity, 'module', $this->provider);
    $method->invoke($this->entity, 'module', 'core');
    $method->invoke($this->entity, 'module', 'node');
    $dependencies = $this->entity
        ->getDependencies();
    $this->assertNotContains($this->provider, $dependencies['module']);
    $this->assertNotContains('core', $dependencies['module']);
    $this->assertContains('node', $dependencies['module']);
    // Test sorting of dependencies.
    $method->invoke($this->entity, 'module', 'action');
    $dependencies = $this->entity
        ->getDependencies();
    $this->assertEquals([
        'action',
        'node',
    ], $dependencies['module']);
    // Test sorting of dependency types.
    $method->invoke($this->entity, 'entity', 'system.action.id');
    $dependencies = $this->entity
        ->getDependencies();
    $this->assertEquals([
        'entity',
        'module',
    ], array_keys($dependencies));
}

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