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

(-)a/t/db_dependent/ArticleRequests.t (-23 / +1 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 => 45;
22
use Test::More tests => 36;
23
use Test::MockModule;
23
use Test::MockModule;
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 110-137 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 = $biblio->article_requests();
114
is( ref($ar),      'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' );
115
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
116
117
is( $biblio->article_requests_current()->count(), 1, 'Open request returned for article_requests_current' );
118
$article_request->process();
119
is( $biblio->article_requests_current()->count(), 1, 'Processing request returned for article_requests_current' );
120
$article_request->complete();
121
is( $biblio->article_requests_current()->count(), 0, 'Completed request not returned for article_requests_current' );
122
$article_request->cancel();
123
is( $biblio->article_requests_current()->count(), 0, 'Canceled request not returned for article_requests_current' );
124
125
$article_request->status(Koha::ArticleRequest::Status::Pending);
126
$article_request->store();
127
128
is( $biblio->article_requests_finished()->count(), 0, 'Open request returned for article_requests_finished' );
129
$article_request->process();
130
is( $biblio->article_requests_finished()->count(), 0, 'Processing request returned for article_requests_finished' );
131
$article_request->complete();
132
$article_request->cancel();
133
is( $biblio->article_requests_finished()->count(), 1, 'Canceled request not returned for article_requests_finished' );
134
135
my $rule = Koha::CirculationRules->set_rule(
113
my $rule = Koha::CirculationRules->set_rule(
136
    {
114
    {
137
        categorycode => undef,
115
        categorycode => undef,
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +121 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 15;
20
use Test::More tests => 18;
21
21
22
use C4::Biblio qw( AddBiblio ModBiblio );
22
use C4::Biblio qw( AddBiblio ModBiblio );
23
use Koha::Database;
23
use Koha::Database;
Lines 690-692 subtest 'host_items() tests' => sub { Link Here
690
690
691
    $schema->storage->txn_rollback;
691
    $schema->storage->txn_rollback;
692
};
692
};
693
- 
693
694
subtest 'article_requests() tests' => sub {
695
696
    plan tests => 3;
697
698
    $schema->storage->txn_begin;
699
700
    my $item   = $builder->build_sample_item;
701
    my $biblio = $item->biblio;
702
703
    my $article_requests = $biblio->article_requests;
704
    is( ref($article_requests), 'Koha::ArticleRequests',
705
        'In scalar context, type is correct' );
706
    is( $article_requests->count, 0, 'No article requests' );
707
708
    foreach my $i ( 0 .. 3 ) {
709
710
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
711
712
        Koha::ArticleRequest->new(
713
            {
714
                borrowernumber => $patron->id,
715
                biblionumber   => $biblio->id,
716
                itemnumber     => $item->id,
717
                title          => $biblio->title,
718
            }
719
        )->request;
720
    }
721
722
    $article_requests = $biblio->article_requests;
723
    is( $article_requests->count, 4, '4 article requests' );
724
725
    $schema->storage->txn_rollback;
726
};
727
728
subtest 'article_requests_current() tests' => sub {
729
730
    plan tests => 7;
731
732
    $schema->storage->txn_begin;
733
734
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
735
    my $item   = $builder->build_sample_item;
736
    my $biblio = $item->biblio;
737
738
    my $article_request = Koha::ArticleRequest->new(
739
        {
740
            borrowernumber => $patron->id,
741
            biblionumber   => $biblio->id,
742
            itemnumber     => $item->id,
743
            title          => $biblio->title,
744
        }
745
    )->request();
746
747
    my $ar = $biblio->article_requests();
748
    is( ref($ar), 'Koha::ArticleRequests',
749
        '$biblio->article_requests returns Koha::ArticleRequests object' );
750
    is( $ar->next->id, $article_request->id,
751
        'Returned article request matches' );
752
753
    is( $biblio->article_requests_current()->count(),
754
        1, 'Open request returned for article_requests_current' );
755
    $article_request->set_pending();
756
    is( $biblio->article_requests_current()->count(),
757
        1, 'Pending request returned for article_requests_current' );
758
    $article_request->process();
759
    is( $biblio->article_requests_current()->count(),
760
        1, 'Processing request returned for article_requests_current' );
761
    $article_request->complete();
762
    is( $biblio->article_requests_current()->count(),
763
        0, 'Completed request not returned for article_requests_current' );
764
    $article_request->cancel();
765
    is( $biblio->article_requests_current()->count(),
766
        0, 'Canceled request not returned for article_requests_current' );
767
768
    $schema->storage->txn_rollback;
769
};
770
771
subtest 'article_requests_finished() tests' => sub {
772
773
    plan tests => 7;
774
775
    $schema->storage->txn_begin;
776
777
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
778
    my $item   = $builder->build_sample_item;
779
    my $biblio = $item->biblio;
780
781
    my $article_request = Koha::ArticleRequest->new(
782
        {
783
            borrowernumber => $patron->id,
784
            biblionumber   => $biblio->id,
785
            itemnumber     => $item->id,
786
            title          => $biblio->title,
787
        }
788
    )->request();
789
790
    my $ar = $biblio->article_requests();
791
    is( ref($ar), 'Koha::ArticleRequests',
792
        '$biblio->article_requests returns Koha::ArticleRequests object' );
793
    is( $ar->next->id, $article_request->id,
794
        'Returned article request matches' );
795
796
    is( $biblio->article_requests_finished->count,
797
        0, 'Open request returned for article_requests_finished' );
798
    $article_request->set_pending();
799
    is( $biblio->article_requests_finished->count,
800
        0, 'Pending request returned for article_requests_finished' );
801
    $article_request->process();
802
    is( $biblio->article_requests_finished->count,
803
        0, 'Processing request returned for article_requests_finished' );
804
    $article_request->complete();
805
    is( $biblio->article_requests_finished->count,
806
        1, 'Completed request returned for article_requests_finished' );
807
    $article_request->cancel();
808
    is( $biblio->article_requests_finished->count,
809
        1, 'Cancelled request not returned for article_requests_finished' );
810
811
    $schema->storage->txn_rollback;
812
};

Return to bug 29084