You are here

public function AdvancedPluginSelectorBaseTest::testBuildSelectorFormWithOneAvailablePlugin in Plugin 8.2

@covers ::buildSelectorForm @covers ::setPluginSelector

File

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

Class

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

Namespace

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

Code

public function testBuildSelectorFormWithOneAvailablePlugin() {
  $form = [];
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $plugin_id = $this
    ->randomMachineName();
  $plugin = $this
    ->createMock(PluginInspectionInterface::class);
  $plugin_definitions = [
    $plugin_id => [
      'id' => $plugin_id,
    ],
  ];
  $this->selectablePluginManager
    ->expects($this
    ->any())
    ->method('createInstance')
    ->with($plugin_id)
    ->willReturn($plugin);
  $this->selectablePluginManager
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->willReturn($plugin_definitions);
  $build = $this->sut
    ->buildSelectorForm($form, $form_state);
  unset($build['container']['#plugin_selector_form_state_key']);
  $expected_build = [
    '#cache' => [
      'contexts' => [],
      'tags' => [],
      'max-age' => 0,
    ],
    'container' => [
      '#attributes' => [
        'class' => [
          'plugin-selector-' . Html::getId($this->pluginId),
        ],
      ],
      '#available_plugins' => [
        $plugin,
      ],
      '#process' => [
        [
          AdvancedPluginSelectorBase::class,
          'processBuildSelectorForm',
        ],
      ],
      '#tree' => TRUE,
      '#type' => 'container',
    ],
  ];
  $this
    ->assertSame($expected_build, $build);
}