class BlockConfigEntityUnitTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php \Drupal\Tests\block\Unit\BlockConfigEntityUnitTest
@coversDefaultClass \Drupal\block\Entity\Block @group block
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\block\Unit\BlockConfigEntityUnitTest
Expanded class hierarchy of BlockConfigEntityUnitTest
File
- core/
modules/ block/ tests/ src/ Unit/ BlockConfigEntityUnitTest.php, line 16
Namespace
Drupal\Tests\block\UnitView source
class BlockConfigEntityUnitTest extends UnitTestCase {
/**
* The entity type used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityType;
/**
* The entity type manager used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
*
* @var string
*/
protected $entityTypeId;
/**
* The UUID generator used for testing.
*
* @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $uuid;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $moduleHandler;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $themeHandler;
/**
* {@inheritdoc}
*/
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);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
$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,
])
->setMethods([
'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()
->setMethods([
'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([
$plugin_collection,
]));
$dependencies = $entity
->calculateDependencies()
->getDependencies();
$this
->assertContains('test', $dependencies['module']);
$this
->assertContains('stark', $dependencies['theme']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockConfigEntityUnitTest:: |
protected | property | The entity type used for testing. | |
BlockConfigEntityUnitTest:: |
protected | property | The ID of the type of the entity under test. | |
BlockConfigEntityUnitTest:: |
protected | property | The entity type manager used for testing. | |
BlockConfigEntityUnitTest:: |
protected | property | The module handler. | |
BlockConfigEntityUnitTest:: |
protected | property | The theme handler. | |
BlockConfigEntityUnitTest:: |
protected | property | The UUID generator used for testing. | |
BlockConfigEntityUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
BlockConfigEntityUnitTest:: |
public | function | @covers ::calculateDependencies | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |