From f145ae7f88e8ae9f723fcb5ca9c899745a0063a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 30 Dec 2015 16:57:16 +0100 Subject: [PATCH] re-introduce post_text extension in fields.html.twig + tests --- Resources/views/Form/fields.html.twig | 24 ++++++++ .../PostTextIntegerExtensionTest.php | 58 +++++++++++++++++++ .../Extension/PostTextNumberExtensionTest.php | 58 +++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 Tests/Form/Extension/PostTextIntegerExtensionTest.php create mode 100644 Tests/Form/Extension/PostTextNumberExtensionTest.php diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index 990f9719f..56f5b8733 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -80,5 +80,29 @@ {% endblock cf_choices_row %} +{# extend the number type to add post_text extension #} +{% block number_widget %} +{%- if post_text is defined and post_text is not empty-%} +
+{%- endif -%} +{{ block('form_widget') }} +{%- if post_text is defined and post_text is not empty-%} +{{ post_text }} +
+{%- endif -%} +{% endblock %} + +{# extend the number type to add post_text extension #} +{% block integer_widget %} +{%- if post_text is defined and post_text is not empty-%} +
+{%- endif -%} +{{ block('form_widget') }} +{%- if post_text is defined and post_text is not empty-%} +{{ post_text }} +
+{%- endif -%} +{% endblock %} + {# The choice_with_other_widget widget is defined in the main bundle #} diff --git a/Tests/Form/Extension/PostTextIntegerExtensionTest.php b/Tests/Form/Extension/PostTextIntegerExtensionTest.php new file mode 100644 index 000000000..08664735a --- /dev/null +++ b/Tests/Form/Extension/PostTextIntegerExtensionTest.php @@ -0,0 +1,58 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\CustomFields\Tests\Form\Extension; + +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; + +/** + * Test the post-text extension + * + * @author Julien Fastré + */ +class PostTextIntegerExtensionTest extends KernelTestCase +{ + /** + * + * @var \Symfony\Component\Form\FormBuilderInterface + */ + private $formBuilder; + + public function setUp() + { + self::bootKernel(); + + $container = self::$kernel->getContainer(); + + $this->formBuilder = $container->get('form.factory') + ->createBuilder('form', null); + } + + public function testCreateView() + { + $form = $this->formBuilder->add('test', 'integer', array( + 'post_text' => 'my text' + ))->getForm(); + + $view = $form->createView(); + + $this->assertEquals('my text', $view['test']->vars['post_text']); + } + +} diff --git a/Tests/Form/Extension/PostTextNumberExtensionTest.php b/Tests/Form/Extension/PostTextNumberExtensionTest.php new file mode 100644 index 000000000..4348445d9 --- /dev/null +++ b/Tests/Form/Extension/PostTextNumberExtensionTest.php @@ -0,0 +1,58 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\CustomFields\Tests\Form\Extension; + +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; + +/** + * Test the post-text extension + * + * @author Julien Fastré + */ +class PostTextNumberExtensionTest extends KernelTestCase +{ + /** + * + * @var \Symfony\Component\Form\FormBuilderInterface + */ + private $formBuilder; + + public function setUp() + { + self::bootKernel(); + + $container = self::$kernel->getContainer(); + + $this->formBuilder = $container->get('form.factory') + ->createBuilder('form', null); + } + + public function testCreateView() + { + $form = $this->formBuilder->add('test', 'number', array( + 'post_text' => 'my text' + ))->getForm(); + + $view = $form->createView(); + + $this->assertEquals('my text', $view['test']->vars['post_text']); + } + +}