function ConfigImporterMissingContentTest::testMissingBlockContent

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Config/ConfigImporterMissingContentTest.php \Drupal\KernelTests\Core\Config\ConfigImporterMissingContentTest::testMissingBlockContent()

Tests the missing content, config import and the block plugin manager.

See also

\Drupal\Core\Config\ConfigImporter::processMissingContent()

\Drupal\config_import_test\EventSubscriber

File

core/tests/Drupal/KernelTests/Core/Config/ConfigImporterMissingContentTest.php, line 144

Class

ConfigImporterMissingContentTest
Tests importing configuration which has missing content dependencies.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testMissingBlockContent() : void {
    $this->enableModules([
        'block',
        'block_content',
        'field',
        'text',
    ]);
    $this->container
        ->get('theme_installer')
        ->install([
        'stark',
    ]);
    $this->installEntitySchema('block_content');
    $this->installConfig([
        'block_content',
    ]);
    // Create a block content type.
    $block_content_type = BlockContentType::create([
        'id' => 'test',
        'label' => 'Test block content',
        'description' => "Provides a block type",
    ]);
    $block_content_type->save();
    // And a block content entity.
    $block_content = BlockContent::create([
        'info' => 'Prototype',
        'type' => 'test',
        // Set the UUID to make asserting against missing test easy.
'uuid' => '6376f337-fcbf-4b28-b30e-ed5b6932e692',
    ]);
    $block_content->save();
    $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid();
    $block = $this->placeBlock($plugin_id);
    $storage = $this->container
        ->get('config.storage');
    $sync = $this->container
        ->get('config.storage.sync');
    $this->copyConfig($storage, $sync);
    $block->delete();
    $block_content->delete();
    $block_content_type->delete();
    // Import.
    $this->logMessages = [];
    $config_importer = $this->configImporter();
    $config_importer->import();
    $this->assertNotContains('The "block_content:6376f337-fcbf-4b28-b30e-ed5b6932e692" block plugin was not found', $this->logMessages);
    // Ensure the expected message is generated when creating an instance of the
    // block.
    $instance = $this->container
        ->get('plugin.manager.block')
        ->createInstance($plugin_id);
    $this->assertContains('The "block_content:6376f337-fcbf-4b28-b30e-ed5b6932e692" block plugin was not found', $this->logMessages);
    $this->assertInstanceOf(Broken::class, $instance);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.