From b7999c2d68315a56cd2f5d1cd39ca420b98e80fb Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 8 Nov 2024 12:36:21 +0100 Subject: [PATCH 1/3] Add test examples for inclue to render --- .../IncludeToRenderFunctionRule.fixed.twig | 17 +++++++++++ .../IncludeToRenderFunctionRuleTest.php | 29 +++++++++++++++++++ .../IncludeToRenderFunctionRuleTest.twig | 17 +++++++++++ 3 files changed, 63 insertions(+) create mode 100644 tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig create mode 100644 tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php create mode 100644 tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.twig diff --git a/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig new file mode 100644 index 00000000..15e58f23 --- /dev/null +++ b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig @@ -0,0 +1,17 @@ +{{ render('template.html', _context) }} +{{ render('template.html', {'foo': 'bar'}|merge(_context)) }} +{{ render('template.html', {'foo': 'bar'}|merge(_context), true) }} +{{ render('template.html', {'foo': 'bar'}|merge(_context), true, true) }} +{{ render('template.html', _context) }} + +{{ render(['template_a.html', 'template_b.html'], _context) }} +{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}|merge(_context)) }} +{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}|merge(_context), true) }} +{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}|merge(_context), true, true) }} +{{ render(['template_a.html', 'template_b.html'], _context) }} + +{{ render(['template_a.html', 'template_b.html']) }} +{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}) }} +{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true) }} +{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true, true) }} +{{ render(['template_a.html', 'template_b.html']) }} diff --git a/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php new file mode 100644 index 00000000..af5bd855 --- /dev/null +++ b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.php @@ -0,0 +1,29 @@ +checkRule( + [ + new IncludeToRenderFunctionRule(), + // Extra rule for a better diff + new PunctuationSpacingRule(), + ], + [ + 'IncludeToRender.Error:13:4' => 'Include function must be used instead of include tag.', + 'IncludeToRender.Error:14:4' => 'Include function must be used instead of include tag.', + 'IncludeToRender.Error:15:5' => 'Include function must be used instead of include tag.', + 'IncludeToRender.Error:16:5' => 'Include function must be used instead of include tag.', + ] + ); + } +} diff --git a/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.twig b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.twig new file mode 100644 index 00000000..fcc68ad1 --- /dev/null +++ b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRuleTest.twig @@ -0,0 +1,17 @@ +{{ include('template.html') }} +{{ include('template.html', {'foo': 'bar'}, true) }} +{{ include('template.html', {'foo': 'bar'}, true, true) }} +{{ include('template.html', {'foo': 'bar'}, true, true, true) }} +{{ include('template.html', with_context = true) }} + +{{ include(['template_a.html', 'template_b.html']) }} +{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true) }} +{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true, true) }} +{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true, true, true) }} +{{ include(['template_a.html', 'template_b.html'], with_context = true) }} + +{{ include(['template_a.html', 'template_b.html'], with_context = false) }} +{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, false) }} +{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, false, true) }} +{{ include(['template_a.html', 'template_b.html'], {'foo': 'bar'}, false, true, true) }} +{{ include(['template_a.html', 'template_b.html'], with_context = true) }} From 4911033bfbcbe99d374cd17a269d4832fd295186 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Fri, 8 Nov 2024 12:41:35 +0100 Subject: [PATCH 2/3] Fix own defined variables should overwrite _context --- .../IncludeToRenderFunctionRule.fixed.twig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig index 15e58f23..21fadd0d 100644 --- a/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig +++ b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig @@ -1,13 +1,13 @@ {{ render('template.html', _context) }} -{{ render('template.html', {'foo': 'bar'}|merge(_context)) }} -{{ render('template.html', {'foo': 'bar'}|merge(_context), true) }} -{{ render('template.html', {'foo': 'bar'}|merge(_context), true, true) }} +{{ render('template.html', {..._context, 'foo': 'bar'}) }} +{{ render('template.html', {..._context, 'foo': 'bar'}, true) }} +{{ render('template.html', {..._context, 'foo': 'bar'}, true, true) }} {{ render('template.html', _context) }} {{ render(['template_a.html', 'template_b.html'], _context) }} -{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}|merge(_context)) }} -{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}|merge(_context), true) }} -{{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}|merge(_context), true, true) }} +{{ render(['template_a.html', 'template_b.html'], {..._context, 'foo': 'bar'}) }} +{{ render(['template_a.html', 'template_b.html'], {..._context, 'foo': 'bar'}, true) }} +{{ render(['template_a.html', 'template_b.html'], {..._context, 'foo': 'bar'}, true, true) }} {{ render(['template_a.html', 'template_b.html'], _context) }} {{ render(['template_a.html', 'template_b.html']) }} From 02d55f05de88d0275032cf4196ef74a88a020a1b Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Sat, 9 Nov 2024 11:21:00 +0100 Subject: [PATCH 3/3] Update tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon André --- .../IncludeToRender/IncludeToRenderFunctionRule.fixed.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig index 21fadd0d..d5035fb4 100644 --- a/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig +++ b/tests/Rules/Function/IncludeToRender/IncludeToRenderFunctionRule.fixed.twig @@ -14,4 +14,4 @@ {{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}) }} {{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true) }} {{ render(['template_a.html', 'template_b.html'], {'foo': 'bar'}, true, true) }} -{{ render(['template_a.html', 'template_b.html']) }} +{{ render(['template_a.html', 'template_b.html'], _context) }}