From cf4e95662ee85ed46e9110b525a368401fc06af1 Mon Sep 17 00:00:00 2001 From: Mathieu Piot Date: Mon, 8 Jan 2018 10:39:34 +0100 Subject: [PATCH 1/2] [TwigBridge] Apply some changes to support Bootstrap4-stable --- .../views/Form/bootstrap_4_layout.html.twig | 106 ++++++++++-------- .../Form/bootstrap_base_layout.html.twig | 2 +- 2 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index 12981e346232e..34fc47e8ecc9b 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -3,11 +3,25 @@ {# Widgets #} {% block money_widget -%} - {% if not valid %} - {% set group_class = ' form-control is-invalid' %} - {% set valid = true %} - {% endif %} - {{- parent() -}} + {%- set prepend = not (money_pattern starts with '{{') -%} + {%- set append = not (money_pattern ends with '}}') -%} + {%- if prepend or append -%} +
+ {%- if prepend -%} +
+ {{ money_pattern|replace({ '{{ widget }}':''}) }} +
+ {%- endif -%} + {{- block('form_widget_simple') -}} + {%- if append -%} +
+ {{ money_pattern|replace({ '{{ widget }}':''}) }} +
+ {%- endif -%} +
+ {%- else -%} + {{- block('form_widget_simple') -}} + {%- endif -%} {%- endblock money_widget %} {% block datetime_widget -%} @@ -39,7 +53,6 @@ {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%} {% set valid = true %} {%- endif -%} - {%- if widget == 'single_text' -%} {{- block('form_widget_simple') -}} {%- else -%} @@ -80,7 +93,9 @@
{% set valid = true %} {{- block('form_widget_simple') -}} - % +
+ % +
{%- endblock percent_widget %} @@ -93,7 +108,7 @@ {%- block widget_attributes -%} {%- if not valid %} - {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %} + {% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %} {% endif -%} {{ parent() }} {%- endblock widget_attributes -%} @@ -105,15 +120,14 @@ {% block checkbox_widget -%} {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%} - {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} - {% if 'checkbox-inline' in parent_label_class %} - {{- form_label(form, null, { widget: parent() }) -}} - {% elseif 'form-check-inline' in parent_label_class %} -
+ {%- if 'checkbox-custom' in parent_label_class -%} + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%} +
{{- form_label(form, null, { widget: parent() }) -}}
- {% else -%} -
+ {%- else -%} + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} +
{{- form_label(form, null, { widget: parent() }) -}}
{%- endif -%} @@ -121,18 +135,21 @@ {% block radio_widget -%} {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%} - {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} - {%- if 'radio-inline' in parent_label_class -%} - {{- form_label(form, null, { widget: parent() }) -}} + {%- if 'radio-custom' in parent_label_class -%} + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%} +
+ {{- form_label(form, null, { widget: parent() }) -}} +
{%- else -%} -
+ {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} +
{{- form_label(form, null, { widget: parent() }) -}}
{%- endif -%} {%- endblock radio_widget %} {% block choice_widget_expanded -%} - {% if '-inline' in label_attr.class|default('') -%} +
{%- for child in form %} {{- form_widget(child, { parent_label_class: label_attr.class|default(''), @@ -140,20 +157,7 @@ valid: valid, }) -}} {% endfor -%} - {%- else -%} - {%- if not valid -%} - {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %} - {%- endif -%} -
- {%- for child in form %} - {{- form_widget(child, { - parent_label_class: label_attr.class|default(''), - translation_domain: choice_translation_domain, - valid: true, - }) -}} - {% endfor -%} -
- {%- endif %} +
{%- endblock choice_widget_expanded %} {# Labels #} @@ -162,7 +166,7 @@ {% if label is not same as(false) -%} {%- if compound is defined and compound -%} {%- set element = 'legend' -%} - {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-legend')|trim}) -%} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%} {%- else -%} {%- set label_attr = label_attr|merge({for: id, class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%} {%- endif -%} @@ -179,19 +183,26 @@ {% set label = name|humanize %} {%- endif -%} {%- endif -%} - <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %} + <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{{- form_errors(form) -}} {%- endif -%} {%- endblock form_label %} {% block checkbox_radio_label -%} {#- Do not display the label if widget is not defined in order to prevent double label rendering -#} {%- if widget is defined -%} - {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%} + {%- if parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) -%} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%} + {%- else %} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%} + {%- endif %} + {%- if not compound -%} + {% set label_attr = label_attr|merge({'for': id}) %} + {%- endif -%} {%- if required -%} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%} {%- endif -%} {%- if parent_label_class is defined -%} - {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) -%} + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%} {%- endif -%} {%- if label is not same as(false) and label is empty -%} {%- if label_format is not empty -%} @@ -203,8 +214,11 @@ {%- set label = name|humanize -%} {%- endif -%} {%- endif -%} + + {{ widget|raw }} - {{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} + {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} + {{- form_errors(form) -}} {%- endif -%} {%- endblock checkbox_radio_label %} @@ -225,12 +239,12 @@ {% block form_errors -%} {%- if errors|length > 0 -%} -
-
    - {%- for error in errors -%} -
  • {{ error.message }}
  • - {%- endfor -%} -
-
+
+
    + {%- for error in errors -%} +
  • {{ error.message }}
  • + {%- endfor -%} +
+
{%- endif %} {%- endblock form_errors %} diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig index d57978220f330..71aedf99ad1fa 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig @@ -147,7 +147,7 @@ {% block choice_label -%} {# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #} - {%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': ''})|trim}) -%} + {%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%} {{- block('form_label') -}} {% endblock choice_label %} From 14e22825134c4bca807f8ea42b48a1ddfa4deae5 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Tue, 13 Feb 2018 23:04:19 +0100 Subject: [PATCH 2/2] Fixed broken tests --- .../views/Form/bootstrap_4_layout.html.twig | 2 +- src/Symfony/Bridge/Twig/composer.json | 4 +- ...AbstractBootstrap4HorizontalLayoutTest.php | 4 +- .../Tests/AbstractBootstrap4LayoutTest.php | 428 ++++++++---------- 4 files changed, 202 insertions(+), 236 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index 34fc47e8ecc9b..7ecc26b7b9727 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -217,7 +217,7 @@ {{ widget|raw }} - {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} + {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} {{- form_errors(form) -}} {%- endif -%} diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index aea0d10a67791..ffec118f502c8 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -23,7 +23,7 @@ "symfony/asset": "~2.8|~3.0|~4.0", "symfony/dependency-injection": "~2.8|~3.0|~4.0", "symfony/finder": "~2.8|~3.0|~4.0", - "symfony/form": "~3.4|~4.0", + "symfony/form": "^3.4.5|^4.0.5", "symfony/http-foundation": "^3.3.11|~4.0", "symfony/http-kernel": "~3.2|~4.0", "symfony/polyfill-intl-icu": "~1.0", @@ -41,7 +41,7 @@ "symfony/workflow": "~3.3|~4.0" }, "conflict": { - "symfony/form": "<3.4", + "symfony/form": "<3.4.5", "symfony/console": "<3.4" }, "suggest": { diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php index 23e6f141cac9d..5934479a90093 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php @@ -53,7 +53,7 @@ public function testLabelOnForm() $this->assertMatchesXpath($html, '/legend - [@class="col-form-label col-sm-2 col-form-legend required"] + [@class="col-form-label col-sm-2 col-form-label required"] [.="[trans]Name[/trans]"] ' ); @@ -144,7 +144,7 @@ public function testLegendOnExpandedType() $this->assertMatchesXpath($html, '/legend - [@class="col-sm-2 col-form-legend required"] + [@class="col-sm-2 col-form-label required"] [.="[trans]Custom label[/trans]"] ' ); diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php index fdaa07e1c15bc..197f3ab8d6854 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php @@ -53,7 +53,7 @@ public function testLabelOnForm() $this->assertMatchesXpath($html, '/legend - [@class="col-form-legend required"] + [@class="col-form-label required"] [.="[trans]Name[/trans]"] ' ); @@ -144,7 +144,7 @@ public function testLegendOnExpandedType() $this->assertMatchesXpath($html, '/legend - [@class="col-form-legend required"] + [@class="col-form-label required"] [.="[trans]Custom label[/trans]"] ' ); @@ -184,12 +184,10 @@ public function testCheckedCheckbox() '/div [@class="form-check"] [ - ./label - [.=" [trans]Name[/trans]"] + ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class form-check-input"][@checked="checked"][@value="1"] + /following-sibling::label + [.="[trans]Name[/trans]"] [@class="form-check-label required"] - [ - ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class form-check-input"][@checked="checked"][@value="1"] - ] ] ' ); @@ -234,20 +232,16 @@ public function testSingleExpandedChoiceAttributesWithMainAttributes() ./div [@class="form-check"] [ - ./label - [.=" [trans]Choice&A[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label + [.="[trans]Choice&A[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&B[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label + [.="[trans]Choice&B[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -263,11 +257,9 @@ public function testUncheckedCheckbox() '/div [@class="form-check"] [ - ./label - [.=" [trans]Name[/trans]"] - [ - ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class form-check-input"][not(@checked)] - ] + ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class form-check-input"][not(@checked)] + /following-sibling::label + [.="[trans]Name[/trans]"] ] ' ); @@ -283,11 +275,9 @@ public function testCheckboxWithValue() '/div [@class="form-check"] [ - ./label - [.=" [trans]Name[/trans]"] - [ - ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class form-check-input"][@value="foo&bar"] - ] + ./input[@type="checkbox"][@name="name"][@id="my&id"][@class="my&class form-check-input"][@value="foo&bar"] + /following-sibling::label + [.="[trans]Name[/trans]"] ] ' ); @@ -307,20 +297,16 @@ public function testSingleChoiceExpanded() ./div [@class="form-check"] [ - ./label - [.=" [trans]Choice&A[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label + [.="[trans]Choice&A[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&B[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label + [.="[trans]Choice&B[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -343,18 +329,14 @@ public function testSingleChoiceExpandedWithLabelsAsFalse() ./div [@class="form-check"] [ - ./label - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label ] /following-sibling::div [@class="form-check"] [ - ./label - [ - ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -383,28 +365,22 @@ public function testSingleChoiceExpandedWithLabelsSetByCallable() ./div [@class="form-check"] [ - ./label - [.=" [trans]label.&a[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label + [.="[trans]label.&a[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [ - ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]label.&c[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_2"][@value="&c"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_2"][@value="&c"][not(@checked)] + /following-sibling::label + [.="[trans]label.&c[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -429,18 +405,14 @@ public function testSingleChoiceExpandedWithLabelsSetFalseByCallable() ./div [@class="form-check"] [ - ./label - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label ] /following-sibling::div [@class="form-check"] [ - ./label - [ - ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -463,20 +435,16 @@ public function testSingleChoiceExpandedWithoutTranslation() ./div [@class="form-check"] [ - ./label - [.=" Choice&A"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label + [.="Choice&A"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" Choice&B"] - [ - ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label + [.="Choice&B"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -499,20 +467,16 @@ public function testSingleChoiceExpandedAttributes() ./div [@class="form-check"] [ - ./label - [.=" [trans]Choice&A[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label + [.="[trans]Choice&A[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&B[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)][@class="foo&bar form-check-input"] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)][@class="foo&bar form-check-input"] + /following-sibling::label + [.="[trans]Choice&B[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -536,29 +500,23 @@ public function testSingleChoiceExpandedWithPlaceholder() ./div [@class="form-check"] [ - ./label - [.=" [trans]Test&Me[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)] + /following-sibling::label + [.="[trans]Test&Me[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&A[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@checked] + /following-sibling::label + [.="[trans]Choice&A[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&B[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)] + /following-sibling::label + [.="[trans]Choice&B[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -583,29 +541,23 @@ public function testSingleChoiceExpandedWithPlaceholderWithoutTranslation() ./div [@class="form-check"] [ - ./label - [.=" Placeholder&Not&Translated"] - [ - ./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_placeholder"][not(@checked)] + /following-sibling::label + [.="Placeholder&Not&Translated"] ] /following-sibling::div [@class="form-check"] - [ - ./label - [.=" Choice&A"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@checked] - ] + [ + ./input[@type="radio"][@name="name"][@id="name_0"][@checked] + /following-sibling::label + [.="Choice&A"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" Choice&B"] - [ - ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)] + /following-sibling::label + [.="Choice&B"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -627,20 +579,16 @@ public function testSingleChoiceExpandedWithBooleanValue() ./div [@class="form-check"] [ - ./label - [.=" [trans]Choice&A[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_0"][@checked] - ] + ./input[@type="radio"][@name="name"][@id="name_0"][@checked] + /following-sibling::label + [.="[trans]Choice&A[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&B[/trans]"] - [ - ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)] - ] + ./input[@type="radio"][@name="name"][@id="name_1"][not(@checked)] + /following-sibling::label + [.="[trans]Choice&B[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -663,29 +611,23 @@ public function testMultipleChoiceExpanded() ./div [@class="form-check"] [ - ./label - [.=" [trans]Choice&A[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)] + /following-sibling::label + [.="[trans]Choice&A[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&B[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)] + /following-sibling::label + [.="[trans]Choice&B[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&C[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)] + /following-sibling::label + [.="[trans]Choice&C[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -708,18 +650,14 @@ public function testMultipleChoiceExpandedWithLabelsAsFalse() ./div [@class="form-check"] [ - ./label - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label ] /following-sibling::div [@class="form-check"] [ - ./label - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -748,28 +686,22 @@ public function testMultipleChoiceExpandedWithLabelsSetByCallable() ./div [@class="form-check"] [ - ./label - [.=" [trans]label.&a[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label + [.="[trans]label.&a[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]label.&c[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@value="&c"][not(@checked)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@value="&c"][not(@checked)] + /following-sibling::label + [.="[trans]label.&c[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -794,18 +726,14 @@ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable() ./div [@class="form-check"] [ - ./label - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@value="&a"][@checked] + /following-sibling::label ] /following-sibling::div [@class="form-check"] [ - ./label - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)] + /following-sibling::label ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -829,29 +757,23 @@ public function testMultipleChoiceExpandedWithoutTranslation() ./div [@class="form-check"] [ - ./label - [.=" Choice&A"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)] + /following-sibling::label + [.="Choice&A"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" Choice&B"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)] + /following-sibling::label + [.="Choice&B"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" Choice&C"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)] + /following-sibling::label + [.="Choice&C"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -875,29 +797,23 @@ public function testMultipleChoiceExpandedAttributes() ./div [@class="form-check"] [ - ./label - [.=" [trans]Choice&A[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)] + /following-sibling::label + [.="[trans]Choice&A[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&B[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)][@class="foo&bar form-check-input"] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)][@class="foo&bar form-check-input"] + /following-sibling::label + [.="[trans]Choice&B[/trans]"] ] /following-sibling::div [@class="form-check"] [ - ./label - [.=" [trans]Choice&C[/trans]"] - [ - ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)] - ] + ./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)] + /following-sibling::label + [.="[trans]Choice&C[/trans]"] ] /following-sibling::input[@type="hidden"][@id="name__token"] ] @@ -913,17 +829,15 @@ public function testCheckedRadio() '/div [@class="form-check"] [ - ./label + ./input + [@id="my&id"] + [@type="radio"] + [@name="name"] + [@class="my&class form-check-input"] + [@checked="checked"] + [@value="1"] + /following-sibling::label [@class="form-check-label required"] - [ - ./input - [@id="my&id"] - [@type="radio"] - [@name="name"] - [@class="my&class form-check-input"] - [@checked="checked"] - [@value="1"] - ] ] ' ); @@ -937,16 +851,14 @@ public function testUncheckedRadio() '/div [@class="form-check"] [ - ./label + ./input + [@id="my&id"] + [@type="radio"] + [@name="name"] + [@class="my&class form-check-input"] + [not(@checked)] + /following-sibling::label [@class="form-check-label required"] - [ - ./input - [@id="my&id"] - [@type="radio"] - [@name="name"] - [@class="my&class form-check-input"] - [not(@checked)] - ] ] ' ); @@ -962,16 +874,15 @@ public function testRadioWithValue() '/div [@class="form-check"] [ - ./label + ./input + [@id="my&id"] + [@type="radio"] + [@name="name"] + [@class="my&class form-check-input"] + [@value="foo&bar"] + /following-sibling::label [@class="form-check-label required"] - [ - ./input - [@id="my&id"] - [@type="radio"] - [@name="name"] - [@class="my&class form-check-input"] - [@value="foo&bar"] - ] + [@for="my&id"] ] ' ); @@ -996,6 +907,61 @@ public function testFile() $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class form-control-file')), '/input [@type="file"] +' + ); + } + + public function testMoney() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType', 1234.56, array( + 'currency' => 'EUR', + )); + + $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')), + '/div + [@class="input-group"] + [ + ./div + [@class="input-group-prepend"] + [ + ./span + [@class="input-group-text"] + [contains(.., "€")] + ] + /following-sibling::input + [@id="my&id"] + [@type="text"] + [@name="name"] + [@class="my&class form-control"] + [@value="1234.56"] + ] +' + ); + } + + public function testPercent() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1); + + $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')), + '/div + [@class="input-group"] + [ + ./input + [@id="my&id"] + [@type="text"] + [@name="name"] + [@class="my&class form-control"] + [@value="10"] + /following-sibling::div + [@class="input-group-append"] + [ + ./span + [@class="input-group-text"] + [contains(.., "%")] + ] + + ] ' ); }