3 namespace Drupal\Tests\Core\Plugin;
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;
13 * @coversDefaultClass \Drupal\Core\Plugin\PluginWithFormsTrait
16 class PluginWithFormsTraitTest extends UnitTestCase {
19 * @covers ::getFormClass
20 * @covers ::hasFormClass
21 * @dataProvider providerGetFormClass
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));
31 public function providerGetFormClass() {
32 $block_plugin_without_forms = new TestClass([], 'block_plugin_without_forms', [
33 'provider' => 'block_test',
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',
39 'poke' => static::class,
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],
54 class TestClass extends PluginBase implements PluginWithFormsInterface, PluginFormInterface {
55 use PluginWithFormsTrait;
57 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
61 public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
64 public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {