From 829ef649c0932f21360a7540cc667a674e6b4d8c Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 18 Dec 2023 08:36:12 +0100 Subject: [PATCH] Bug 35070: Add test verifying plugins cannot override core templates Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer (cherry picked from commit 2233c230b2dc01dfd4e3624ba846cad252988d0e) Signed-off-by: Fridolin Somers --- .../Koha/Plugins/TemplateIncludePathHook.t | 22 ++++++++++++++++--- .../Koha/Plugin/Test/inc/csrf-token.inc | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 t/lib/plugins/Koha/Plugin/Test/inc/csrf-token.inc diff --git a/t/db_dependent/Koha/Plugins/TemplateIncludePathHook.t b/t/db_dependent/Koha/Plugins/TemplateIncludePathHook.t index 0c260c4bd7..9ac1540967 100755 --- a/t/db_dependent/Koha/Plugins/TemplateIncludePathHook.t +++ b/t/db_dependent/Koha/Plugins/TemplateIncludePathHook.t @@ -16,7 +16,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::MockModule; use Test::Warn; @@ -51,7 +51,23 @@ subtest 'template_include_paths' => sub { $template->process( \"[% INCLUDE test.inc %]", {}, \$output ) || die $template->error(); is( $output, 'included content' ); - $schema->storage->txn_commit; + $schema->storage->txn_rollback; +}; + +subtest 'cannot override core templates' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + Koha::Plugins->new->InstallPlugins(); + Koha::Plugin::Test->new->enable; + + require C4::Templates; + my $c4_template = C4::Templates::gettemplate( 'intranet-main.tt', 'intranet' ); + my $template = $c4_template->{TEMPLATE}; + my $output = ''; + $template->process( \"[% INCLUDE 'csrf-token.inc' %]", {}, \$output ) || die $template->error(); + unlike( $output, qr/OVERRIDE/ ); - #Koha::Plugins::Methods->delete; + $schema->storage->txn_rollback; }; diff --git a/t/lib/plugins/Koha/Plugin/Test/inc/csrf-token.inc b/t/lib/plugins/Koha/Plugin/Test/inc/csrf-token.inc new file mode 100644 index 0000000000..a48f8faa07 --- /dev/null +++ b/t/lib/plugins/Koha/Plugin/Test/inc/csrf-token.inc @@ -0,0 +1,2 @@ +[%# This file has the same name as a core template. This is used to test that plugins cannot override core templates %] +[%~ 'OVERRIDE' ~%] -- 2.39.5