function BlockContentDeriverTest::testGetDerivativeDefinitionsAdminLabels

Same name in other branches
  1. 11.x core/modules/block_content/tests/src/Kernel/BlockContentDeriverTest.php \Drupal\Tests\block_content\Kernel\BlockContentDeriverTest::testGetDerivativeDefinitionsAdminLabels()

Tests the admin labels of derivative definitions.

File

core/modules/block_content/tests/src/Kernel/BlockContentDeriverTest.php, line 100

Class

BlockContentDeriverTest
Tests block content plugin deriver.

Namespace

Drupal\Tests\block_content\Kernel

Code

public function testGetDerivativeDefinitionsAdminLabels() : void {
    $blockContentType = BlockContentType::create([
        'id' => 'basic',
        'label' => 'Basic Block',
    ]);
    $blockContentType->save();
    $blockContentWithLabel = BlockContent::create([
        'info' => 'Basic prototype',
        'type' => 'basic',
    ]);
    $blockContentWithLabel->save();
    $blockContentNoLabel = BlockContent::create([
        'type' => 'basic',
    ]);
    $blockContentNoLabel->save();
    $blockPluginManager = \Drupal::service('plugin.manager.block');
    $plugin = $blockPluginManager->createInstance('block_content:' . $blockContentWithLabel->uuid());
    $this->assertEquals('Basic prototype', $plugin->getPluginDefinition()['admin_label']);
    $plugin = $blockPluginManager->createInstance('block_content:' . $blockContentNoLabel->uuid());
    $this->assertEquals('Basic Block: ' . $blockContentNoLabel->id(), $plugin->getPluginDefinition()['admin_label']);
}

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