protected function BlockFormAlterTest::setUp in Block Style Plugins 8.2
Create the setup for constants and configFactory stub.
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ BlockFormAlterTest.php, line 76
Class
- BlockFormAlterTest
- @coversDefaultClass \Drupal\block_style_plugins\BlockFormAlter @group block_style_plugins
Namespace
Drupal\Tests\block_style_plugins\UnitCode
protected function setUp() : void {
parent::setUp();
// Stub the Entity Repository Service.
$this->entityRepository = $this
->prophesize(EntityRepositoryInterface::class);
// Stub the Entity Type Manager.
$this->entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
// Form state double.
$this->formState = $this
->prophesize(FormStateInterface::class);
// Block plugin.
$this->blockPlugin = $this
->prophesize(BlockPluginInterface::class);
$this->blockPlugin
->getBaseId()
->willReturn('block_content');
$this->blockPlugin
->getDerivativeId()
->willReturn('uuid-1234');
$this->blockPlugin
->getPluginId()
->willReturn('basic_block');
$configuration = [];
$plugin_id = 'block_style_plugins';
$plugin_definition['provider'] = 'block_style_plugins';
$this->plugin = new MockBlockStyleBase($configuration, $plugin_id, $plugin_definition, $this->entityTypeManager
->reveal());
// Stub the Block Style Manager service.
$this->blockStyleManager = $this
->prophesize(BlockStyleManager::class);
$this->blockStyleManager
->getBlockDefinitions()
->willReturn([
$plugin_id => $plugin_definition,
]);
$this->blockStyleManager
->createInstance('block_style_plugins')
->willReturn($this->plugin);
$this->classInstance = new BlockFormAlter($this->blockStyleManager
->reveal());
// Use reflection to alter the protected entityRepository property.
$reflectionObject = new \ReflectionObject($this->classInstance);
$property = $reflectionObject
->getProperty('entityRepository');
$property
->setAccessible(TRUE);
$property
->setValue($this->classInstance, $this->entityRepository
->reveal());
// Create a translation stub for the t() method.
$translator = $this
->getStringTranslationStub();
$this->classInstance
->setStringTranslation($translator);
}