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 => 46;
22
use Test::More tests => 37;
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 => 14;
20
use Test::More tests => 17;
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 637-639 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
637
637
638
    $schema->storage->txn_rollback;
638
    $schema->storage->txn_rollback;
639
};
639
};
640
- 
640
641
subtest 'article_requests() tests' => sub {
642
643
    plan tests => 3;
644
645
    $schema->storage->txn_begin;
646
647
    my $item   = $builder->build_sample_item;
648
    my $biblio = $item->biblio;
649
650
    my $article_requests = $biblio->article_requests;
651
    is( ref($article_requests), 'Koha::ArticleRequests',
652
        'In scalar context, type is correct' );
653
    is( $article_requests->count, 0, 'No article requests' );
654
655
    foreach my $i ( 0 .. 3 ) {
656
657
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
658
659
        Koha::ArticleRequest->new(
660
            {
661
                borrowernumber => $patron->id,
662
                biblionumber   => $biblio->id,
663
                itemnumber     => $item->id,
664
                title          => $biblio->title,
665
            }
666
        )->request;
667
    }
668
669
    $article_requests = $biblio->article_requests;
670
    is( $article_requests->count, 4, '4 article requests' );
671
672
    $schema->storage->txn_rollback;
673
};
674
675
subtest 'article_requests_current() tests' => sub {
676
677
    plan tests => 7;
678
679
    $schema->storage->txn_begin;
680
681
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
682
    my $item   = $builder->build_sample_item;
683
    my $biblio = $item->biblio;
684
685
    my $article_request = Koha::ArticleRequest->new(
686
        {
687
            borrowernumber => $patron->id,
688
            biblionumber   => $biblio->id,
689
            itemnumber     => $item->id,
690
            title          => $biblio->title,
691
        }
692
    )->request();
693
694
    my $ar = $biblio->article_requests();
695
    is( ref($ar), 'Koha::ArticleRequests',
696
        '$biblio->article_requests returns Koha::ArticleRequests object' );
697
    is( $ar->next->id, $article_request->id,
698
        'Returned article request matches' );
699
700
    is( $biblio->article_requests_current()->count(),
701
        1, 'Open request returned for article_requests_current' );
702
    $article_request->set_pending();
703
    is( $biblio->article_requests_current()->count(),
704
        1, 'Pending request returned for article_requests_current' );
705
    $article_request->process();
706
    is( $biblio->article_requests_current()->count(),
707
        1, 'Processing request returned for article_requests_current' );
708
    $article_request->complete();
709
    is( $biblio->article_requests_current()->count(),
710
        0, 'Completed request not returned for article_requests_current' );
711
    $article_request->cancel();
712
    is( $biblio->article_requests_current()->count(),
713
        0, 'Canceled request not returned for article_requests_current' );
714
715
    $schema->storage->txn_rollback;
716
};
717
718
subtest 'article_requests_finished() tests' => sub {
719
720
    plan tests => 7;
721
722
    $schema->storage->txn_begin;
723
724
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
725
    my $item   = $builder->build_sample_item;
726
    my $biblio = $item->biblio;
727
728
    my $article_request = Koha::ArticleRequest->new(
729
        {
730
            borrowernumber => $patron->id,
731
            biblionumber   => $biblio->id,
732
            itemnumber     => $item->id,
733
            title          => $biblio->title,
734
        }
735
    )->request();
736
737
    my $ar = $biblio->article_requests();
738
    is( ref($ar), 'Koha::ArticleRequests',
739
        '$biblio->article_requests returns Koha::ArticleRequests object' );
740
    is( $ar->next->id, $article_request->id,
741
        'Returned article request matches' );
742
743
    is( $biblio->article_requests_finished->count,
744
        0, 'Open request returned for article_requests_finished' );
745
    $article_request->set_pending();
746
    is( $biblio->article_requests_finished->count,
747
        0, 'Pending request returned for article_requests_finished' );
748
    $article_request->process();
749
    is( $biblio->article_requests_finished->count,
750
        0, 'Processing request returned for article_requests_finished' );
751
    $article_request->complete();
752
    is( $biblio->article_requests_finished->count,
753
        1, 'Completed request returned for article_requests_finished' );
754
    $article_request->cancel();
755
    is( $biblio->article_requests_finished->count,
756
        1, 'Cancelled request not returned for article_requests_finished' );
757
758
    $schema->storage->txn_rollback;
759
};

Return to bug 29084