public function SectionFormAlterTest::testFormAlter in Block Style Plugins 8.2
Tests the formAlter() method.
See also
::formAlter()
File
- tests/
src/ Unit/ SectionFormAlterTest.php, line 129
Class
- SectionFormAlterTest
- @coversDefaultClass \Drupal\block_style_plugins\SectionFormAlter @group block_style_plugins
Namespace
Drupal\Tests\block_style_plugins\UnitCode
public function testFormAlter() {
$this->section
->getThirdPartySetting('block_style_plugins', 'block_style_plugins', [])
->willReturn([
'test_style' => TRUE,
]);
$sectionStorage = $this
->prophesize(SectionStorageInterface::class);
$sectionStorage
->getSections()
->willReturn([
$this->section
->reveal(),
]);
$sectionForm = $this
->prophesize(ConfigureSectionForm::class);
$sectionForm
->getSectionStorage()
->willReturn($sectionStorage
->reveal());
$this->formState
->getFormObject()
->willReturn($sectionForm
->reveal());
$this->formState
->getBuildInfo()
->willReturn([
'args' => [
1 => 0,
],
]);
$form = [
'#attributes' => [
'data-layout-builder-target-highlight-id' => 'section-update-1',
],
];
$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\\SectionFormAlter', $form['#validate'][0][0]);
$this
->assertEquals('validateForm', $form['#validate'][0][1]);
$this
->assertInstanceOf('Drupal\\block_style_plugins\\SectionFormAlter', $form['#submit'][0][0]);
$this
->assertEquals('submitForm', $form['#submit'][0][1]);
}