From a857cb6cc9d6aee4ac43f45e0063c39d9b6f5799 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 28 May 2025 16:37:45 +0200
Subject: [PATCH] Bug 40018: Remove warnings from Koha/Template/Plugin/Koha.t
Content-Type: text/plain; charset=utf-8
Because we still use CGI::Session (bug 17427), we need to mock
CGI::Session to remove those 2 warnings
rollback ineffective with AutoCommit enabled
Test plan:
Run the tests after this patch, it should be green
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
t/db_dependent/Koha/Template/Plugin/Koha.t | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/t/db_dependent/Koha/Template/Plugin/Koha.t b/t/db_dependent/Koha/Template/Plugin/Koha.t
index 4cb1de7e8a..91cfed59a7 100755
--- a/t/db_dependent/Koha/Template/Plugin/Koha.t
+++ b/t/db_dependent/Koha/Template/Plugin/Koha.t
@@ -17,10 +17,12 @@
use Modern::Perl;
-use Test::More tests => 2;
+use Test::More tests => 3;
use Template::Context;
use Template::Stash;
+use Test::MockModule;
+use Test::NoWarnings;
use C4::Auth;
use Koha::Cache::Memory::Lite;
@@ -29,22 +31,26 @@ use Koha::Template::Plugin::Koha;
my $schema = Koha::Database->new->schema;
+my $session_id = 42;
+my $cgi_session = Test::MockModule->new('CGI::Session');
+$cgi_session->mock( 'load', sub { return bless { id => $session_id }, 'CGI::Session' } );
+$cgi_session->mock( 'new', sub { return bless { id => $session_id }, 'CGI::Session' } );
+$cgi_session->mock( 'param', sub { return $session_id } );
+
subtest 'GenerateCSRF() tests' => sub {
plan tests => 1;
$schema->storage->txn_begin;
- my $session = C4::Auth::get_session('');
-
- my $stash = Template::Stash->new( { sessionID => $session->id } );
+ my $stash = Template::Stash->new( { sessionID => $session_id } );
my $context = Template::Context->new( { STASH => $stash } );
my $plugin = Koha::Template::Plugin::Koha->new($context);
my $token = $plugin->GenerateCSRF();
- ok( Koha::Token->new->check_csrf( { session_id => $session->id, token => $token } ) );
+ ok( Koha::Token->new->check_csrf( { session_id => $session_id, token => $token } ) );
$schema->storage->txn_rollback;
};
@@ -54,9 +60,7 @@ subtest 'GenerateCSRF - New CSRF token generated every time we need one' => sub
$schema->storage->txn_begin;
- my $session = C4::Auth::get_session('');
-
- my $stash = Template::Stash->new( { sessionID => $session->id } );
+ my $stash = Template::Stash->new( { sessionID => $session_id } );
my $context = Template::Context->new( { STASH => $stash } );
my $plugin = Koha::Template::Plugin::Koha->new($context);
--
2.39.5