Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 9; |
22 |
use Test::More tests => 12; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
use Test::Warn; |
24 |
use Test::Warn; |
25 |
|
25 |
|
Lines 813-815
subtest 'can_request_article() tests' => sub {
Link Here
|
813 |
|
813 |
|
814 |
$schema->storage->txn_rollback; |
814 |
$schema->storage->txn_rollback; |
815 |
}; |
815 |
}; |
816 |
- |
816 |
|
|
|
817 |
subtest 'article_requests() tests' => sub { |
818 |
|
819 |
plan tests => 3; |
820 |
|
821 |
$schema->storage->txn_begin; |
822 |
|
823 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
824 |
|
825 |
my $article_requests = $patron->article_requests; |
826 |
is( ref($article_requests), 'Koha::ArticleRequests', |
827 |
'In scalar context, type is correct' ); |
828 |
is( $article_requests->count, 0, 'No article requests' ); |
829 |
|
830 |
foreach my $i ( 0 .. 3 ) { |
831 |
|
832 |
my $item = $builder->build_sample_item; |
833 |
|
834 |
Koha::ArticleRequest->new( |
835 |
{ |
836 |
borrowernumber => $patron->id, |
837 |
biblionumber => $item->biblionumber, |
838 |
itemnumber => $item->id, |
839 |
title => "Title", |
840 |
} |
841 |
)->request; |
842 |
} |
843 |
|
844 |
$article_requests = $patron->article_requests; |
845 |
is( $article_requests->count, 4, '4 article requests' ); |
846 |
|
847 |
$schema->storage->txn_rollback; |
848 |
}; |
849 |
|
850 |
subtest 'article_requests_current() tests' => sub { |
851 |
|
852 |
plan tests => 7; |
853 |
|
854 |
$schema->storage->txn_begin; |
855 |
|
856 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
857 |
my $item = $builder->build_sample_item; |
858 |
|
859 |
my $article_request = Koha::ArticleRequest->new( |
860 |
{ |
861 |
borrowernumber => $patron->id, |
862 |
biblionumber => $item->biblionumber, |
863 |
itemnumber => $item->itemnumber, |
864 |
title => "Boo", |
865 |
} |
866 |
)->request(); |
867 |
|
868 |
my $ar = $patron->article_requests(); |
869 |
is( ref($ar), 'Koha::ArticleRequests', |
870 |
'$patron->article_requests returns Koha::ArticleRequests object' ); |
871 |
is( $ar->next->id, $article_request->id, |
872 |
'Returned article request matches' ); |
873 |
|
874 |
is( $patron->article_requests_current()->count(), |
875 |
1, 'Open request returned for article_requests_current' ); |
876 |
$article_request->set_pending(); |
877 |
is( $patron->article_requests_current()->count(), |
878 |
1, 'Pending request returned for article_requests_current' ); |
879 |
$article_request->process(); |
880 |
is( $patron->article_requests_current()->count(), |
881 |
1, 'Processing request returned for article_requests_current' ); |
882 |
$article_request->complete(); |
883 |
is( $patron->article_requests_current()->count(), |
884 |
0, 'Completed request not returned for article_requests_current' ); |
885 |
$article_request->cancel(); |
886 |
is( $patron->article_requests_current()->count(), |
887 |
0, 'Canceled request not returned for article_requests_current' ); |
888 |
|
889 |
$schema->storage->txn_rollback; |
890 |
}; |
891 |
|
892 |
subtest 'article_requests_finished() tests' => sub { |
893 |
|
894 |
plan tests => 7; |
895 |
|
896 |
$schema->storage->txn_begin; |
897 |
|
898 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
899 |
my $item = $builder->build_sample_item; |
900 |
|
901 |
my $article_request = Koha::ArticleRequest->new( |
902 |
{ |
903 |
borrowernumber => $patron->id, |
904 |
biblionumber => $item->biblionumber, |
905 |
itemnumber => $item->itemnumber, |
906 |
title => "Boo", |
907 |
} |
908 |
)->request(); |
909 |
|
910 |
my $ar = $patron->article_requests(); |
911 |
is( ref($ar), 'Koha::ArticleRequests', |
912 |
'$patron->article_requests returns Koha::ArticleRequests object' ); |
913 |
is( $ar->next->id, $article_request->id, |
914 |
'Returned article request matches' ); |
915 |
|
916 |
is( $patron->article_requests_finished->count, |
917 |
0, 'Open request returned for article_requests_finished' ); |
918 |
$article_request->set_pending(); |
919 |
is( $patron->article_requests_finished->count, |
920 |
0, 'Pending request returned for article_requests_finished' ); |
921 |
$article_request->process(); |
922 |
is( $patron->article_requests_finished->count, |
923 |
0, 'Processing request returned for article_requests_finished' ); |
924 |
$article_request->complete(); |
925 |
is( $patron->article_requests_finished->count, |
926 |
1, 'Completed request returned for article_requests_finished' ); |
927 |
$article_request->cancel(); |
928 |
is( $patron->article_requests_finished->count, |
929 |
1, 'Cancelled request not returned for article_requests_finished' ); |
930 |
|
931 |
$schema->storage->txn_rollback; |
932 |
}; |