BlockConfigEntityUnitTest.php in Zircon Profile 8.0
File
core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php
View source
<?php
namespace Drupal\Tests\block\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin;
use Drupal\Tests\UnitTestCase;
class BlockConfigEntityUnitTest extends UnitTestCase {
protected $entityType;
protected $entityManager;
protected $entityTypeId;
protected $uuid;
protected function setUp() {
$this->entityTypeId = $this
->randomMachineName();
$this->entityType = $this
->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('block'));
$this->entityManager = $this
->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->entityManager
->expects($this
->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this
->returnValue($this->entityType));
$this->uuid = $this
->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$container = new ContainerBuilder();
$container
->set('entity.manager', $this->entityManager);
$container
->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
public function testCalculateDependencies() {
$values = array(
'theme' => 'stark',
);
$entity = $this
->getMockBuilder('\\Drupal\\block\\Entity\\Block')
->setConstructorArgs(array(
$values,
$this->entityTypeId,
))
->setMethods(array(
'getPluginCollections',
))
->getMock();
$instance_id = $this
->randomMachineName();
$instance = new TestConfigurablePlugin(array(), $instance_id, array(
'provider' => 'test',
));
$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);
$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']);
}
}