Commit d88c0803 authored by Marcel de Rooy's avatar Marcel de Rooy Committed by joubu

Bug 13287: (QA follow-up) Extend Suggestions.t for DelSuggestionsOlderThan

Adding a days>0 test in the sub with a POD line.
Specific subtest for this sub added in Suggestions.t.

Test plan:
Run t/db_dependent/Suggestions.t again.
Signed-off-by: default avatarMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: joubu's avatarJonathan Druart <jonathan.druart@bugs.koha-community.org>
parent b241555b
......@@ -588,12 +588,13 @@ sub DelSuggestion {
&DelSuggestionsOlderThan($days)
Delete all suggestions older than TODAY-$days , that have be accepted or rejected.
We do now allow a negative number. If you want to delete all suggestions, just use Koha::Suggestions->delete or so.
=cut
sub DelSuggestionsOlderThan {
my ($days) = @_;
return unless $days;
return unless $days && $days > 0;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
q{
......
......@@ -18,7 +18,7 @@
use Modern::Perl;
use DateTime::Duration;
use Test::More tests => 102;
use Test::More tests => 103;
use Test::Warn;
use t::lib::Mocks;
......@@ -29,9 +29,10 @@ use C4::Members;
use C4::Letters;
use C4::Budgets qw( AddBudgetPeriod AddBudget );
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Library;
use Koha::Libraries;
use Koha::Suggestions;
BEGIN {
use_ok('C4::Suggestions');
......@@ -382,4 +383,36 @@ subtest 'GetUnprocessedSuggestions' => sub {
is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
};
subtest 'DelSuggestionsOlderThan' => sub {
plan tests => 6;
Koha::Suggestions->delete;
# Add four suggestions; note that STATUS needs uppercase (FIXME)
my $d1 = output_pref({ dt => dt_from_string->add(days => -2), dateformat => 'sql' });
my $d2 = output_pref({ dt => dt_from_string->add(days => -4), dateformat => 'sql' });
my $sugg01 = $builder->build({ source => 'Suggestion', value => { date => $d1, STATUS => 'ASKED' }});
my $sugg02 = $builder->build({ source => 'Suggestion', value => { date => $d1, STATUS => 'CHECKED' }});
my $sugg03 = $builder->build({ source => 'Suggestion', value => { date => $d2, STATUS => 'ASKED' }});
my $sugg04 = $builder->build({ source => 'Suggestion', value => { date => $d2, STATUS => 'ACCEPTED' }});
# Test no parameter: should do nothing
C4::Suggestions::DelSuggestionsOlderThan();
is( Koha::Suggestions->count, 4, 'No suggestions deleted' );
# Test zero: should do nothing too
C4::Suggestions::DelSuggestionsOlderThan(0);
is( Koha::Suggestions->count, 4, 'No suggestions deleted again' );
# Test negative value
C4::Suggestions::DelSuggestionsOlderThan(-1);
is( Koha::Suggestions->count, 4, 'No suggestions deleted for -1' );
# Test positive values
C4::Suggestions::DelSuggestionsOlderThan(5);
is( Koha::Suggestions->count, 4, 'No suggestions>5d deleted' );
C4::Suggestions::DelSuggestionsOlderThan(3);
is( Koha::Suggestions->count, 3, '1 suggestions>3d deleted' );
C4::Suggestions::DelSuggestionsOlderThan(1);
is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' );
};
$schema->storage->txn_rollback;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment