BlockConfigEntityUnitTest.php in Drupal 8
File
core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php
View source
<?php
namespace Drupal\Tests\block\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin;
use Drupal\Tests\UnitTestCase;
class BlockConfigEntityUnitTest extends UnitTestCase {
protected $entityType;
protected $entityTypeManager;
protected $entityTypeId;
protected $uuid;
protected $moduleHandler;
protected $themeHandler;
protected function setUp() {
$this->entityTypeId = $this
->randomMachineName();
$this->entityType = $this
->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('block'));
$this->entityTypeManager = $this
->createMock(EntityTypeManagerInterface::class);
$this->entityTypeManager
->expects($this
->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this
->returnValue($this->entityType));
$this->uuid = $this
->createMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$this->moduleHandler = $this
->prophesize(ModuleHandlerInterface::class);
$this->themeHandler = $this
->prophesize(ThemeHandlerInterface::class);
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $this->entityTypeManager);
$container
->set('module_handler', $this->moduleHandler
->reveal());
$container
->set('theme_handler', $this->themeHandler
->reveal());
$container
->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
public function testCalculateDependencies() {
$this->themeHandler
->themeExists('stark')
->willReturn(TRUE);
$values = [
'theme' => 'stark',
];
$entity = $this
->getMockBuilder('\\Drupal\\block\\Entity\\Block')
->setConstructorArgs([
$values,
$this->entityTypeId,
])
->setMethods([
'getPluginCollections',
])
->getMock();
$instance_id = $this
->randomMachineName();
$this->moduleHandler
->moduleExists('test')
->willReturn(TRUE);
$instance = new TestConfigurablePlugin([], $instance_id, [
'provider' => 'test',
]);
$plugin_collection = $this
->getMockBuilder('\\Drupal\\Core\\Plugin\\DefaultLazyPluginCollection')
->disableOriginalConstructor()
->setMethods([
'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([
$plugin_collection,
]));
$dependencies = $entity
->calculateDependencies()
->getDependencies();
$this
->assertContains('test', $dependencies['module']);
$this
->assertContains('stark', $dependencies['theme']);
}
}