You are here

public function BlockConfigEntityUnitTest::testCalculateDependencies in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 76
Contains \Drupal\Tests\block\Unit\BlockConfigEntityUnitTest.

Class

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

Namespace

Drupal\Tests\block\Unit

Code

public function testCalculateDependencies() {
  $values = array(
    'theme' => 'stark',
  );

  // Mock the entity under test so that we can mock getPluginCollections().
  $entity = $this
    ->getMockBuilder('\\Drupal\\block\\Entity\\Block')
    ->setConstructorArgs(array(
    $values,
    $this->entityTypeId,
  ))
    ->setMethods(array(
    'getPluginCollections',
  ))
    ->getMock();

  // Create a configurable plugin that would add a dependency.
  $instance_id = $this
    ->randomMachineName();
  $instance = new TestConfigurablePlugin(array(), $instance_id, array(
    'provider' => 'test',
  ));

  // Create a plugin collection to contain the instance.
  $plugin_collection = $this
    ->getMockBuilder('\\Drupal\\Core\\Plugin\\DefaultLazyPluginCollection')
    ->disableOriginalConstructor()
    ->setMethods(array(
    'get',
  ))
    ->getMock();
  $plugin_collection
    ->expects($this
    ->atLeastOnce())
    ->method('get')
    ->with($instance_id)
    ->will($this
    ->returnValue($instance));
  $plugin_collection
    ->addInstanceId($instance_id);

  // Return the mocked plugin collection.
  $entity
    ->expects($this
    ->once())
    ->method('getPluginCollections')
    ->will($this
    ->returnValue(array(
    $plugin_collection,
  )));
  $dependencies = $entity
    ->calculateDependencies()
    ->getDependencies();
  $this
    ->assertContains('test', $dependencies['module']);
  $this
    ->assertContains('stark', $dependencies['theme']);
}