You are here

public function BlockStyleBaseTest::testPrepareForm in Block Style Plugins 8

Tests the prepareForm() method.

See also

::prepareForm()

File

tests/src/Unit/Plugin/BlockStyleBaseTest.php, line 124

Class

BlockStyleBaseTest
@coversDefaultClass \Drupal\block_style_plugins\Plugin\BlockStyleBase @group block_style_plugins

Namespace

Drupal\Tests\block_style_plugins\Unit\Plugin

Code

public function testPrepareForm() {
  $block = $this
    ->prophesize(Block::CLASS);
  $block
    ->getPlugin()
    ->willReturn($this->blockPlugin
    ->reveal());
  $block
    ->getThirdPartySetting('block_style_plugins', 'block_style_plugins')
    ->willReturn([
    'test_style' => TRUE,
  ]);
  $blockForm = $this
    ->prophesize(BlockForm::CLASS);
  $blockForm
    ->getEntity()
    ->willReturn($block
    ->reveal());
  $this->formState
    ->getFormObject()
    ->willReturn($blockForm
    ->reveal());
  $form = [];
  $form['actions']['submit']['#submit'] = [];
  $return = $this->plugin
    ->prepareForm($form, $this->formState
    ->reveal());

  // Check the callback function attached.
  $return_callback = $return['actions']['submit']['#submit'][0];
  $this
    ->assertInstanceOf('Drupal\\block_style_plugins\\Plugin\\BlockStyleBase', $return_callback[0]);
  $this
    ->assertEquals('submitForm', $return_callback[1]);

  // Check that a block_styles array is set.
  $this
    ->assertArrayHasKey('block_styles', $return);

  // Check that styles were set.
  $styles = $this->plugin
    ->getConfiguration();
  $expected_styles = [
    'sample_class' => '',
    'sample_checkbox' => '',
    'test_style' => TRUE,
  ];
  $this
    ->assertArrayEquals($expected_styles, $styles);

  // Check third party settings.
  $expected_third_party_settings['block_style_plugins']['block_style_plugins'] = [
    '#type' => 'container',
    '#group' => 'block_styles',
  ];
  $this
    ->assertArrayEquals($expected_third_party_settings, $return['third_party_settings']);
}