public function BlockFormAlterTest::testFormAlter in Block Style Plugins 8.2
Tests the formAlter() method.
See also
::formAlter()
File
- tests/
src/ Unit/ BlockFormAlterTest.php, line 148
Class
- BlockFormAlterTest
- @coversDefaultClass \Drupal\block_style_plugins\BlockFormAlter @group block_style_plugins
Namespace
Drupal\Tests\block_style_plugins\UnitCode
public function testFormAlter() {
$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 = [];
$this->classInstance
->alterForm($form, $this->formState
->reveal());
// Check that a block_styles array is set.
$this
->assertArrayHasKey('block_styles', $form);
// Check that styles were set.
$styles = $this->plugin
->getConfiguration();
$expected_styles = [
'sample_class' => '',
'sample_checkbox' => '',
'test_style' => TRUE,
];
$this
->assertEquals($expected_styles, $styles);
// Check third party settings.
$expected_third_party_settings['block_style_plugins']['block_style_plugins'] = [
'#type' => 'container',
'#group' => 'block_styles',
];
$this
->assertEquals($expected_third_party_settings, $form['third_party_settings']);
// Check that validation and submit callbacks are set.
$this
->assertInstanceOf('Drupal\\block_style_plugins\\BlockFormAlter', $form['#validate'][0][0]);
$this
->assertEquals('validateForm', $form['#validate'][0][1]);
$this
->assertInstanceOf('Drupal\\block_style_plugins\\BlockFormAlter', $form['#submit'][0][0]);
$this
->assertEquals('submitForm', $form['#submit'][0][1]);
}