|
Lines 19-30
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 9; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
| 26 |
use Koha::Database; |
26 |
use Koha::Database; |
| 27 |
use Koha::DateUtils qw(dt_from_string); |
27 |
use Koha::DateUtils qw(dt_from_string); |
|
|
28 |
use Koha::ArticleRequests; |
| 28 |
use Koha::Patrons; |
29 |
use Koha::Patrons; |
| 29 |
use Koha::Patron::Relationships; |
30 |
use Koha::Patron::Relationships; |
| 30 |
|
31 |
|
|
Lines 716-718
subtest 'can_log_into() tests' => sub {
Link Here
|
| 716 |
|
717 |
|
| 717 |
$schema->storage->txn_rollback; |
718 |
$schema->storage->txn_rollback; |
| 718 |
}; |
719 |
}; |
| 719 |
- |
720 |
|
|
|
721 |
subtest 'can_request_article() tests' => sub { |
| 722 |
|
| 723 |
plan tests => 13; |
| 724 |
|
| 725 |
$schema->storage->txn_begin; |
| 726 |
|
| 727 |
t::lib::Mocks::mock_preference( 'ArticleRequests', 1 ); |
| 728 |
|
| 729 |
my $item = $builder->build_sample_item; |
| 730 |
|
| 731 |
my $category = $builder->build_object( |
| 732 |
{ |
| 733 |
class => 'Koha::Patron::Categories', |
| 734 |
value => { |
| 735 |
article_request_limit => 1 |
| 736 |
} |
| 737 |
} |
| 738 |
); |
| 739 |
my $patron = $builder->build_object( |
| 740 |
{ |
| 741 |
class => 'Koha::Patrons', |
| 742 |
value => { |
| 743 |
categorycode => $category->categorycode |
| 744 |
}, |
| 745 |
} |
| 746 |
); |
| 747 |
|
| 748 |
is( $patron->can_request_article, |
| 749 |
1, 'There are no AR, so patron can request more articles' ); |
| 750 |
|
| 751 |
my $article_request_1 = Koha::ArticleRequest->new( |
| 752 |
{ |
| 753 |
borrowernumber => $patron->id, |
| 754 |
biblionumber => $item->biblionumber, |
| 755 |
itemnumber => $item->itemnumber, |
| 756 |
title => 'an article request', |
| 757 |
} |
| 758 |
)->request; |
| 759 |
|
| 760 |
is( $patron->can_request_article, |
| 761 |
0, 'Limit is 1, so patron cannot request more articles' ); |
| 762 |
is( $patron->article_requests->count, |
| 763 |
1, 'There is one current article request' ); |
| 764 |
|
| 765 |
throws_ok { |
| 766 |
Koha::ArticleRequest->new( |
| 767 |
{ |
| 768 |
borrowernumber => $patron->id, |
| 769 |
biblionumber => $item->biblionumber, |
| 770 |
itemnumber => $item->itemnumber, |
| 771 |
title => 'a second article request', |
| 772 |
} |
| 773 |
)->request; |
| 774 |
} |
| 775 |
'Koha::Exceptions::ArticleRequest::LimitReached', |
| 776 |
'When limit was reached and we ask for a new AR, Limit reached is thrown'; |
| 777 |
|
| 778 |
is( $patron->can_request_article, |
| 779 |
0, 'There is still an AR, so patron cannot request more articles' ); |
| 780 |
is( $patron->article_requests->count, |
| 781 |
1, 'There is still one article request' ); |
| 782 |
|
| 783 |
$article_request_1->complete(); |
| 784 |
|
| 785 |
is( $patron->can_request_article, 0, |
| 786 |
'AR was completed but within one day, so patron cannot request more articles' |
| 787 |
); |
| 788 |
|
| 789 |
$article_request_1->updated_on( dt_from_string->add( days => -2 ) ) |
| 790 |
->store(); |
| 791 |
|
| 792 |
is( $patron->can_request_article, 1, |
| 793 |
'There are no completed AR within one day, so patron can request more articles' |
| 794 |
); |
| 795 |
|
| 796 |
my $article_request_3 = Koha::ArticleRequest->new( |
| 797 |
{ |
| 798 |
borrowernumber => $patron->id, |
| 799 |
biblionumber => $item->biblionumber, |
| 800 |
itemnumber => $item->itemnumber, |
| 801 |
title => 'a third article request', |
| 802 |
} |
| 803 |
)->request; |
| 804 |
|
| 805 |
is( $patron->can_request_article, |
| 806 |
0, 'A new AR was created, so patron cannot request more articles' ); |
| 807 |
is( $patron->article_requests->count, 2, 'There are 2 article requests' ); |
| 808 |
|
| 809 |
$article_request_3->cancel(); |
| 810 |
|
| 811 |
is( $patron->can_request_article, |
| 812 |
1, 'New AR was cancelled, so patron can request more articles' ); |
| 813 |
|
| 814 |
my $article_request_4 = Koha::ArticleRequest->new( |
| 815 |
{ |
| 816 |
borrowernumber => $patron->id, |
| 817 |
biblionumber => $item->biblionumber, |
| 818 |
itemnumber => $item->itemnumber, |
| 819 |
title => 'an fourth article request', |
| 820 |
} |
| 821 |
)->request; |
| 822 |
|
| 823 |
$article_request_4->updated_on( dt_from_string->add( days => -30 ) ) |
| 824 |
->store(); |
| 825 |
|
| 826 |
is( $patron->can_request_article, 0, |
| 827 |
'There is an old AR but not completed or cancelled, so patron cannot request more articles' |
| 828 |
); |
| 829 |
is( $patron->article_requests->count, |
| 830 |
3, 'There are 3 current article requests' ); |
| 831 |
|
| 832 |
$schema->storage->txn_rollback; |
| 833 |
}; |