From 935cb2c506edeb754a20d3c82e62445372bd854d Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Sun, 28 Jan 2024 16:49:46 +0100 Subject: [PATCH 1/4] Revert #47715 --- Resources/views/Form/form_div_layout.html.twig | 10 +++++----- Test/FormLayoutTestCase.php | 2 -- Tests/Extension/AbstractBootstrap3LayoutTestCase.php | 4 ++-- Tests/Extension/AbstractLayoutTestCase.php | 4 ++-- .../Extension/Fixtures/templates/form/theme.html.twig | 2 +- .../Fixtures/templates/form/theme_extends.html.twig | 2 +- .../Fixtures/templates/form/theme_use.html.twig | 2 +- Tests/Extension/FormExtensionBootstrap3LayoutTest.php | 2 +- Tests/Extension/FormExtensionBootstrap4LayoutTest.php | 2 +- Tests/Extension/FormExtensionBootstrap5LayoutTest.php | 2 +- Tests/Extension/FormExtensionDivLayoutTest.php | 2 +- 11 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Resources/views/Form/form_div_layout.html.twig b/Resources/views/Form/form_div_layout.html.twig index 29cfc2dc..02628b5a 100644 --- a/Resources/views/Form/form_div_layout.html.twig +++ b/Resources/views/Form/form_div_layout.html.twig @@ -14,7 +14,7 @@ {# Attribute "required" is not supported #} {%- set required = false -%} {%- endif -%} - + {%- endblock form_widget_simple -%} {%- block form_widget_compound -%} @@ -91,11 +91,11 @@ {%- endblock choice_widget_options -%} {%- block checkbox_widget -%} - + {%- endblock checkbox_widget -%} {%- block radio_widget -%} - + {%- endblock radio_widget -%} {%- block datetime_widget -%} @@ -402,7 +402,7 @@ {%- endif -%} {%- if form_method != method -%} - + {%- endif -%} {%- endblock form_start -%} @@ -440,7 +440,7 @@ {%- endif -%} {%- if form_method != method -%} - + {%- endif -%} {% endif -%} {% endblock form_rest %} diff --git a/Test/FormLayoutTestCase.php b/Test/FormLayoutTestCase.php index 71a71530..1fdd83c9 100644 --- a/Test/FormLayoutTestCase.php +++ b/Test/FormLayoutTestCase.php @@ -52,8 +52,6 @@ protected function assertMatchesXpath($html, $expression, $count = 1): void { $dom = new \DOMDocument('UTF-8'); - $html = preg_replace('/(]+)(?/', '$1/>', $html); - try { // Wrap in node so we can load HTML with multiple tags at // the top level diff --git a/Tests/Extension/AbstractBootstrap3LayoutTestCase.php b/Tests/Extension/AbstractBootstrap3LayoutTestCase.php index 5b02b695..08a026fe 100644 --- a/Tests/Extension/AbstractBootstrap3LayoutTestCase.php +++ b/Tests/Extension/AbstractBootstrap3LayoutTestCase.php @@ -2797,7 +2797,7 @@ public function testWidgetAttributes() $html = $this->renderWidget($form->createView()); // compare plain HTML to check the whitespace - $this->assertSame('', $html); + $this->assertSame('', $html); } public function testWidgetAttributeNameRepeatedIfTrue() @@ -2809,7 +2809,7 @@ public function testWidgetAttributeNameRepeatedIfTrue() $html = $this->renderWidget($form->createView()); // foo="foo" - $this->assertSame('', $html); + $this->assertSame('', $html); } public function testButtonAttributes() diff --git a/Tests/Extension/AbstractLayoutTestCase.php b/Tests/Extension/AbstractLayoutTestCase.php index 6d98620d..f340b066 100644 --- a/Tests/Extension/AbstractLayoutTestCase.php +++ b/Tests/Extension/AbstractLayoutTestCase.php @@ -2448,7 +2448,7 @@ public function testWidgetAttributes() $html = $this->renderWidget($form->createView()); // compare plain HTML to check the whitespace - $this->assertSame('', $html); + $this->assertSame('', $html); } public function testWidgetAttributeNameRepeatedIfTrue() @@ -2460,7 +2460,7 @@ public function testWidgetAttributeNameRepeatedIfTrue() $html = $this->renderWidget($form->createView()); // foo="foo" - $this->assertSame('', $html); + $this->assertSame('', $html); } public function testWidgetAttributeHiddenIfFalse() diff --git a/Tests/Extension/Fixtures/templates/form/theme.html.twig b/Tests/Extension/Fixtures/templates/form/theme.html.twig index 3ec513a4..e8816be9 100644 --- a/Tests/Extension/Fixtures/templates/form/theme.html.twig +++ b/Tests/Extension/Fixtures/templates/form/theme.html.twig @@ -1,4 +1,4 @@ {% block form_widget_simple %} {%- set type = type|default('text') -%} - + {%- endblock form_widget_simple %} diff --git a/Tests/Extension/Fixtures/templates/form/theme_extends.html.twig b/Tests/Extension/Fixtures/templates/form/theme_extends.html.twig index 2b9118a2..501b555e 100644 --- a/Tests/Extension/Fixtures/templates/form/theme_extends.html.twig +++ b/Tests/Extension/Fixtures/templates/form/theme_extends.html.twig @@ -2,5 +2,5 @@ {% block form_widget_simple %} {%- set type = type|default('text') -%} - + {%- endblock form_widget_simple %} diff --git a/Tests/Extension/Fixtures/templates/form/theme_use.html.twig b/Tests/Extension/Fixtures/templates/form/theme_use.html.twig index e05de5ac..37150734 100644 --- a/Tests/Extension/Fixtures/templates/form/theme_use.html.twig +++ b/Tests/Extension/Fixtures/templates/form/theme_use.html.twig @@ -2,5 +2,5 @@ {% block form_widget_simple %} {%- set type = type|default('text') -%} - + {%- endblock form_widget_simple %} diff --git a/Tests/Extension/FormExtensionBootstrap3LayoutTest.php b/Tests/Extension/FormExtensionBootstrap3LayoutTest.php index 90a17563..7c3742a7 100644 --- a/Tests/Extension/FormExtensionBootstrap3LayoutTest.php +++ b/Tests/Extension/FormExtensionBootstrap3LayoutTest.php @@ -71,7 +71,7 @@ public function testMoneyWidgetInIso() $this->assertSame(<<<'HTML'
-
+ HTML , trim($this->renderWidget($view))); } diff --git a/Tests/Extension/FormExtensionBootstrap4LayoutTest.php b/Tests/Extension/FormExtensionBootstrap4LayoutTest.php index bffebe3f..5fdec71d 100644 --- a/Tests/Extension/FormExtensionBootstrap4LayoutTest.php +++ b/Tests/Extension/FormExtensionBootstrap4LayoutTest.php @@ -76,7 +76,7 @@ public function testMoneyWidgetInIso() $this->assertSame(<<<'HTML'
-
+ HTML , trim($this->renderWidget($view))); } diff --git a/Tests/Extension/FormExtensionBootstrap5LayoutTest.php b/Tests/Extension/FormExtensionBootstrap5LayoutTest.php index e7e537ac..ced0fe60 100644 --- a/Tests/Extension/FormExtensionBootstrap5LayoutTest.php +++ b/Tests/Extension/FormExtensionBootstrap5LayoutTest.php @@ -75,7 +75,7 @@ public function testMoneyWidgetInIso() ->createView(); self::assertSame(<<<'HTML' -
+
HTML , trim($this->renderWidget($view))); } diff --git a/Tests/Extension/FormExtensionDivLayoutTest.php b/Tests/Extension/FormExtensionDivLayoutTest.php index cf76f9ee..ad2627a2 100644 --- a/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/Tests/Extension/FormExtensionDivLayoutTest.php @@ -156,7 +156,7 @@ public function testMoneyWidgetInIso() ->createView() ; - $this->assertSame('€ ', $this->renderWidget($view)); + $this->assertSame('€ ', $this->renderWidget($view)); } public function testHelpAttr() From e8c1ca7272cfb84a22743bfba9ecceba40190bc7 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 29 Jan 2024 11:00:25 +0100 Subject: [PATCH 2/4] separate child and parent context in NotificationEmail on writes --- Mime/NotificationEmail.php | 17 ++++++++++ Tests/Mime/NotificationEmailTest.php | 50 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/Mime/NotificationEmail.php b/Mime/NotificationEmail.php index 67173a8a..e8b4a736 100644 --- a/Mime/NotificationEmail.php +++ b/Mime/NotificationEmail.php @@ -178,6 +178,23 @@ public function getHtmlTemplate(): ?string return '@email/'.$this->theme.'/notification/body.html.twig'; } + public function context(array $context) + { + $parentContext = []; + + foreach ($context as $key => $value) { + if (\array_key_exists($key, $this->context)) { + $this->context[$key] = $value; + } else { + $parentContext[$key] = $value; + } + } + + parent::context($parentContext); + + return $this; + } + public function getContext(): array { return array_merge($this->context, parent::getContext()); diff --git a/Tests/Mime/NotificationEmailTest.php b/Tests/Mime/NotificationEmailTest.php index ceafea1b..71ced84f 100644 --- a/Tests/Mime/NotificationEmailTest.php +++ b/Tests/Mime/NotificationEmailTest.php @@ -128,4 +128,54 @@ public function testPublicMailSubject() $headers = $email->getPreparedHeaders(); $this->assertSame('Foo', $headers->get('Subject')->getValue()); } + + public function testContext() + { + $email = new NotificationEmail(); + $email->context(['some' => 'context']); + + $this->assertSame([ + 'importance' => NotificationEmail::IMPORTANCE_LOW, + 'content' => '', + 'exception' => false, + 'action_text' => null, + 'action_url' => null, + 'markdown' => false, + 'raw' => false, + 'footer_text' => 'Notification e-mail sent by Symfony', + 'some' => 'context', + ], $email->getContext()); + + $context = $email->getContext(); + $context['foo'] = 'bar'; + $email->context($context); + + $this->assertSame([ + 'importance' => NotificationEmail::IMPORTANCE_LOW, + 'content' => '', + 'exception' => false, + 'action_text' => null, + 'action_url' => null, + 'markdown' => false, + 'raw' => false, + 'footer_text' => 'Notification e-mail sent by Symfony', + 'some' => 'context', + 'foo' => 'bar', + ], $email->getContext()); + + $email->action('Action Text', 'Action URL'); + + $this->assertSame([ + 'importance' => NotificationEmail::IMPORTANCE_LOW, + 'content' => '', + 'exception' => false, + 'action_text' => 'Action Text', + 'action_url' => 'Action URL', + 'markdown' => false, + 'raw' => false, + 'footer_text' => 'Notification e-mail sent by Symfony', + 'some' => 'context', + 'foo' => 'bar', + ], $email->getContext()); + } } From 1127292134775bfc79917c6295b1dbb0396f2d2e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 29 Jan 2024 15:59:05 +0100 Subject: [PATCH 3/4] Add missing return type --- Mime/NotificationEmail.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Mime/NotificationEmail.php b/Mime/NotificationEmail.php index e8b4a736..2a661445 100644 --- a/Mime/NotificationEmail.php +++ b/Mime/NotificationEmail.php @@ -178,6 +178,9 @@ public function getHtmlTemplate(): ?string return '@email/'.$this->theme.'/notification/body.html.twig'; } + /** + * @return $this + */ public function context(array $context) { $parentContext = []; From 98e88cd0a9607d8e5c33778371e8c0508f75f86d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 29 Jan 2024 16:11:35 +0100 Subject: [PATCH 4/4] Fix merge --- Tests/Mime/NotificationEmailTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Mime/NotificationEmailTest.php b/Tests/Mime/NotificationEmailTest.php index e7ac5b13..979f2791 100644 --- a/Tests/Mime/NotificationEmailTest.php +++ b/Tests/Mime/NotificationEmailTest.php @@ -142,7 +142,7 @@ public function testContext() 'action_url' => null, 'markdown' => false, 'raw' => false, - 'footer_text' => 'Notification e-mail sent by Symfony', + 'footer_text' => 'Notification email sent by Symfony', 'some' => 'context', ], $email->getContext()); @@ -158,7 +158,7 @@ public function testContext() 'action_url' => null, 'markdown' => false, 'raw' => false, - 'footer_text' => 'Notification e-mail sent by Symfony', + 'footer_text' => 'Notification email sent by Symfony', 'some' => 'context', 'foo' => 'bar', ], $email->getContext()); @@ -173,7 +173,7 @@ public function testContext() 'action_url' => 'Action URL', 'markdown' => false, 'raw' => false, - 'footer_text' => 'Notification e-mail sent by Symfony', + 'footer_text' => 'Notification email sent by Symfony', 'some' => 'context', 'foo' => 'bar', ], $email->getContext());