class MultipleBlockFormTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php \Drupal\KernelTests\Core\Block\MultipleBlockFormTest
- 10 core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php \Drupal\KernelTests\Core\Block\MultipleBlockFormTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php \Drupal\KernelTests\Core\Block\MultipleBlockFormTest
Tests that blocks can have multiple forms.
@group block
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Block\MultipleBlockFormTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of MultipleBlockFormTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Block/ MultipleBlockFormTest.php, line 13
Namespace
Drupal\KernelTests\Core\BlockView source
class MultipleBlockFormTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'block',
'block_test',
];
/**
* Tests that blocks can have multiple forms.
*/
public function testMultipleForms() {
$configuration = [
'label' => 'A very cool block',
];
$block = \Drupal::service('plugin.manager.block')->createInstance('test_multiple_forms_block', $configuration);
$form_object1 = \Drupal::service('plugin_form.factory')->createInstance($block, 'configure');
$form_object2 = \Drupal::service('plugin_form.factory')->createInstance($block, 'secondary');
// Assert that the block itself is used for the default form.
$this->assertSame($block, $form_object1);
// Ensure that EmptyBlockForm is used and the plugin is set.
$this->assertInstanceOf(EmptyBlockForm::class, $form_object2);
$this->assertEquals($block, $form_object2->plugin);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.