From e3dd4b367d815670ff14d8caf38c93e2cc5fb836 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 Content-Type: text/plain; charset=utf-8 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 --- t/db_dependent/Log.t | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t index 3267e08ebf..f84fb14265 100644 --- a/t/db_dependent/Log.t +++ b/t/db_dependent/Log.t @@ -1,33 +1,41 @@ #!/usr/bin/perl # # Copyright 2011 MJ Ray and software.coop -# This Koha test module is a stub! -# Add more tests here!!! +# +# This file is part of Koha. +# +# 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. +# +# 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"); @@ -155,4 +163,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.11.0