Chris@0: entityTypeId = $this->randomMachineName(); Chris@0: Chris@0: $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); Chris@0: $this->entityType->expects($this->any()) Chris@0: ->method('getProvider') Chris@0: ->will($this->returnValue('block')); Chris@0: Chris@0: $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); Chris@0: $this->entityManager->expects($this->any()) Chris@0: ->method('getDefinition') Chris@0: ->with($this->entityTypeId) Chris@0: ->will($this->returnValue($this->entityType)); Chris@0: Chris@0: $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); Chris@0: Chris@0: $container = new ContainerBuilder(); Chris@0: $container->set('entity.manager', $this->entityManager); Chris@0: $container->set('uuid', $this->uuid); Chris@0: \Drupal::setContainer($container); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @covers ::calculateDependencies Chris@0: */ Chris@0: public function testCalculateDependencies() { Chris@0: $values = ['theme' => 'stark']; Chris@0: // Mock the entity under test so that we can mock getPluginCollections(). Chris@0: $entity = $this->getMockBuilder('\Drupal\block\Entity\Block') Chris@0: ->setConstructorArgs([$values, $this->entityTypeId]) Chris@0: ->setMethods(['getPluginCollections']) Chris@0: ->getMock(); Chris@0: // Create a configurable plugin that would add a dependency. Chris@0: $instance_id = $this->randomMachineName(); Chris@0: $instance = new TestConfigurablePlugin([], $instance_id, ['provider' => 'test']); Chris@0: Chris@0: // Create a plugin collection to contain the instance. Chris@0: $plugin_collection = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultLazyPluginCollection') Chris@0: ->disableOriginalConstructor() Chris@0: ->setMethods(['get']) Chris@0: ->getMock(); Chris@0: $plugin_collection->expects($this->atLeastOnce()) Chris@0: ->method('get') Chris@0: ->with($instance_id) Chris@0: ->will($this->returnValue($instance)); Chris@0: $plugin_collection->addInstanceId($instance_id); Chris@0: Chris@0: // Return the mocked plugin collection. Chris@0: $entity->expects($this->once()) Chris@0: ->method('getPluginCollections') Chris@0: ->will($this->returnValue([$plugin_collection])); Chris@0: Chris@0: $dependencies = $entity->calculateDependencies()->getDependencies(); Chris@0: $this->assertContains('test', $dependencies['module']); Chris@0: $this->assertContains('stark', $dependencies['theme']); Chris@0: } Chris@0: Chris@0: }