Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Authority / MergeRequests.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use Test::More tests => 1;
5
6 use Koha::Authority::MergeRequest;
7 use Koha::Authority::MergeRequests;
8 use Koha::Database;
9 use Koha::DateUtils qw/dt_from_string/;
10
11 my $schema  = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
13
14 subtest "Tests for cron_cleanup" => sub {
15     plan tests => 3;
16
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;
24
25     $dt->subtract( days => 30 );
26     my $req2 = Koha::Authority::MergeRequest->new({
27         authid => 2,
28         done => 1,
29         timestamp => $dt,
30     })->store;
31
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' );
42 };
43
44 $schema->storage->txn_rollback;