|
Lines 19-25
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use POSIX qw(strftime); |
20 |
use POSIX qw(strftime); |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 54; |
22 |
use Test::More tests => 55; |
| 23 |
|
23 |
|
| 24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
| 25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
|
Lines 31-36
use Koha::Patron;
Link Here
|
| 31 |
use Koha::Library::Group; |
31 |
use Koha::Library::Group; |
| 32 |
use Koha::CirculationRules; |
32 |
use Koha::CirculationRules; |
| 33 |
use Koha::Caches; |
33 |
use Koha::Caches; |
|
|
34 |
use Koha::DateUtils qw( dt_from_string ); |
| 35 |
use Try::Tiny; |
| 34 |
|
36 |
|
| 35 |
BEGIN { |
37 |
BEGIN { |
| 36 |
use_ok('Koha::ArticleRequest'); |
38 |
use_ok('Koha::ArticleRequest'); |
|
Lines 252-255
subtest 'may_article_request' => sub {
Link Here
|
| 252 |
$cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); |
254 |
$cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); |
| 253 |
}; |
255 |
}; |
| 254 |
|
256 |
|
|
|
257 |
|
| 258 |
subtest 'article request limit' => sub { |
| 259 |
plan tests => 12; |
| 260 |
|
| 261 |
t::lib::Mocks::mock_preference('ArticleRequests', 1); |
| 262 |
|
| 263 |
my $item = $builder->build_sample_item; |
| 264 |
|
| 265 |
my $category = $builder->build_object( |
| 266 |
{ |
| 267 |
class => 'Koha::Patron::Categories', |
| 268 |
value => { |
| 269 |
article_request_limit => 1 |
| 270 |
} |
| 271 |
} |
| 272 |
); |
| 273 |
my $patron = $builder->build_object( |
| 274 |
{ |
| 275 |
class => 'Koha::Patrons', |
| 276 |
value => { |
| 277 |
categorycode => $category->categorycode |
| 278 |
}, |
| 279 |
} |
| 280 |
); |
| 281 |
$patron->article_requests->delete(); |
| 282 |
|
| 283 |
is($patron->can_request_article, 1, 'Patron can request more articles'); |
| 284 |
|
| 285 |
my $article_request_1 = Koha::ArticleRequest->new( |
| 286 |
{ |
| 287 |
borrowernumber => $patron->id, |
| 288 |
biblionumber => $item->biblionumber, |
| 289 |
itemnumber => $item->itemnumber, |
| 290 |
title => 'an article request', |
| 291 |
} |
| 292 |
)->store(); |
| 293 |
|
| 294 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
| 295 |
is($patron->article_requests->count, 1, 'There is one current article request'); |
| 296 |
|
| 297 |
try { |
| 298 |
Koha::ArticleRequest->new( |
| 299 |
{ |
| 300 |
borrowernumber => $patron->id, |
| 301 |
biblionumber => $item->biblionumber, |
| 302 |
itemnumber => $item->itemnumber, |
| 303 |
title => 'an second article request', |
| 304 |
} |
| 305 |
)->store(); |
| 306 |
} |
| 307 |
catch { |
| 308 |
is(ref($_), 'Koha::Exceptions::ArticleRequest::LimitReached', 'Limit reached thrown'); |
| 309 |
}; |
| 310 |
|
| 311 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
| 312 |
is($patron->article_requests->count, 1, 'There is still one article request'); |
| 313 |
|
| 314 |
$article_request_1->created_on(dt_from_string->add(days => -1))->store(); |
| 315 |
|
| 316 |
is($patron->can_request_article, 1, 'Patron can request more articles'); |
| 317 |
|
| 318 |
my $article_request_3 = Koha::ArticleRequest->new( |
| 319 |
{ |
| 320 |
borrowernumber => $patron->id, |
| 321 |
biblionumber => $item->biblionumber, |
| 322 |
itemnumber => $item->itemnumber, |
| 323 |
title => 'an third article request', |
| 324 |
} |
| 325 |
)->store(); |
| 326 |
|
| 327 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
| 328 |
is($patron->article_requests->count, 2, 'There are 2 article requests'); |
| 329 |
|
| 330 |
$article_request_3->cancel(); |
| 331 |
|
| 332 |
is($patron->can_request_article, 1, 'Patron can request more articles'); |
| 333 |
|
| 334 |
Koha::ArticleRequest->new( |
| 335 |
{ |
| 336 |
borrowernumber => $patron->id, |
| 337 |
biblionumber => $item->biblionumber, |
| 338 |
itemnumber => $item->itemnumber, |
| 339 |
title => 'an fourth article request', |
| 340 |
} |
| 341 |
)->store(); |
| 342 |
|
| 343 |
is($patron->can_request_article, 0, 'Patron cannot request more articles'); |
| 344 |
is($patron->article_requests->count, 3, 'There are 3 current article requests'); |
| 345 |
|
| 346 |
}; |
| 347 |
|
| 255 |
$schema->storage->txn_rollback(); |
348 |
$schema->storage->txn_rollback(); |
| 256 |
- |
|
|