|
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 |
}; |