Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Block / MultipleBlockFormTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Block;
4
5 use Drupal\block_test\PluginForm\EmptyBlockForm;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests that blocks can have multiple forms.
10  *
11  * @group block
12  */
13 class MultipleBlockFormTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['system', 'block', 'block_test'];
19
20   /**
21    * Tests that blocks can have multiple forms.
22    */
23   public function testMultipleForms() {
24     $configuration = ['label' => 'A very cool block'];
25     $block = \Drupal::service('plugin.manager.block')->createInstance('test_multiple_forms_block', $configuration);
26
27     $form_object1 = \Drupal::service('plugin_form.factory')->createInstance($block, 'configure');
28     $form_object2 = \Drupal::service('plugin_form.factory')->createInstance($block, 'secondary');
29
30     // Assert that the block itself is used for the default form.
31     $this->assertSame($block, $form_object1);
32
33     // Ensure that EmptyBlockForm is used and the plugin is set.
34     $this->assertInstanceOf(EmptyBlockForm::class, $form_object2);
35     $this->assertAttributeEquals($block, 'plugin', $form_object2);
36   }
37
38 }