public function DazzlerTest::providerPreRenderForm in Formdazzle! 2.x
Data provider for testPreRenderForm().
See also
testPreRenderForm()
File
- tests/
src/ Unit/ DazzlerTest.php, line 243
Class
- DazzlerTest
- @coversDefaultClass \Drupal\formdazzle\Dazzler @group formdazzle
Namespace
Drupal\Tests\formdazzle\UnitCode
public function providerPreRenderForm() {
$data = [];
// Basic test.
$form = [
'#form_id' => 'a_form_id',
'#theme' => [
'a_form_id',
],
] + $this
->getFixture('with_child');
Dazzler::formAlter($form, 'a_form_id');
$expected = $form;
$expected['#theme_wrappers'] = [
'form__a_form_id',
];
$expected['child'] = [
'#type' => 'with_theme_and_wrappers',
'#theme' => 'with_theme__a_form_id',
'#theme_wrappers' => [
'with_theme_wrapper__a_form_id',
],
];
$expected['#markup'] = $this
->getTwigDebugComment([
'a-form-id.html.twig',
]);
unset($expected['#formdazzle']);
$data['adds suggestions to the entire form'] = [
$form,
$expected,
];
// Node edit form.
$form = $this
->getFixture('node_article_edit_form');
Dazzler::formAlter($form, 'node_article_edit_form');
$expected = $form + [
'#theme_wrappers' => [
'form__node_article_edit_form',
],
'#markup' => $this
->getTwigDebugComment([
'node-article-edit-form.html.twig',
'node-form.html.twig',
]),
];
unset($expected['#formdazzle']);
$data['no form__FORMID suggestions (issue #3180152)'] = [
$form,
$expected,
];
// Form with #theme as string.
$form = $this
->getFixture('node_article_edit_form');
$form['#theme'] = 'node_form__article__edit';
Dazzler::formAlter($form, 'node_article_edit_form');
$expected = $form + [
'#theme_wrappers' => [
'form__node_article_edit_form',
],
'#markup' => $this
->getTwigDebugComment([
'node-form--article--edit.html.twig',
'node-form--article.html.twig',
'node-form.html.twig',
]),
];
unset($expected['#formdazzle']);
$data['#theme is a string with suggestions'] = [
$form,
$expected,
];
// Form that has not had Dazzler::formAlter() run on it.
$form = $this
->getFixture('with_child');
$data['does not alter forms lacking #formdazzle data'] = [
$form,
$form,
];
// Form that has incorrect #formdazzle data in it.
$form = $this
->getFixture('with_child') + [
'#formdazzle' => [
'not_form_id' => TRUE,
],
];
$data['does not alter forms with wrong #formdazzle data'] = [
$form,
$form,
];
return $data;
}