You are here

public function AdvancedPluginSelectorBaseTest::testbuildMultipleAvailablePlugins in Plugin 8.2

@covers ::buildMultipleAvailablePlugins

File

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

Class

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

Namespace

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

Code

public function testbuildMultipleAvailablePlugins() {
  $plugin = $this
    ->createMock(PluginInspectionInterface::class);
  $element = [
    '#available_plugins' => [
      $plugin,
    ],
  ];
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $form = [];
  $plugin_form = [
    '#type' => $this
      ->randomMachineName(),
  ];
  $selector = [
    '#type' => $this
      ->randomMachineName(),
  ];

  /** @var \Drupal\plugin\Plugin\Plugin\PluginSelector\AdvancedPluginSelectorBase|\PHPUnit_Framework_MockObject_MockObject $plugin_selector */
  $plugin_selector = $this
    ->getMockBuilder(AdvancedPluginSelectorBase::class)
    ->setMethods([
    'buildPluginForm',
    'buildSelector',
  ])
    ->setConstructorArgs([
    [],
    $this->pluginId,
    $this->pluginDefinition,
    $this->defaultPluginResolver,
    $this->stringTranslation,
  ])
    ->getMockForAbstractClass();
  $plugin_selector
    ->setSelectablePluginType($this->selectablePluginType);
  $plugin_selector
    ->expects($this
    ->once())
    ->method('buildPluginForm')
    ->with($form_state)
    ->willReturn($plugin_form);
  $plugin_selector
    ->expects($this
    ->once())
    ->method('buildSelector')
    ->with($element, $form_state, [
    $plugin,
  ])
    ->willReturn($selector);
  $plugin_selector
    ->setSelectedPlugin($plugin);
  $expected_build = [
    '#available_plugins' => [
      $plugin,
    ],
    'select' => $selector,
    'plugin_form' => $plugin_form,
  ];
  $this
    ->assertEquals($expected_build, $plugin_selector
    ->buildMultipleAvailablePlugins($element, $form_state, $form));
}