function MultipleBlockFormTest::testMultipleForms

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php \Drupal\KernelTests\Core\Block\MultipleBlockFormTest::testMultipleForms()
  2. 10 core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php \Drupal\KernelTests\Core\Block\MultipleBlockFormTest::testMultipleForms()
  3. 11.x core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php \Drupal\KernelTests\Core\Block\MultipleBlockFormTest::testMultipleForms()

Tests that blocks can have multiple forms.

File

core/tests/Drupal/KernelTests/Core/Block/MultipleBlockFormTest.php, line 23

Class

MultipleBlockFormTest
Tests that blocks can have multiple forms.

Namespace

Drupal\KernelTests\Core\Block

Code

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->assertAttributeEquals($block, 'plugin', $form_object2);
}

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