diff --git a/core/modules/block/tests/src/Kernel/BlockMachineNameTest.php b/core/modules/block/tests/src/Kernel/BlockMachineNameTest.php index 7522724..dd55d25 100644 --- a/core/modules/block/tests/src/Kernel/BlockMachineNameTest.php +++ b/core/modules/block/tests/src/Kernel/BlockMachineNameTest.php @@ -5,6 +5,7 @@ use Drupal\block_content\Entity\BlockContent; use Drupal\block_content\Entity\BlockContentType; +use Drupal\block_content\Plugin\Block\BlockContentBlock; use Drupal\Component\Plugin\PluginBase; use Drupal\Component\Utility\Unicode; use Drupal\Core\Language\LanguageInterface; @@ -22,14 +23,16 @@ class BlockMachineNameTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['block', 'block_content', 'system']; + public static $modules = ['block', 'block_content', 'system', 'user']; /** * {@inheritdoc} */ public function setUp() { parent::setUp(); + $this->installSchema('system', ['sequence']); $this->installEntitySchema('block_content'); + $this->installEntitySchema('user'); } /** @@ -50,22 +53,21 @@ public function testMachineNamesShouldNotCollideIfBlockTitlesContainPeriod() { ]); $block_content->save(); - // Generate an ID like - // \Drupal\Core\Block\BlockBase::getMachineNameSuggestion does. - $id = $this->container->get('transliteration')->transliterate($block_content->label(), LanguageInterface::LANGCODE_DEFAULT, '_'); - $id = Unicode::strtolower($id); - $id = preg_replace('@[^a-z0-9_.]+@', '', $id); + // Use \Drupal\Core\Block\BlockBase::getMachineNameSuggestion to generate + // an ID. + $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); + $block_plugin = $this->container->get('plugin.manager.block')->createInstance($plugin_id, []); + $method = new \ReflectionMethod($block_plugin, 'getMachineNameSuggestion'); + $method->setAccessible(TRUE); + $id = $method->invoke($block_plugin); // Now place the block content entity. - $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); $block = $this->placeBlock($plugin_id, [ 'label' => 'This. is whizzy', 'id' => $id, ]); $theme = $this->container->get('config.factory')->get('system.theme')->get('default'); - /** @var \Drupal\Core\Entity\EntityFormBuilderInterface $form_builder */ - $form_builder = $this->container->get('entity.form_builder'); // Create a new entity. /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */