Lines 19-27
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 12; |
22 |
use Test::More tests => 13; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
|
24 |
|
|
|
25 |
use List::MoreUtils qw(any); |
26 |
|
25 |
use Koha::Database; |
27 |
use Koha::Database; |
26 |
use Koha::BackgroundJobs; |
28 |
use Koha::BackgroundJobs; |
27 |
use Koha::DateUtils qw( dt_from_string ); |
29 |
use Koha::DateUtils qw( dt_from_string ); |
Lines 31-37
use t::lib::Mocks;
Link Here
|
31 |
use t::lib::Dates; |
33 |
use t::lib::Dates; |
32 |
use t::lib::Koha::BackgroundJob::BatchTest; |
34 |
use t::lib::Koha::BackgroundJob::BatchTest; |
33 |
|
35 |
|
34 |
my $schema = Koha::Database->new->schema; |
36 |
my $builder = t::lib::TestBuilder->new; |
|
|
37 |
my $schema = Koha::Database->new->schema; |
35 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
36 |
|
39 |
|
37 |
t::lib::Mocks::mock_userenv; |
40 |
t::lib::Mocks::mock_userenv; |
Lines 91-93
is_deeply(
Link Here
|
91 |
is_deeply( $new_job->additional_report(), {} ); |
94 |
is_deeply( $new_job->additional_report(), {} ); |
92 |
|
95 |
|
93 |
$schema->storage->txn_rollback; |
96 |
$schema->storage->txn_rollback; |
94 |
- |
97 |
|
|
|
98 |
subtest 'filter_by_current() tests' => sub { |
99 |
|
100 |
plan tests => 4; |
101 |
|
102 |
$schema->storage->txn_begin; |
103 |
|
104 |
my $job_new = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'new' } } ); |
105 |
my $job_cancelled = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'cancelled' } } ); |
106 |
my $job_failed = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'failed' } } ); |
107 |
my $job_finished = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'finished' } } ); |
108 |
|
109 |
my $rs = Koha::BackgroundJobs->search( |
110 |
{ |
111 |
id => [ $job_new->id, $job_cancelled->id, $job_failed->id, $job_finished->id ] |
112 |
} |
113 |
); |
114 |
|
115 |
is( $rs->count, 4, '4 jobs in resultset' ); |
116 |
ok( any {$_->status eq 'new'} @{$rs->as_list}, "There is a 'new' job" ); |
117 |
|
118 |
$rs = $rs->filter_by_current; |
119 |
|
120 |
is( $rs->count, 1, 'Only 1 job in filtered resultset' ); |
121 |
is( $rs->next->status, 'new', "The only job in resultset is 'new'" ); |
122 |
|
123 |
$schema->storage->txn_rollback; |
124 |
}; |