Bug 18811: [QA Follow-up] Add tests for Koha::Authority::Subfields/Tags
[koha.git] / t / db_dependent / Authority / MergeRequests.t
blobbba791992a06c6045e480f830524542e0443af77
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use Test::More tests => 1;
6 use Koha::Authority::MergeRequest;
7 use Koha::Authority::MergeRequests;
8 use Koha::Database;
9 use Koha::DateUtils qw/dt_from_string/;
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
14 subtest "Tests for cron_cleanup" => sub {
15 plan tests => 3;
17 my $dt = dt_from_string;
18 $dt->subtract( hours => 2 );
19 my $req1 = Koha::Authority::MergeRequest->new({
20 authid => 1,
21 done => 2,
22 timestamp => $dt,
23 })->store;
25 $dt->subtract( days => 30 );
26 my $req2 = Koha::Authority::MergeRequest->new({
27 authid => 2,
28 done => 1,
29 timestamp => $dt,
30 })->store;
32 # Now test two cleanup calls
33 # First call should only remove req2; second call should reset req1
34 Koha::Authority::MergeRequests->cron_cleanup({ reset_hours => 3 });
35 $req1->discard_changes; # requery
36 is( $req1->done, 2, 'My request was not touched' );
37 $req2->discard_changes; # requery
38 is( $req2->in_storage, 0, 'Second request removed' );
39 Koha::Authority::MergeRequests->cron_cleanup({ reset_hours => 1 });
40 $req1->discard_changes; # requery
41 is( $req1->done, 0, 'Yes, we got a reset' );
44 $schema->storage->txn_rollback;