From 135ab4c26ad8f32f4aed291578145b82574ab075 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 25 Oct 2019 07:32:56 +0000 Subject: [PATCH] Bug 21190: Add subtest to Log.t for GDPR logging Apart from a new subtest, doing some more cleanup: [1] Copyright statement [2] Removing the (unneeded) flush [3] Removing C4::Log from the BEGIN block; we seem to skip that nowadays. [4] $succes goes to the subtest, $schema and $dbh are global our vars. Not required but just what we should do if it would run under Plack. Test plan: Run t/db_dependent/Log.t Signed-off-by: Marcel de Rooy Signed-off-by: Jon Knight Signed-off-by: Michal Denar Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- t/db_dependent/Log.t | 52 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t index d24a405afd..ca8fa9e454 100644 --- a/t/db_dependent/Log.t +++ b/t/db_dependent/Log.t @@ -1,46 +1,39 @@ #!/usr/bin/perl # -# Copyright 2011 MJ Ray and software.coop -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. +# This file is part of Koha. # -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. # -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -# This Koha test module is a stub! -# Add more tests here!!! +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, see . use Modern::Perl; use Test::More tests => 5; use C4::Context; +use C4::Log; use Koha::Database; use Koha::DateUtils; use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog - -$| = 1; - -BEGIN { - use_ok('C4::Log'); -} -my $success; +use t::lib::TestBuilder; # Make sure we can rollback. -my $schema = Koha::Database->new->schema; +our $schema = Koha::Database->new->schema; $schema->storage->txn_begin; -my $dbh = C4::Context->dbh; +our $dbh = C4::Context->dbh; subtest 'Existing tests' => sub { plan tests => 6; + my $success; eval { # FIXME: are we sure there is an member number 1? logaction("MEMBERS","MODIFY",1,"test operation"); @@ -168,4 +161,17 @@ subtest 'GetLogs() respects interface filters' => sub { is( @{$logs}[0]->{ interface }, 'commandline', 'Interface correctly filtered (commandline)'); }; +subtest 'GDPR logging' => sub { + plan tests => 1; + + my $builder = t::lib::TestBuilder->new; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + t::lib::Mocks::mock_userenv({ patron => $patron }); + logaction( 'AUTH', 'FAILURE', $patron->id, '', 'opac' ); + my $logs = GetLogs( undef, undef, $patron->id, ['AUTH'], ['FAILURE'], $patron->id ); + is( @$logs, 1, 'We should find one auth failure for this patron' ); + +}; + $schema->storage->txn_rollback; -- 2.39.5