From 0b337012573c48615e0098983bdc5153588cecf2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 27 Feb 2024 08:56:24 +0100 Subject: [PATCH] Bug 35955: Add tests Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- t/db_dependent/Koha/Template/Plugin/Koha.t | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Template/Plugin/Koha.t b/t/db_dependent/Koha/Template/Plugin/Koha.t index 98318bdd534..ff50b3580e0 100755 --- a/t/db_dependent/Koha/Template/Plugin/Koha.t +++ b/t/db_dependent/Koha/Template/Plugin/Koha.t @@ -17,12 +17,13 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Template::Context; use Template::Stash; use C4::Auth; +use Koha::Cache::Memory::Lite; use Koha::Database; use Koha::Template::Plugin::Koha; @@ -47,3 +48,30 @@ subtest 'GenerateCSRF() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'GenerateCSRF - New CSRF token generated everytime we need one' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my $session = C4::Auth::get_session(''); + + 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; + + is( $plugin->GenerateCSRF, $token, 'the token is cached and no new one generate' ); + + Koha::Cache::Memory::Lite->flush(); + + isnt( + $plugin->GenerateCSRF, $token, + 'new token generated after the cache is flushed' + ); + + $schema->storage->txn_rollback; + +}; -- 2.30.2