Pull merge.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Plugin / PluginWithFormsTraitTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Plugin;
4
5 use Drupal\Component\Plugin\PluginBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Plugin\PluginFormInterface;
8 use Drupal\Core\Plugin\PluginWithFormsInterface;
9 use Drupal\Core\Plugin\PluginWithFormsTrait;
10 use Drupal\Tests\UnitTestCase;
11
12 /**
13  * @coversDefaultClass \Drupal\Core\Plugin\PluginWithFormsTrait
14  * @group Plugin
15  */
16 class PluginWithFormsTraitTest extends UnitTestCase {
17
18   /**
19    * @covers ::getFormClass
20    * @covers ::hasFormClass
21    * @dataProvider providerGetFormClass
22    */
23   public function testGetFormClass(PluginWithFormsInterface $block_plugin, $operation, $expected_class) {
24     $this->assertSame($expected_class, $block_plugin->getFormClass($operation));
25     $this->assertSame($expected_class !== NULL, $block_plugin->hasFormClass($operation));
26   }
27
28   /**
29    * @return array
30    */
31   public function providerGetFormClass() {
32     $block_plugin_without_forms = new TestClass([], 'block_plugin_without_forms', [
33       'provider' => 'block_test',
34     ]);
35     // A block plugin that has a form defined for the 'poke' operation.
36     $block_plugin_with_forms = new TestClass([], 'block_plugin_with_forms', [
37       'provider' => 'block_test',
38       'forms' => [
39         'poke' => static::class,
40       ],
41     ]);
42     return [
43       'block plugin without forms, "configure" operation' => [$block_plugin_without_forms, 'configure', TestClass::class],
44       'block plugin without forms, "tickle" operation'    => [$block_plugin_without_forms, 'tickle', NULL],
45       'block plugin withut forms, "poke" operation'       => [$block_plugin_without_forms, 'poke', NULL],
46       'block plugin with forms, "configure" operation' => [$block_plugin_with_forms, 'configure', TestClass::class],
47       'block plugin with forms, "tickle" operation'    => [$block_plugin_with_forms, 'tickle', NULL],
48       'block plugin with forms, "poke" operation'      => [$block_plugin_with_forms, 'poke', static::class],
49     ];
50   }
51
52 }
53
54 class TestClass extends PluginBase implements PluginWithFormsInterface, PluginFormInterface {
55   use PluginWithFormsTrait;
56
57   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
58     return [];
59   }
60
61   public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
62   }
63
64   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
65   }
66
67 }