You are here

public function AdvancedPluginSelectorBaseTest::testBuildOneAvailablePlugin in Plugin 8.2

@covers ::buildOneAvailablePlugin

File

tests/src/Unit/Plugin/Plugin/PluginSelector/AdvancedPluginSelectorBaseTest.php, line 503

Class

AdvancedPluginSelectorBaseTest
@coversDefaultClass \Drupal\plugin\Plugin\Plugin\PluginSelector\AdvancedPluginSelectorBase

Namespace

Drupal\Tests\plugin\Unit\Plugin\Plugin\PluginSelector

Code

public function testBuildOneAvailablePlugin() {
  $plugin_id = $this
    ->randomMachineName();
  $plugin_form = [
    '#type' => $this
      ->randomMachineName(),
  ];
  $plugin = $this
    ->getMockForAbstractClass(AdvancedPluginSelectorBaseUnitTestPluginFormPluginInterface::class);
  $plugin
    ->expects($this
    ->atLeastOnce())
    ->method('getPluginId')
    ->willReturn($plugin_id);
  $plugin
    ->expects($this
    ->once())
    ->method('buildConfigurationForm')
    ->willReturn($plugin_form);
  $element = [
    '#available_plugins' => [
      $plugin,
    ],
  ];
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $form = [];
  $label = $this
    ->randomMachineName();
  $this->sut
    ->setLabel($label);
  $expected_build = [
    '#available_plugins' => [
      $plugin,
    ],
    'select' => [
      'message' => [
        '#title' => $label,
        '#type' => 'item',
      ],
      'container' => [
        '#type' => 'container',
        'plugin_id' => [
          '#type' => 'value',
          '#value' => $plugin_id,
        ],
      ],
    ],
    'plugin_form' => [
      '#attributes' => [
        'class' => [
          'plugin-selector-' . Html::getId($this->pluginId) . '-plugin-form',
        ],
      ],
      '#type' => 'container',
    ] + $plugin_form,
  ];
  $build = $this->sut
    ->buildOneAvailablePlugin($element, $form_state, $form);
  unset($build['plugin_form']['#id']);
  $this
    ->assertSame($expected_build, $build);
}