|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 10; |
22 |
use Test::More tests => 13; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 883-885
subtest 'can_request_article() tests' => sub {
Link Here
|
| 883 |
|
883 |
|
| 884 |
$schema->storage->txn_rollback; |
884 |
$schema->storage->txn_rollback; |
| 885 |
}; |
885 |
}; |
| 886 |
- |
886 |
|
|
|
887 |
subtest 'article_requests() tests' => sub { |
| 888 |
|
| 889 |
plan tests => 3; |
| 890 |
|
| 891 |
$schema->storage->txn_begin; |
| 892 |
|
| 893 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 894 |
|
| 895 |
my $article_requests = $patron->article_requests; |
| 896 |
is( ref($article_requests), 'Koha::ArticleRequests', |
| 897 |
'In scalar context, type is correct' ); |
| 898 |
is( $article_requests->count, 0, 'No article requests' ); |
| 899 |
|
| 900 |
foreach my $i ( 0 .. 3 ) { |
| 901 |
|
| 902 |
my $item = $builder->build_sample_item; |
| 903 |
|
| 904 |
Koha::ArticleRequest->new( |
| 905 |
{ |
| 906 |
borrowernumber => $patron->id, |
| 907 |
biblionumber => $item->biblionumber, |
| 908 |
itemnumber => $item->id, |
| 909 |
title => "Title", |
| 910 |
} |
| 911 |
)->request; |
| 912 |
} |
| 913 |
|
| 914 |
$article_requests = $patron->article_requests; |
| 915 |
is( $article_requests->count, 4, '4 article requests' ); |
| 916 |
|
| 917 |
$schema->storage->txn_rollback; |
| 918 |
}; |
| 919 |
|
| 920 |
subtest 'article_requests_current() tests' => sub { |
| 921 |
|
| 922 |
plan tests => 7; |
| 923 |
|
| 924 |
$schema->storage->txn_begin; |
| 925 |
|
| 926 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 927 |
my $item = $builder->build_sample_item; |
| 928 |
|
| 929 |
my $article_request = Koha::ArticleRequest->new( |
| 930 |
{ |
| 931 |
borrowernumber => $patron->id, |
| 932 |
biblionumber => $item->biblionumber, |
| 933 |
itemnumber => $item->itemnumber, |
| 934 |
title => "Boo", |
| 935 |
} |
| 936 |
)->request(); |
| 937 |
|
| 938 |
my $ar = $patron->article_requests(); |
| 939 |
is( ref($ar), 'Koha::ArticleRequests', |
| 940 |
'$patron->article_requests returns Koha::ArticleRequests object' ); |
| 941 |
is( $ar->next->id, $article_request->id, |
| 942 |
'Returned article request matches' ); |
| 943 |
|
| 944 |
is( $patron->article_requests_current()->count(), |
| 945 |
1, 'Open request returned for article_requests_current' ); |
| 946 |
$article_request->set_pending(); |
| 947 |
is( $patron->article_requests_current()->count(), |
| 948 |
1, 'Pending request returned for article_requests_current' ); |
| 949 |
$article_request->process(); |
| 950 |
is( $patron->article_requests_current()->count(), |
| 951 |
1, 'Processing request returned for article_requests_current' ); |
| 952 |
$article_request->complete(); |
| 953 |
is( $patron->article_requests_current()->count(), |
| 954 |
0, 'Completed request not returned for article_requests_current' ); |
| 955 |
$article_request->cancel(); |
| 956 |
is( $patron->article_requests_current()->count(), |
| 957 |
0, 'Canceled request not returned for article_requests_current' ); |
| 958 |
|
| 959 |
$schema->storage->txn_rollback; |
| 960 |
}; |
| 961 |
|
| 962 |
subtest 'article_requests_finished() tests' => sub { |
| 963 |
|
| 964 |
plan tests => 7; |
| 965 |
|
| 966 |
$schema->storage->txn_begin; |
| 967 |
|
| 968 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 969 |
my $item = $builder->build_sample_item; |
| 970 |
|
| 971 |
my $article_request = Koha::ArticleRequest->new( |
| 972 |
{ |
| 973 |
borrowernumber => $patron->id, |
| 974 |
biblionumber => $item->biblionumber, |
| 975 |
itemnumber => $item->itemnumber, |
| 976 |
title => "Boo", |
| 977 |
} |
| 978 |
)->request(); |
| 979 |
|
| 980 |
my $ar = $patron->article_requests(); |
| 981 |
is( ref($ar), 'Koha::ArticleRequests', |
| 982 |
'$patron->article_requests returns Koha::ArticleRequests object' ); |
| 983 |
is( $ar->next->id, $article_request->id, |
| 984 |
'Returned article request matches' ); |
| 985 |
|
| 986 |
is( $patron->article_requests_finished->count, |
| 987 |
0, 'Open request returned for article_requests_finished' ); |
| 988 |
$article_request->set_pending(); |
| 989 |
is( $patron->article_requests_finished->count, |
| 990 |
0, 'Pending request returned for article_requests_finished' ); |
| 991 |
$article_request->process(); |
| 992 |
is( $patron->article_requests_finished->count, |
| 993 |
0, 'Processing request returned for article_requests_finished' ); |
| 994 |
$article_request->complete(); |
| 995 |
is( $patron->article_requests_finished->count, |
| 996 |
1, 'Completed request returned for article_requests_finished' ); |
| 997 |
$article_request->cancel(); |
| 998 |
is( $patron->article_requests_finished->count, |
| 999 |
1, 'Cancelled request not returned for article_requests_finished' ); |
| 1000 |
|
| 1001 |
$schema->storage->txn_rollback; |
| 1002 |
}; |