|
Lines 17-31
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 3; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
|
22 |
|
| 23 |
use t::lib::TestBuilder; |
23 |
use Koha::ArticleRequest::Status; |
| 24 |
use t::lib::Mocks; |
|
|
| 25 |
|
| 26 |
use Koha::ArticleRequests; |
24 |
use Koha::ArticleRequests; |
| 27 |
use Koha::Database; |
25 |
use Koha::Database; |
| 28 |
|
26 |
|
|
|
27 |
use t::lib::Mocks; |
| 28 |
use t::lib::TestBuilder; |
| 29 |
|
| 29 |
my $schema = Koha::Database->new->schema; |
30 |
my $schema = Koha::Database->new->schema; |
| 30 |
my $builder = t::lib::TestBuilder->new; |
31 |
my $builder = t::lib::TestBuilder->new; |
| 31 |
|
32 |
|
|
Lines 77-79
subtest 'requested() tests' => sub {
Link Here
|
| 77 |
|
78 |
|
| 78 |
$schema->storage->txn_rollback; |
79 |
$schema->storage->txn_rollback; |
| 79 |
}; |
80 |
}; |
| 80 |
- |
81 |
|
|
|
82 |
subtest 'filter_by_current() tests' => sub { |
| 83 |
|
| 84 |
plan tests => 1; |
| 85 |
|
| 86 |
$schema->storage->txn_begin; |
| 87 |
|
| 88 |
my $ar_requested = $builder->build_object( |
| 89 |
{ |
| 90 |
class => 'Koha::ArticleRequests', |
| 91 |
value => { status => Koha::ArticleRequest::Status::Requested } |
| 92 |
} |
| 93 |
); |
| 94 |
my $ar_pending = $builder->build_object( |
| 95 |
{ |
| 96 |
class => 'Koha::ArticleRequests', |
| 97 |
value => { status => Koha::ArticleRequest::Status::Pending } |
| 98 |
} |
| 99 |
); |
| 100 |
my $ar_processing = $builder->build_object( |
| 101 |
{ |
| 102 |
class => 'Koha::ArticleRequests', |
| 103 |
value => { status => Koha::ArticleRequest::Status::Processing } |
| 104 |
} |
| 105 |
); |
| 106 |
my $ar_completed = $builder->build_object( |
| 107 |
{ |
| 108 |
class => 'Koha::ArticleRequests', |
| 109 |
value => { status => Koha::ArticleRequest::Status::Completed } |
| 110 |
} |
| 111 |
); |
| 112 |
my $ar_cancelled = $builder->build_object( |
| 113 |
{ |
| 114 |
class => 'Koha::ArticleRequests', |
| 115 |
value => { status => Koha::ArticleRequest::Status::Canceled } |
| 116 |
} |
| 117 |
); |
| 118 |
|
| 119 |
my $article_requests = Koha::ArticleRequests->search( |
| 120 |
{ |
| 121 |
id => [ |
| 122 |
$ar_requested->id, $ar_pending->id, $ar_processing->id, |
| 123 |
$ar_completed->id, $ar_cancelled->id |
| 124 |
] |
| 125 |
} |
| 126 |
); |
| 127 |
|
| 128 |
my $current_article_requests = $article_requests->filter_by_current; |
| 129 |
|
| 130 |
is( $current_article_requests->count, 3, 'Count is correct' ); |
| 131 |
|
| 132 |
$schema->storage->txn_rollback; |
| 133 |
}; |
| 134 |
|
| 135 |
subtest 'filter_by_current() tests' => sub { |
| 136 |
|
| 137 |
plan tests => 1; |
| 138 |
|
| 139 |
$schema->storage->txn_begin; |
| 140 |
|
| 141 |
my $ar_requested = $builder->build_object( |
| 142 |
{ |
| 143 |
class => 'Koha::ArticleRequests', |
| 144 |
value => { status => Koha::ArticleRequest::Status::Requested } |
| 145 |
} |
| 146 |
); |
| 147 |
my $ar_pending = $builder->build_object( |
| 148 |
{ |
| 149 |
class => 'Koha::ArticleRequests', |
| 150 |
value => { status => Koha::ArticleRequest::Status::Pending } |
| 151 |
} |
| 152 |
); |
| 153 |
my $ar_processing = $builder->build_object( |
| 154 |
{ |
| 155 |
class => 'Koha::ArticleRequests', |
| 156 |
value => { status => Koha::ArticleRequest::Status::Processing } |
| 157 |
} |
| 158 |
); |
| 159 |
my $ar_completed = $builder->build_object( |
| 160 |
{ |
| 161 |
class => 'Koha::ArticleRequests', |
| 162 |
value => { status => Koha::ArticleRequest::Status::Completed } |
| 163 |
} |
| 164 |
); |
| 165 |
my $ar_cancelled = $builder->build_object( |
| 166 |
{ |
| 167 |
class => 'Koha::ArticleRequests', |
| 168 |
value => { status => Koha::ArticleRequest::Status::Canceled } |
| 169 |
} |
| 170 |
); |
| 171 |
|
| 172 |
my $article_requests = Koha::ArticleRequests->search( |
| 173 |
{ |
| 174 |
id => [ |
| 175 |
$ar_requested->id, $ar_pending->id, $ar_processing->id, |
| 176 |
$ar_completed->id, $ar_cancelled->id |
| 177 |
] |
| 178 |
} |
| 179 |
); |
| 180 |
|
| 181 |
my $finished_article_requests = $article_requests->filter_by_finished; |
| 182 |
|
| 183 |
is( $finished_article_requests->count, 2, 'Count is correct' ); |
| 184 |
|
| 185 |
$schema->storage->txn_rollback; |
| 186 |
}; |