From cef6f6d4ea60945ba6ebd5dd5067277acaf3f40a Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 08:27:56 -0800 Subject: [PATCH 01/10] Require phpunit --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 123281096..294d72364 100644 --- a/composer.json +++ b/composer.json @@ -78,5 +78,8 @@ "branch-alias": { "dev-master": "2.3.x-dev" } + }, + "require-dev": { + "phpunit/phpunit": "~4.6" } } From e27177906bd84ea23cbecff73098a59764be2ed9 Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 09:50:59 -0800 Subject: [PATCH 02/10] Allow symfony 3.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 294d72364..21ad0f157 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "target-dir": "Mopa/Bundle/BootstrapBundle", "require": { - "symfony/symfony": "~2.3", + "symfony/symfony": "~2.3|~3.0", "mopa/composer-bridge": "1.3.*" }, "suggest": { From a95b512ca5155f263c73d50d12f2df52259e3d7a Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 09:51:20 -0800 Subject: [PATCH 03/10] Backport travis config from master --- .travis.yml | 59 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5604ce489..f015ddfaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,52 @@ language: php + +sudo: false + php: - 5.3 - 5.4 - 5.5 - 5.6 + - 7.0 + - hhvm env: - - SYMFONY_VERSION=v2.0.17 - - SYMFONY_VERSION=v2.1.13 - - SYMFONY_VERSION=v2.2.11 - - SYMFONY_VERSION=v2.3.42 - - SYMFONY_VERSION=v2.4.10 - - SYMFONY_VERSION=v2.5.12 - - SYMFONY_VERSION=v2.6.13 - - SYMFONY_VERSION=v2.7.14 - - SYMFONY_VERSION=v2.8.7 - - SYMFONY_VERSION=v3.0.7 - - SYMFONY_VERSION=v3.1.0 - - SYMFONY_VERSION=origin/master - -before_script: php Tests/tests/vendors.php -script: phpunit + - SYMFONY_VERSION=2.3.* + - SYMFONY_VERSION=2.4.* + - SYMFONY_VERSION=2.5.* + - SYMFONY_VERSION=2.6.* SYMFONY_DEPRECATIONS_HELPER=weak + - SYMFONY_VERSION=2.7.* + - SYMFONY_VERSION=2.8.* + - SYMFONY_VERSION=3.0.* + - SYMFONY_VERSION=3.1.* + - SYMFONY_VERSION=dev-master + +matrix: + exclude: + - php: 5.3 + env: SYMFONY_VERSION=3.0.* + - php: 5.3 + env: SYMFONY_VERSION=3.1.* + - php: 5.3 + env: SYMFONY_VERSION=dev-master + - php: 5.4 + env: SYMFONY_VERSION=3.0.* + - php: 5.4 + env: SYMFONY_VERSION=3.1.* + - php: 5.4 + env: SYMFONY_VERSION=dev-master + +cache: + directories: + - $HOME/.composer/cache + +before_script: + - composer selfupdate + - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; + - composer update --prefer-dist $COMPOSER_FLAGS + +script: + - vendor/bin/phpunit + +after_success: + - coveralls From 42cf1e0fabee7367a16ace8ee9eeb4ebf8e40ea1 Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 09:51:52 -0800 Subject: [PATCH 04/10] WIP test suite from 2.3 branch --- Tests/FileSystemLoader.php | 18 + Tests/Form/AbstractDivLayoutTest.php | 307 ++++++++++++++++++ Tests/Form/AddonLayoutTest.php | 112 +++++++ .../AddinfoFieldTypeExtensionTest.php | 11 - Tests/Form/LegendLayoutTest.php | 134 ++++++++ Tests/Form/SimpleDivLayoutTest.php | 27 ++ Tests/tests/autoload.php.dist | 25 -- Tests/tests/bootstrap.php | 16 - Tests/tests/vendors.php | 27 -- phpunit.xml.dist | 4 +- 10 files changed, 600 insertions(+), 81 deletions(-) create mode 100644 Tests/FileSystemLoader.php create mode 100644 Tests/Form/AbstractDivLayoutTest.php create mode 100644 Tests/Form/AddonLayoutTest.php delete mode 100644 Tests/Form/Extension/AddinfoFieldTypeExtensionTest.php create mode 100644 Tests/Form/LegendLayoutTest.php create mode 100644 Tests/Form/SimpleDivLayoutTest.php delete mode 100644 Tests/tests/autoload.php.dist delete mode 100644 Tests/tests/bootstrap.php delete mode 100644 Tests/tests/vendors.php diff --git a/Tests/FileSystemLoader.php b/Tests/FileSystemLoader.php new file mode 100644 index 000000000..06362ac7e --- /dev/null +++ b/Tests/FileSystemLoader.php @@ -0,0 +1,18 @@ + 1) { + $parsed[1] = $parts[1]; + } + + return $parsed; + } +} diff --git a/Tests/Form/AbstractDivLayoutTest.php b/Tests/Form/AbstractDivLayoutTest.php new file mode 100644 index 000000000..88357458d --- /dev/null +++ b/Tests/Form/AbstractDivLayoutTest.php @@ -0,0 +1,307 @@ + 'Symfony\Component\Form\Extension\Core\Type\FormType', + 'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType', + 'email' => 'Symfony\Component\Form\Extension\Core\Type\EmailType', + ); + + /** + * @throws \Twig_Error_Loader + */ + protected function setUp() + { + // Setup factory for tabs + $this->tabFactory = Forms::createFormFactory(); + + parent::setUp(); + + $rendererEngine = new TwigRendererEngine(array( + 'form_div_layout.html.twig', + 'fields.html.twig', + )); + + if (interface_exists('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')) { + $csrfProviderInterface = 'Symfony\Component\Security\Csrf\CsrfTokenManagerInterface'; + } else { + $csrfProviderInterface = 'Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'; + } + + $renderer = new TwigRenderer($rendererEngine, $this->getMock($csrfProviderInterface)); + + $this->extension = new FormExtension($renderer); + + $reflection = new \ReflectionClass($renderer); + $bridgeDirectory = dirname($reflection->getFileName()).'/../Resources/views/Form'; + + $loader = new FileSystemLoader(array( + $bridgeDirectory, + __DIR__.'/../../Resources/views/Form', + __DIR__.'/../../Resources/views', + )); + + $environment = new Twig_Environment($loader, array('strict_variables' => true)); + $environment->addExtension(new TranslationExtension(new StubTranslator())); + $environment->addExtension(new MopaBootstrapInitializrTwigExtension(array( + 'mopa_bootstrap.initializr.meta' => null, + 'mopa_bootstrap.initializr.dns_prefetch' => null, + 'mopa_bootstrap.initializr.google' => null, + 'mopa_bootstrap.initializr.diagnostic_mode' => false, + ))); + $environment->addExtension(new MopaBootstrapTwigExtension()); + $environment->addGlobal('global', ''); + $environment->addExtension($this->extension); + + $this->extension->initRuntime($environment); + } + + /** + * @return PreloadedExtension[] + */ + protected function getExtensions() + { + return array(new PreloadedExtension(array(), array( + $this->getFormType('form') => array( + $this->getHelpFormTypeExtension(), + $this->getWidgetFormTypeExtension(), + $this->getWidgetCollectionFormTypeExtension(), + $this->getLegendFormTypeExtension(), + $this->getErrorTypeFormTypeExtension(), + $this->getIconButtonExtension(), + ), + $this->getFormType('text') => array( + ), + ))); + } + + /** + * @return HelpFormTypeExtension + */ + protected function getHelpFormTypeExtension() + { + $popoverOptions = array( + 'title' => null, + 'content' => null, + 'text' => null, + 'trigger' => 'hover', + 'toggle' => 'popover', + 'icon' => 'info-sign', + 'placement' => 'right', + 'selector' => null, + ); + + $tooltipOptions = array( + 'title' => null, + 'text' => null, + 'icon' => 'info-sign', + 'placement' => 'top', + ); + + return new HelpFormTypeExtension(array( + 'help_inline' => null, + 'help_block' => null, + 'help_label' => null, + 'help_block_popover' => $popoverOptions, + 'help_label_popover' => $popoverOptions, + 'help_widget_popover' => $popoverOptions, + 'help_block_tooltip' => $tooltipOptions, + 'help_label_tooltip' => $tooltipOptions, + )); + } + + /** + * @return WidgetFormTypeExtension + */ + protected function getWidgetFormTypeExtension() + { + return new WidgetFormTypeExtension(array( + 'checkbox_label' => 'both', + )); + } + + /** + * @return WidgetFormTypeExtension + */ + protected function getWidgetCollectionFormTypeExtension() + { + return new WidgetCollectionFormTypeExtension(array( + 'render_collection_item' => null, + )); + } + + /** + * @return LegendFormTypeExtension + */ + protected function getLegendFormTypeExtension() + { + return new LegendFormTypeExtension(array( + 'render_fieldset' => true, + 'show_legend' => true, + 'show_child_legend' => false, + 'errors_on_forms' => false, + 'render_required_asterisk' => false, + 'render_optional_text' => true, + )); + } + + /** + * @return ErrorTypeFormTypeExtension + */ + protected function getErrorTypeFormTypeExtension() + { + return new ErrorTypeFormTypeExtension(array( + 'error_type' => null, + )); + } + + /** + * @return TabbedFormTypeExtension + */ + protected function getTabbedFormTypeExtension() + { + return new TabbedFormTypeExtension($this->tabFactory, array( + 'class' => 'tabs nav-tabs', + )); + } + + /** + * @return TabbedFormTypeExtension + */ + protected function getIconButtonExtension() + { + return new IconButtonExtension(array( + 'icon' => null, + 'icon_color' => null, + )); + } + + /** + * @param string $html + * @param string $expression + * @param int $count + */ + protected function assertMatchesXpath($html, $expression, $count = 1) + { + $dom = new \DomDocument('UTF-8'); + try { + // Wrap in node so we can load HTML with multiple tags at + // the top level + $dom->loadXml(''.$html.''); + } catch (\Exception $e) { + $this->fail(sprintf( + "Failed loading HTML:\n\n%s\n\nError: %s", + $html, + $e->getMessage() + )); + } + $xpath = new \DOMXPath($dom); + $nodeList = $xpath->evaluate('/root'.$expression); + if ($nodeList->length != $count) { + $dom->formatOutput = true; + $this->fail(sprintf( + "Failed asserting that \n\n%s\n\nmatches exactly %s. Matches %s in \n\n%s", + $expression, + $count == 1 ? 'once' : $count.' times', + $nodeList->length == 1 ? 'once' : $nodeList->length.' times', + // strip away and + substr($dom->saveHTML(), 6, -8) + )); + } + } + + /** + * @param string $html + * + * @return string + */ + protected function removeBreaks($html) + { + return str_replace(' ', '', $html); + } + + /** + * @param FormView $view + * @param array $vars + * + * @return string + */ + protected function renderForm(FormView $view, array $vars = array()) + { + return (string) $this->extension->renderer->renderBlock($view, 'form', $vars); + } + + /** + * @param FormView $view + * @param array $vars + * + * @return string + */ + protected function renderRow(FormView $view, array $vars = array()) + { + return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars); + } + + /** + * @param FormView $view + * @param array $vars + * + * @return string + */ + protected function renderWidget(FormView $view, array $vars = array()) + { + return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars); + } + + /** + * @param FormView $view + * @param string $label + * @param array $vars + * + * @return string + */ + protected function renderLabel(FormView $view, $label = null, array $vars = array()) + { + if ($label !== null) { + $vars += array('label' => $label); + } + + return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars); + } + + protected function getFormType($name) + { + if(method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) { + return $this->formTypeMap[$name]; + } + + return $name; + } +} diff --git a/Tests/Form/AddonLayoutTest.php b/Tests/Form/AddonLayoutTest.php new file mode 100644 index 000000000..16ca91378 --- /dev/null +++ b/Tests/Form/AddonLayoutTest.php @@ -0,0 +1,112 @@ +factory + ->createNamed('name', $this->getFormType('text'), null, array( + 'widget_addon' => array( + 'type' => 'prepend', + 'text' => 'foo', + ), + )) + ->createView() + ; + + $html = $this->renderWidget($view); + + $this->assertMatchesXpath($html, +' +/div[@class="input-prepend"] + [ + ./span[@class="add-on"][.="[trans]foo[/trans] "] + /following-sibling::input[@type="text"][@id="name"][@name="name"] + ] +' + ); + } + + public function testIconPrepend() + { + $view = $this->factory + ->createNamed('name', $this->getFormType('text'), null, array( + 'widget_addon' => array( + 'type' => 'prepend', + 'icon' => 'cog', + ), + )) + ->createView() + ; + + $html = $this->renderWidget($view); + + $this->assertMatchesXpath($html, +' +/div[@class="input-prepend"] + [ + ./span[@class="add-on"] + [ + ./i[@class="icon-cog"] + ] + /following-sibling::input[@type="text"][@id="name"][@name="name"] + ] +' + ); + } + + public function testTextAppend() + { + $view = $this->factory + ->createNamed('name', $this->getFormType('text'), null, array( + 'widget_addon' => array( + 'type' => 'append', + 'text' => 'foo', + ), + )) + ->createView() + ; + + $html = $this->renderWidget($view); + + $this->assertMatchesXpath($html, +' +/div[@class="input-append"] + [ + ./input[@type="text"][@id="name"][@name="name"] + /following-sibling::span[@class="add-on"][.="[trans]foo[/trans] "] + ] +' + ); + } + + public function testIconAppend() + { + $view = $this->factory + ->createNamed('name', $this->getFormType('text'), null, array( + 'widget_addon' => array( + 'type' => 'append', + 'icon' => 'cog', + ), + )) + ->createView() + ; + + $html = $this->renderWidget($view); + + $this->assertMatchesXpath($html, +' +/div[@class="input-append"] + [ + ./input[@type="text"][@id="name"][@name="name"] + /following-sibling::span[@class="add-on"] + [ + ./i[@class="icon-cog"] + ] + ] +' + ); + } +} diff --git a/Tests/Form/Extension/AddinfoFieldTypeExtensionTest.php b/Tests/Form/Extension/AddinfoFieldTypeExtensionTest.php deleted file mode 100644 index 43dc422bf..000000000 --- a/Tests/Form/Extension/AddinfoFieldTypeExtensionTest.php +++ /dev/null @@ -1,11 +0,0 @@ -assertTrue(True, 'Wow'); - } -} diff --git a/Tests/Form/LegendLayoutTest.php b/Tests/Form/LegendLayoutTest.php new file mode 100644 index 000000000..72814c330 --- /dev/null +++ b/Tests/Form/LegendLayoutTest.php @@ -0,0 +1,134 @@ +factory + ->createNamed('name', $this->getFormType('text'), null, array( + 'render_required_asterisk' => true, + )) + ->createView() + ; + $html = $this->renderLabel($view); + $this->assertMatchesXpath($this->removeBreaks($html), +' +/label[@for="name"][@class=" control-label required"] + [ + ./span[.="*"] + ] +' + ); + } + + public function testRenderFieldset() + { + $view = $this->factory->createNamedBuilder('name', $this->getFormType('form')) + ->add('field1', $this->getFormType('text')) + ->getForm() + ->createView() + ; + + $html = $this->renderForm($view); + + $this->assertMatchesXpath($html, +' +/form + [ + ./fieldset + [ + ./div[@class=" control-group"] + ] + ] +' + ); + } + + public function testNoRenderFieldset() + { + $view = $this->factory->createNamedBuilder('name', $this->getFormType('form'), null, array('render_fieldset' => false)) + ->add('field1', $this->getFormType('text')) + ->getForm() + ->createView() + ; + + $html = $this->renderForm($view); + + $this->assertMatchesXpath($html, +' +/form + [ + ./div[@class=" control-group"] + ] +' + ); + } + + public function testRenderLegend() + { + $view = $this->factory->createNamedBuilder('name', $this->getFormType('form')) + ->add('field1', $this->getFormType('text')) + ->getForm() + ->createView() + ; + + $html = $this->renderForm($view); + + $this->assertMatchesXpath($html, +' +/form + [ + ./fieldset + [ + ./legend[.="[trans]Name[/trans]"] + /following-sibling::div[@class=" control-group"] + ] + ] +' + ); + } + + public function testNoRenderLegend() + { + $view = $this->factory->createNamedBuilder('name', $this->getFormType('form'), null, array('show_legend' => false)) + ->add('field1', $this->getFormType('text')) + ->getForm() + ->createView() + ; + + $html = $this->renderForm($view); + + $this->assertMatchesXpath($html, +' +/form + [ + ./fieldset + [ + not(./legend) + ] + ] +' + ); + } + + public function testLabelRender() + { + $view = $this->factory + ->createNamed('name', $this->getFormType('text'), null, array( + 'label_render' => false, + )) + ->createView() + ; + $html = $this->renderRow($view); + $this->assertMatchesXpath($this->removeBreaks($html), +' +/div[@class=" control-group"] + [ + not(./label) + ] +' + ); + } +} diff --git a/Tests/Form/SimpleDivLayoutTest.php b/Tests/Form/SimpleDivLayoutTest.php new file mode 100644 index 000000000..7d31e10da --- /dev/null +++ b/Tests/Form/SimpleDivLayoutTest.php @@ -0,0 +1,27 @@ +factory + ->createNamed('name', $this->getFormType('text')) + ->createView() + ; + + $html = $this->renderRow($view); + + $this->assertMatchesXpath($html, +' +/div[@class=" control-group"] + [ + ./label[@for="name"][@class=" control-label required"] + /following-sibling::div[@class=" controls"] + /input[@type="text"][@id="name"][@name="name"][@required="required"] + ] +' + ); + } +} diff --git a/Tests/tests/autoload.php.dist b/Tests/tests/autoload.php.dist deleted file mode 100644 index 32b436432..000000000 --- a/Tests/tests/autoload.php.dist +++ /dev/null @@ -1,25 +0,0 @@ -registerNamespaces(array( - 'Symfony' => array($vendorDir.'/symfony/src'), - 'Knp' => array($vendorDir.'/knpmenu/src'), -)); -$loader->register(); - -spl_autoload_register(function($class) { - if (0 === strpos($class, 'Mopa\\Bundle\\BootstrapBundle\\')) { - $path = __DIR__.'/../../'.implode('/', array_slice(explode('\\', $class), 2)).'.php'; - - if (!stream_resolve_include_path($path)) { - return false; - } - require_once $path; - return true; - } -}); diff --git a/Tests/tests/bootstrap.php b/Tests/tests/bootstrap.php deleted file mode 100644 index 3d7191de2..000000000 --- a/Tests/tests/bootstrap.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * for the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (file_exists($file = __DIR__.'/autoload.php')) { - require_once $file; -} elseif (file_exists($file = __DIR__.'/autoload.php.dist')) { - require_once $file; -} diff --git a/Tests/tests/vendors.php b/Tests/tests/vendors.php deleted file mode 100644 index 2ecb0fe5a..000000000 --- a/Tests/tests/vendors.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env php - Installing/Updating $name\n"; - - $installDir = $vendorDir.'/'.$name; - if (!is_dir($installDir)) { - system(sprintf('git clone --quiet %s %s', escapeshellarg($url), escapeshellarg($installDir))); - } - - system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev))); -} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a807a4340..87faaf532 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,8 +9,8 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="Tests/tests/bootstrap.php" -> + bootstrap="vendor/autoload.php"> + ./Tests/ From 0b92bb9c941d8794e63fefaf18af0a19c24323d9 Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 09:52:08 -0800 Subject: [PATCH 05/10] Twig deprecations --- Twig/MopaBootstrapInitializrTwigExtension.php | 32 +++++++------------ Twig/MopaBootstrapTwigExtension.php | 23 ------------- composer.json | 3 +- 3 files changed, 13 insertions(+), 45 deletions(-) diff --git a/Twig/MopaBootstrapInitializrTwigExtension.php b/Twig/MopaBootstrapInitializrTwigExtension.php index acbf98278..9df95fccc 100644 --- a/Twig/MopaBootstrapInitializrTwigExtension.php +++ b/Twig/MopaBootstrapInitializrTwigExtension.php @@ -9,8 +9,6 @@ namespace Mopa\Bundle\BootstrapBundle\Twig; -use Symfony\Component\DependencyInjection\ContainerInterface; - /** * Reads initializr configuration file and generates corresponding Twig Globals * @@ -18,26 +16,18 @@ */ class MopaBootstrapInitializrTwigExtension extends \Twig_Extension { - protected $container; - - protected $environment; - /** - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * @var array */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } + protected $parameters; /** * - * @param \Twig_Environment $environment + * @param array */ - public function initRuntime(\Twig_Environment $environment) + public function __construct(array $parameters) { - $this->environment = $environment; + $this->parameters = $parameters; } /** @@ -47,13 +37,13 @@ public function initRuntime(\Twig_Environment $environment) */ public function getGlobals() { - $meta = $this->container->getParameter('mopa_bootstrap.initializr.meta'); - $dns_prefetch = $this->container->getParameter('mopa_bootstrap.initializr.dns_prefetch'); - $google = $this->container->getParameter('mopa_bootstrap.initializr.google'); + $meta = $this->parameters['mopa_bootstrap.initializr.meta']; + $dns_prefetch = $this->parameters['mopa_bootstrap.initializr.dns_prefetch']; + $google = $this->parameters['mopa_bootstrap.initializr.google']; // TODO: think about setting this default as kernel debug, // what about PROD env which does not need diagnostic mode and test - $diagnostic_mode = $this->container->getParameter('mopa_bootstrap.initializr.diagnostic_mode'); + $diagnostic_mode = $this->parameters['mopa_bootstrap.initializr.diagnostic_mode']; return array( 'dns_prefetch' => $dns_prefetch, @@ -62,7 +52,7 @@ public function getGlobals() 'diagnostic_mode' => $diagnostic_mode ); } - + /** * Returns a list of functions to add to the existing list. * @@ -74,7 +64,7 @@ public function getFunctions() 'form_help' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))), ); } - + /** * Returns the name of the extension. * diff --git a/Twig/MopaBootstrapTwigExtension.php b/Twig/MopaBootstrapTwigExtension.php index daed802a1..6cbad9ef5 100644 --- a/Twig/MopaBootstrapTwigExtension.php +++ b/Twig/MopaBootstrapTwigExtension.php @@ -9,8 +9,6 @@ namespace Mopa\Bundle\BootstrapBundle\Twig; -use Symfony\Component\DependencyInjection\ContainerInterface; - /** * Add new twig functions related to forms * @@ -19,27 +17,6 @@ */ class MopaBootstrapTwigExtension extends \Twig_Extension { - protected $container; - - protected $environment; - - /** - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * - * @param \Twig_Environment $environment - */ - public function initRuntime(\Twig_Environment $environment) - { - $this->environment = $environment; - } /** * Returns a list of functions to add to the existing list. * diff --git a/composer.json b/composer.json index 21ad0f157..79d547e1a 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "target-dir": "Mopa/Bundle/BootstrapBundle", "require": { "symfony/symfony": "~2.3|~3.0", - "mopa/composer-bridge": "1.3.*" + "mopa/composer-bridge": "1.3.*", + "twig/twig": "^v1.24.0" }, "suggest": { "twbs/bootstrap": "2.*", From 7aa30e8fe089c82590fdc1a350283cec59064d7a Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 16:04:12 -0800 Subject: [PATCH 06/10] Fix Twig deprecations --- Navbar/Twig/NavbarExtension.php | 2 +- Twig/MopaBootstrapInitializrTwigExtension.php | 7 +++++-- Twig/MopaBootstrapTwigExtension.php | 10 ++++++++-- composer.json | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Navbar/Twig/NavbarExtension.php b/Navbar/Twig/NavbarExtension.php index 641ae035d..17c013253 100644 --- a/Navbar/Twig/NavbarExtension.php +++ b/Navbar/Twig/NavbarExtension.php @@ -18,7 +18,7 @@ public function __construct(NavbarRenderer $renderer) public function getFunctions() { return array( - 'mopa_bootstrap_navbar' => new \Twig_Function_Method($this, 'render', array('is_safe' => array('html'))), + new \Twig_SimpleFunction('mopa_bootstrap_navbar', array($this, 'render'), array('is_safe' => array('html'))), ); } diff --git a/Twig/MopaBootstrapInitializrTwigExtension.php b/Twig/MopaBootstrapInitializrTwigExtension.php index 9df95fccc..c3537f564 100644 --- a/Twig/MopaBootstrapInitializrTwigExtension.php +++ b/Twig/MopaBootstrapInitializrTwigExtension.php @@ -14,7 +14,7 @@ * * @author PaweÅ‚ Madej (nysander) */ -class MopaBootstrapInitializrTwigExtension extends \Twig_Extension +class MopaBootstrapInitializrTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface { /** * @var array @@ -61,7 +61,10 @@ public function getGlobals() public function getFunctions() { return array( - 'form_help' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))), + new \Twig_SimpleFunction('form_help', null, array( + 'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', + 'is_safe' => array('html'), + )), ); } diff --git a/Twig/MopaBootstrapTwigExtension.php b/Twig/MopaBootstrapTwigExtension.php index 6cbad9ef5..b953409e2 100644 --- a/Twig/MopaBootstrapTwigExtension.php +++ b/Twig/MopaBootstrapTwigExtension.php @@ -25,8 +25,14 @@ class MopaBootstrapTwigExtension extends \Twig_Extension public function getFunctions() { return array( - 'form_help' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))), - 'form_tabs' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))), + new \Twig_SimpleFunction('form_help', null, array( + 'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', + 'is_safe' => array('html'), + )), + new \Twig_SimpleFunction('form_tabs', null, array( + 'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', + 'is_safe' => array('html'), + )), ); } diff --git a/composer.json b/composer.json index 79d547e1a..8ff946955 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "require": { "symfony/symfony": "~2.3|~3.0", "mopa/composer-bridge": "1.3.*", - "twig/twig": "^v1.24.0" + "twig/twig": "~1.23" }, "suggest": { "twbs/bootstrap": "2.*", From 3ca236a756c00d35bf1fc021ee54680dedf9e472 Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 16:04:27 -0800 Subject: [PATCH 07/10] Fix form deprecations --- Form/Extension/DateTypeExtension.php | 28 +++++++-- Form/Extension/ErrorTypeFormTypeExtension.php | 36 ++++++++--- Form/Extension/HelpFormTypeExtension.php | 30 ++++++++-- Form/Extension/IconButtonExtension.php | 30 +++++++--- Form/Extension/LegendFormTypeExtension.php | 28 ++++++++- Form/Extension/TabbedFormTypeExtension.php | 59 ++++++++++++------- .../WidgetCollectionFormTypeExtension.php | 27 ++++++++- Form/Extension/WidgetFormTypeExtension.php | 49 ++++++++++++--- Form/Type/HexColorType.php | 25 ++++++++ Form/Type/TabType.php | 29 ++++++++- Form/Type/TabsType.php | 27 ++++++++- Resources/views/Form/fields.html.twig | 4 +- Tests/Form/AbstractDivLayoutTest.php | 2 + 13 files changed, 312 insertions(+), 62 deletions(-) diff --git a/Form/Extension/DateTypeExtension.php b/Form/Extension/DateTypeExtension.php index 782f90564..15128f02c 100644 --- a/Form/Extension/DateTypeExtension.php +++ b/Form/Extension/DateTypeExtension.php @@ -1,10 +1,11 @@ setOptional(array( 'datepicker' )); } + /** + * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ public function getExtendedType() { - return 'date'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Symfony\Component\Form\Extension\Core\Type\DateType' + : 'date' // SF <2.8 BC + ; } } diff --git a/Form/Extension/ErrorTypeFormTypeExtension.php b/Form/Extension/ErrorTypeFormTypeExtension.php index 18e9d1945..87ac7d980 100644 --- a/Form/Extension/ErrorTypeFormTypeExtension.php +++ b/Form/Extension/ErrorTypeFormTypeExtension.php @@ -1,33 +1,55 @@ error_type = $options['error_type']; + $this->errorType = $options['error_type']; } public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['error_type'] = $options['error_type']; $view->vars['error_delay'] = $options['error_delay']; } + + /** + * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ + */ public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( - 'error_type' => $this->error_type, - 'error_delay'=> false - )); + 'error_type' => $this->errorType, + 'error_delay' => false, + )); } + + /** + * {@inheritdoc} + */ public function getExtendedType() { - return 'form'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Symfony\Component\Form\Extension\Core\Type\FormType' + : 'form' // SF <2.8 BC + ; } } diff --git a/Form/Extension/HelpFormTypeExtension.php b/Form/Extension/HelpFormTypeExtension.php index a2d785232..d096e4386 100644 --- a/Form/Extension/HelpFormTypeExtension.php +++ b/Form/Extension/HelpFormTypeExtension.php @@ -1,11 +1,12 @@ vars['help_inline'] = $options['help_inline']; $view->vars['help_block'] = $options['help_block']; $view->vars['help_label'] = $options['help_label']; - + if (!isset($options['help_label_tooltip']['icon']) && !is_null($this->options['tooltip_icon'])) { $options['help_label_tooltip']['icon'] = $this->options['tooltip_icon']; } @@ -65,7 +66,10 @@ public function buildView(FormView $view, FormInterface $form, array $options) } } - public function setDefaultOptions(OptionsResolverInterface $resolver) + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'help_inline' => null, @@ -85,8 +89,24 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) )); } + /** + * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ public function getExtendedType() { - return 'form'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Symfony\Component\Form\Extension\Core\Type\FormType' + : 'form' // SF <2.8 BC + ; } } diff --git a/Form/Extension/IconButtonExtension.php b/Form/Extension/IconButtonExtension.php index 00553ab9b..7bc243f40 100644 --- a/Form/Extension/IconButtonExtension.php +++ b/Form/Extension/IconButtonExtension.php @@ -1,27 +1,29 @@ vars['icon'] = $options['icon']; + $view->vars['icon_color'] = $options['icon_color']; } /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( array( @@ -33,10 +35,22 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) /** * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function setDefaultOptions(OptionsResolverInterface $resolver) { - $view->vars['icon'] = $options['icon']; - $view->vars['icon_color'] = $options['icon_color']; + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ + public function getExtendedType() + { + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Symfony\Component\Form\Extension\Core\Type\ButtonType' + : 'button' // SF <2.8 BC + ; } } diff --git a/Form/Extension/LegendFormTypeExtension.php b/Form/Extension/LegendFormTypeExtension.php index fb4b9a99e..8da4ef1bc 100644 --- a/Form/Extension/LegendFormTypeExtension.php +++ b/Form/Extension/LegendFormTypeExtension.php @@ -1,10 +1,11 @@ vars['render_optional_text'] = $options['render_optional_text']; $view->vars['errors_on_forms'] = $options['errors_on_forms']; } - public function setDefaultOptions(OptionsResolverInterface $resolver) + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'render_fieldset' => $this->render_fieldset, @@ -47,8 +52,25 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'errors_on_forms' => $this->errors_on_forms, )); } + + /** + * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ public function getExtendedType() { - return 'form'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Symfony\Component\Form\Extension\Core\Type\FormType' + : 'form' // SF <2.8 BC + ; } } diff --git a/Form/Extension/TabbedFormTypeExtension.php b/Form/Extension/TabbedFormTypeExtension.php index 2f6a55aab..fe6c68491 100644 --- a/Form/Extension/TabbedFormTypeExtension.php +++ b/Form/Extension/TabbedFormTypeExtension.php @@ -1,11 +1,12 @@ options = $options; } - /** - * {@inheritdoc} - */ - public function getExtendedType() - { - return 'form'; - } - - /** - * {@inheritdoc} - */ - public function setDefaultOptions(OptionsResolverInterface $resolver) - { - $resolver->setDefaults(array( - 'tabs_class' => $this->options['class'], - )); - } - public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['tabbed'] = false; @@ -65,7 +48,12 @@ public function finishView(FormView $view, FormInterface $form, array $options) } } - $tabsForm = $this->formFactory->create(new TabsType(), null, array( + $tabsType = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Mopa\Bundle\BootstrapBundle\Form\Type\TabsType' + : new TabsType() // SF <2.8 BC + ; + + $tabsForm = $this->formFactory->create($tabsType, null, array( 'tabs' => $tabs, 'attr' => array( 'class' => $options['tabs_class'], @@ -76,4 +64,35 @@ public function finishView(FormView $view, FormInterface $form, array $options) $view->vars['tabbed'] = true; $view->vars['tabsView'] = $tabsForm->createView(); } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'tabs_class' => $this->options['class'], + )); + } + + /** + * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ + public function getExtendedType() + { + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Mopa\Bundle\BootstrapBundle\Form\Type\TabsType' + : 'tabs' // SF <2.8 BC + ; + } } diff --git a/Form/Extension/WidgetCollectionFormTypeExtension.php b/Form/Extension/WidgetCollectionFormTypeExtension.php index b25f43525..3b9e59122 100644 --- a/Form/Extension/WidgetCollectionFormTypeExtension.php +++ b/Form/Extension/WidgetCollectionFormTypeExtension.php @@ -1,11 +1,12 @@ vars['widget_remove_btn'] = $options['widget_remove_btn']; } - public function setDefaultOptions(OptionsResolverInterface $resolver) + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'omit_collection_item' => true === $this->options['render_collection_item'] ? false : true, @@ -71,8 +75,25 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'widget_remove_btn' => null, )); } + + /** + * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ public function getExtendedType() { - return 'form'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Symfony\Component\Form\Extension\Core\Type\FormType' + : 'form' // SF <2.8 BC + ; } } diff --git a/Form/Extension/WidgetFormTypeExtension.php b/Form/Extension/WidgetFormTypeExtension.php index edf2f51d9..05c8be462 100644 --- a/Form/Extension/WidgetFormTypeExtension.php +++ b/Form/Extension/WidgetFormTypeExtension.php @@ -1,11 +1,13 @@ vars['widget_checkbox_label'] = $options['widget_checkbox_label']; } - public function setDefaultOptions(OptionsResolverInterface $resolver) + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( array( @@ -68,7 +74,18 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'widget_checkbox_label' => $this->options['checkbox_label'], ) ); - $resolver->setAllowedValues(array( + if (version_compare(Kernel::VERSION, '2.6', '>=')) { + $resolver->setAllowedValues('widget_type', array( + 'inline', + '', + )); + $resolver->setAllowedValues('widget_checkbox_label', array( + 'label', + 'widget', + 'both', + )); + } else { + $resolver->setAllowedValues(array( 'widget_type' => array( 'inline', '', @@ -77,12 +94,30 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'label', 'widget', 'both', - ) - ) - ); + ), + )); + } + } + + /** + * {@inheritdoc} + * + * @deprecated Remove it when bumping requirements to SF 2.7+ + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ public function getExtendedType() { - return 'form'; + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') + ? 'Symfony\Component\Form\Extension\Core\Type\FormType' + : 'form' // SF <2.8 BC + ; } } diff --git a/Form/Type/HexColorType.php b/Form/Type/HexColorType.php index 43a24e0d2..5cff54823 100644 --- a/Form/Type/HexColorType.php +++ b/Form/Type/HexColorType.php @@ -2,6 +2,7 @@ namespace Mopa\Bundle\BootstrapBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; @@ -15,7 +16,18 @@ public function finishView(FormView $view, FormInterface $form, array $options) } } + /** + * {@inheritdoc} + */ public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'compound' => false, @@ -26,7 +38,20 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) )); } + /** + * {@inheritdoc} + * + * SF <2.8 BC + */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'hexcolor'; } diff --git a/Form/Type/TabType.php b/Form/Type/TabType.php index cf1137808..0c842bf0a 100644 --- a/Form/Type/TabType.php +++ b/Form/Type/TabType.php @@ -5,11 +5,23 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class TabType extends AbstractType { + /** + * {@inheritdoc} + */ public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'icon' => null, @@ -20,12 +32,25 @@ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['icon'] = $options['icon']; $view->vars['tab_active'] = false; - + $view->parent->vars['tabbed'] = true; } + /** + * {@inheritdoc} + * + * SF <2.8 BC + */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'tab'; } -} \ No newline at end of file +} diff --git a/Form/Type/TabsType.php b/Form/Type/TabsType.php index f65283b9d..5aa93ba43 100644 --- a/Form/Type/TabsType.php +++ b/Form/Type/TabsType.php @@ -5,6 +5,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class TabsType extends AbstractType @@ -14,15 +15,39 @@ public function buildView(FormView $view, FormInterface $form, array $options) $view->vars['tabs'] = $options['tabs']; } + /** + * {@inheritdoc} + */ public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'tabs' => array(), )); } + /** + * {@inheritdoc} + * + * SF <2.8 BC + */ public function getName() + { + return $this->getBlockPrefix(); + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() { return 'tabs'; } -} \ No newline at end of file +} diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index 929275e31..b856e7bff 100755 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -104,7 +104,7 @@ {% block checkbox_widget %} {% spaceless %} -{% if label is not sameas(false) and label is empty %} +{% if label is not same as(false) and label is empty %} {% set label = name|humanize %} {% endif %} {% if form.parent != null and 'choice' not in form.parent.vars.block_prefixes and label_render %} @@ -241,7 +241,7 @@ {% block form_label %} {% if 'checkbox' not in block_prefixes or widget_checkbox_label in ['label', 'both'] %} {% spaceless %} - {% if label is not sameas(false) %} + {% if label is not same as(false) %} {% if label is empty %} {% set label = name|humanize %} {% endif %} diff --git a/Tests/Form/AbstractDivLayoutTest.php b/Tests/Form/AbstractDivLayoutTest.php index 88357458d..24873cb78 100644 --- a/Tests/Form/AbstractDivLayoutTest.php +++ b/Tests/Form/AbstractDivLayoutTest.php @@ -99,6 +99,8 @@ protected function getExtensions() ), $this->getFormType('text') => array( ), + $this->getFormType('tab') => array( + ), ))); } From 8b5b14166c7c9c3930955889a1b74d5cbe59c02e Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sun, 14 Feb 2016 16:20:30 -0800 Subject: [PATCH 08/10] Add phpunit-bridge to detect deprecations --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f015ddfaa..af26dc94d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ php: - hhvm env: - - SYMFONY_VERSION=2.3.* - - SYMFONY_VERSION=2.4.* - - SYMFONY_VERSION=2.5.* + - SYMFONY_VERSION=2.3.* NO_PHPUNIT_BRIDGE=1 + - SYMFONY_VERSION=2.4.* NO_PHPUNIT_BRIDGE=1 + - SYMFONY_VERSION=2.5.* NO_PHPUNIT_BRIDGE=1 - SYMFONY_VERSION=2.6.* SYMFONY_DEPRECATIONS_HELPER=weak - SYMFONY_VERSION=2.7.* - SYMFONY_VERSION=2.8.* @@ -43,6 +43,7 @@ cache: before_script: - composer selfupdate - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; + - if [ "$NO_PHPUNIT_BRIDGE" == "" ]; then composer require symfony/phpunit-bridge; fi; - composer update --prefer-dist $COMPOSER_FLAGS script: From c415fa4ee30a5b59e7f38cc9c815a061eb975a02 Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sat, 11 Jun 2016 10:50:36 -0700 Subject: [PATCH 09/10] WIP tabs test --- Tests/Form/AbstractDivLayoutTest.php | 9 +++++--- Tests/Form/TabbedLayoutTest.php | 33 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 Tests/Form/TabbedLayoutTest.php diff --git a/Tests/Form/AbstractDivLayoutTest.php b/Tests/Form/AbstractDivLayoutTest.php index 24873cb78..0363b2442 100644 --- a/Tests/Form/AbstractDivLayoutTest.php +++ b/Tests/Form/AbstractDivLayoutTest.php @@ -10,6 +10,7 @@ use Mopa\Bundle\BootstrapBundle\Form\Extension\WidgetFormTypeExtension; use Mopa\Bundle\BootstrapBundle\Form\Extension\WidgetCollectionFormTypeExtension; use Mopa\Bundle\BootstrapBundle\Form\Extension\IconButtonExtension; +use Mopa\Bundle\BootstrapBundle\Form\Type\TabType; use Mopa\Bundle\BootstrapBundle\Twig\MopaBootstrapInitializrTwigExtension; use Mopa\Bundle\BootstrapBundle\Twig\MopaBootstrapTwigExtension; use Mopa\Bundle\BootstrapBundle\Tests\FileSystemLoader; @@ -32,6 +33,7 @@ abstract class AbstractDivLayoutTest extends FormIntegrationTestCase 'form' => 'Symfony\Component\Form\Extension\Core\Type\FormType', 'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType', 'email' => 'Symfony\Component\Form\Extension\Core\Type\EmailType', + 'tab' => 'Mopa\Bundle\BootstrapBundle\Form\Type\TabType', ); /** @@ -88,7 +90,9 @@ protected function setUp() */ protected function getExtensions() { - return array(new PreloadedExtension(array(), array( + return array(new PreloadedExtension(array( + 'tab' => new TabType(), + ), array( $this->getFormType('form') => array( $this->getHelpFormTypeExtension(), $this->getWidgetFormTypeExtension(), @@ -96,11 +100,10 @@ protected function getExtensions() $this->getLegendFormTypeExtension(), $this->getErrorTypeFormTypeExtension(), $this->getIconButtonExtension(), + $this->getTabbedFormTypeExtension(), ), $this->getFormType('text') => array( ), - $this->getFormType('tab') => array( - ), ))); } diff --git a/Tests/Form/TabbedLayoutTest.php b/Tests/Form/TabbedLayoutTest.php new file mode 100644 index 000000000..8e9774c3d --- /dev/null +++ b/Tests/Form/TabbedLayoutTest.php @@ -0,0 +1,33 @@ +factory + ->createNamed('form', $this->getFormType('form')) + ; + $tab1 = $this->factory + ->createNamed('tab1', $this->getFormType('tab'), null, array( + 'auto_initialize' => false, + )) + ; + $tab2 = $this->factory + ->createNamed('tab2', $this->getFormType('tab'), null, array( + 'auto_initialize' => false, + )) + ; + $form->add($tab1); + $form->add($tab2); + $view = $form->createView(); + $html = $this->renderWidget($view); + + $this->assertContains($html, +' +FAIL +' + ); + } +} From 62882a94dd76338c883ad729e408e533f32ce066 Mon Sep 17 00:00:00 2001 From: Carlo Forghieri Date: Sat, 11 Jun 2016 15:31:18 -0700 Subject: [PATCH 10/10] fixup! Fix form deprecations --- Resources/config/form_extensions.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Resources/config/form_extensions.yml b/Resources/config/form_extensions.yml index f27db6274..432becfbe 100644 --- a/Resources/config/form_extensions.yml +++ b/Resources/config/form_extensions.yml @@ -2,47 +2,47 @@ services: mopa.form.icon_button_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\IconButtonExtension tags: - - { name: form.type_extension, alias: button } + - { name: form.type_extension, alias: button, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } mopa.form.help_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\HelpFormTypeExtension arguments: - { tooltip_icon: %mopa_bootstrap.form.tooltip.icon%, tooltip_placement: %mopa_bootstrap.form.tooltip.placement% } tags: - - { name: form.type_extension, alias: form } + - { name: form.type_extension, alias: form, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } mopa.form.legend_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\LegendFormTypeExtension arguments: - { render_fieldset: %mopa_bootstrap.form.render_fieldset%, show_legend: %mopa_bootstrap.form.show_legend%, show_child_legend: %mopa_bootstrap.form.show_child_legend%, render_required_asterisk: %mopa_bootstrap.form.render_required_asterisk%, render_optional_text: %mopa_bootstrap.form.render_optional_text%, errors_on_forms: %mopa_bootstrap.form.errors_on_forms%} tags: - - { name: form.type_extension, alias: form } + - { name: form.type_extension, alias: form, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } mopa.form.error_type_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\ErrorTypeFormTypeExtension arguments: - { error_type: %mopa_bootstrap.form.error_type% } tags: - - { name: form.type_extension, alias: form } + - { name: form.type_extension, alias: form, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } mopa.form.widget_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\WidgetFormTypeExtension arguments: - { checkbox_label: %mopa_bootstrap.form.checkbox_label%, bootstrap_version: mopa_bootstrap.version } tags: - - { name: form.type_extension, alias: form } + - { name: form.type_extension, alias: form, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } mopa.form.widget_collection_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\WidgetCollectionFormTypeExtension arguments: - { render_collection_item: %mopa_bootstrap.form.render_collection_item%, widget_add_btn: %mopa_bootstrap.form.collection.widget_add_btn%, widget_remove_btn: %mopa_bootstrap.form.collection.widget_remove_btn% } tags: - - { name: form.type_extension, alias: form } + - { name: form.type_extension, alias: form, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } mopa.form.date_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\DateTypeExtension tags: - - { name: form.type_extension, alias: date } + - { name: form.type_extension, alias: date, extended_type: Symfony\Component\Form\Extension\Core\Type\DateType } mopa.form.tabbed_extension: class: Mopa\Bundle\BootstrapBundle\Form\Extension\TabbedFormTypeExtension @@ -50,7 +50,7 @@ services: - "@form.factory" - { class: %mopa_bootstrap.form.tabs.class% } tags: - - { name: form.type_extension, alias: form } + - { name: form.type_extension, alias: form, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } mopa.form.tab_type: class: Mopa\Bundle\BootstrapBundle\Form\Type\TabType