View | Details | Raw Unified | Return to bug 29083
Collapse All | Expand All

(-)a/t/db_dependent/ArticleRequests.t (-25 / +2 lines)
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 => 45;
23
use Test::MockModule;
23
use Test::MockModule;
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 110-139 is( $article_request->biblio->id, $biblio->id, '$ar->biblio() gets correspondi Link Here
110
is( $article_request->item->id,     $item->id,   '$ar->item() gets corresponding Koha::Item object' );
110
is( $article_request->item->id,     $item->id,   '$ar->item() gets corresponding Koha::Item object' );
111
is( $article_request->borrower->id, $patron->id, '$ar->borrower() gets corresponding Koha::Patron object' );
111
is( $article_request->borrower->id, $patron->id, '$ar->borrower() gets corresponding Koha::Patron object' );
112
112
113
my $ar = $patron->article_requests();
113
my $ar = $biblio->article_requests();
114
is( ref($ar),      'Koha::ArticleRequests', '$patron->article_requests returns Koha::ArticleRequests object' );
115
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
116
117
is( $patron->article_requests_current()->count(), 1, 'Open request returned for article_requests_current' );
118
$article_request->process();
119
is( $patron->article_requests_current()->count(), 1, 'Processing request returned for article_requests_current' );
120
$article_request->complete();
121
is( $patron->article_requests_current()->count(), 0, 'Completed request not returned for article_requests_current' );
122
$article_request->cancel();
123
is( $patron->article_requests_current()->count(), 0, 'Canceled request not returned for article_requests_current' );
124
125
$article_request->set_pending();
126
127
is( $patron->article_requests_finished()->count(), 0, 'Open request returned for article_requests_finished' );
128
$article_request->process();
129
is( $patron->article_requests_finished()->count(), 0, 'Processing request returned for article_requests_finished' );
130
$article_request->complete();
131
$article_request->cancel();
132
is( $patron->article_requests_finished()->count(), 1, 'Canceled request not returned for article_requests_finished' );
133
134
$article_request->set_pending();
135
136
$ar = $biblio->article_requests();
137
is( ref($ar),      'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' );
114
is( ref($ar),      'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' );
138
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
115
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
139
116
(-)a/t/db_dependent/Koha/Patron.t (-2 / +118 lines)
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
};

Return to bug 29083