function BlockConfigEntityUnitTest::testCalculateDependencies

Same name in other branches
  1. 9 core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php \Drupal\Tests\block\Unit\BlockConfigEntityUnitTest::testCalculateDependencies()
  2. 8.9.x core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php \Drupal\Tests\block\Unit\BlockConfigEntityUnitTest::testCalculateDependencies()
  3. 11.x core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php \Drupal\Tests\block\Unit\BlockConfigEntityUnitTest::testCalculateDependencies()

@covers ::calculateDependencies

File

core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php, line 97

Class

BlockConfigEntityUnitTest
@coversDefaultClass \Drupal\block\Entity\Block @group block

Namespace

Drupal\Tests\block\Unit

Code

public function testCalculateDependencies() : void {
    $this->themeHandler
        ->themeExists('stark')
        ->willReturn(TRUE);
    $values = [
        'theme' => 'stark',
    ];
    // Mock the entity under test so that we can mock getPluginCollections().
    $entity = $this->getMockBuilder('\\Drupal\\block\\Entity\\Block')
        ->setConstructorArgs([
        $values,
        $this->entityTypeId,
    ])
        ->onlyMethods([
        'getPluginCollections',
    ])
        ->getMock();
    // Create a configurable plugin that would add a dependency.
    $instance_id = $this->randomMachineName();
    $this->moduleHandler
        ->moduleExists('test')
        ->willReturn(TRUE);
    $instance = new TestConfigurablePlugin([], $instance_id, [
        'provider' => 'test',
    ]);
    // Create a plugin collection to contain the instance.
    $plugin_collection = $this->getMockBuilder('\\Drupal\\Core\\Plugin\\DefaultLazyPluginCollection')
        ->disableOriginalConstructor()
        ->onlyMethods([
        'get',
    ])
        ->getMock();
    $plugin_collection->expects($this->atLeastOnce())
        ->method('get')
        ->with($instance_id)
        ->willReturn($instance);
    $plugin_collection->addInstanceId($instance_id);
    // Return the mocked plugin collection.
    $entity->expects($this->once())
        ->method('getPluginCollections')
        ->willReturn([
        $plugin_collection,
    ]);
    $dependencies = $entity->calculateDependencies()
        ->getDependencies();
    $this->assertContains('test', $dependencies['module']);
    $this->assertContains('stark', $dependencies['theme']);
}

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