Bugzilla – Attachment 125244 Details for
Bug 29084
Update article requests-related Koha::Biblio methods to use relationships
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29084: Unit tests
Bug-29084-Unit-tests.patch (text/plain), 7.52 KB, created by
Martin Renvoize (ashimema)
on 2021-09-24 13:04:47 UTC
(
hide
)
Description:
Bug 29084: Unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-09-24 13:04:47 UTC
Size:
7.52 KB
patch
obsolete
>From 0d4e8e375ed33f23bb5c69219156481380a55158 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 22 Sep 2021 16:11:14 -0300 >Subject: [PATCH] Bug 29084: Unit tests > >This patch adds missing tests for Koha::Biblio->article_requests and >reorganizes (and extends) the tests for 'article_requests_current' and >'article_requests_finished' that were originally in ArticleRequests.t >into Koha/Biblio.t as we do now. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/ArticleRequests.t \ > t/db_dependent/Koha/Biblio.t >=> SUCCESS: Tests pass! > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/ArticleRequests.t | 24 +----- > t/db_dependent/Koha/Biblio.t | 122 ++++++++++++++++++++++++++++++- > 2 files changed, 122 insertions(+), 24 deletions(-) > >diff --git a/t/db_dependent/ArticleRequests.t b/t/db_dependent/ArticleRequests.t >index cb25c00b959..d7400081728 100644 >--- a/t/db_dependent/ArticleRequests.t >+++ b/t/db_dependent/ArticleRequests.t >@@ -19,7 +19,7 @@ use Modern::Perl; > > use POSIX qw(strftime); > >-use Test::More tests => 46; >+use Test::More tests => 37; > use Test::MockModule; > > use t::lib::TestBuilder; >@@ -110,28 +110,6 @@ is( $article_request->biblio->id, $biblio->id, '$ar->biblio() gets correspondi > is( $article_request->item->id, $item->id, '$ar->item() gets corresponding Koha::Item object' ); > is( $article_request->borrower->id, $patron->id, '$ar->borrower() gets corresponding Koha::Patron object' ); > >-my $ar = $biblio->article_requests(); >-is( ref($ar), 'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' ); >-is( $ar->next->id, $article_request->id, 'Returned article request matches' ); >- >-is( $biblio->article_requests_current()->count(), 1, 'Open request returned for article_requests_current' ); >-$article_request->process(); >-is( $biblio->article_requests_current()->count(), 1, 'Processing request returned for article_requests_current' ); >-$article_request->complete(); >-is( $biblio->article_requests_current()->count(), 0, 'Completed request not returned for article_requests_current' ); >-$article_request->cancel(); >-is( $biblio->article_requests_current()->count(), 0, 'Canceled request not returned for article_requests_current' ); >- >-$article_request->status(Koha::ArticleRequest::Status::Pending); >-$article_request->store(); >- >-is( $biblio->article_requests_finished()->count(), 0, 'Open request returned for article_requests_finished' ); >-$article_request->process(); >-is( $biblio->article_requests_finished()->count(), 0, 'Processing request returned for article_requests_finished' ); >-$article_request->complete(); >-$article_request->cancel(); >-is( $biblio->article_requests_finished()->count(), 1, 'Canceled request not returned for article_requests_finished' ); >- > my $rule = Koha::CirculationRules->set_rule( > { > categorycode => undef, >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index 83de0634c6b..8e92dccad33 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 14; >+use Test::More tests => 17; > > use C4::Biblio qw( AddBiblio ModBiblio ); > use Koha::Database; >@@ -637,3 +637,123 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'article_requests() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $item = $builder->build_sample_item; >+ my $biblio = $item->biblio; >+ >+ my $article_requests = $biblio->article_requests; >+ is( ref($article_requests), 'Koha::ArticleRequests', >+ 'In scalar context, type is correct' ); >+ is( $article_requests->count, 0, 'No article requests' ); >+ >+ foreach my $i ( 0 .. 3 ) { >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ Koha::ArticleRequest->new( >+ { >+ borrowernumber => $patron->id, >+ biblionumber => $biblio->id, >+ itemnumber => $item->id, >+ title => $biblio->title, >+ } >+ )->request; >+ } >+ >+ $article_requests = $biblio->article_requests; >+ is( $article_requests->count, 4, '4 article requests' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'article_requests_current() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item; >+ my $biblio = $item->biblio; >+ >+ my $article_request = Koha::ArticleRequest->new( >+ { >+ borrowernumber => $patron->id, >+ biblionumber => $biblio->id, >+ itemnumber => $item->id, >+ title => $biblio->title, >+ } >+ )->request(); >+ >+ my $ar = $biblio->article_requests(); >+ is( ref($ar), 'Koha::ArticleRequests', >+ '$biblio->article_requests returns Koha::ArticleRequests object' ); >+ is( $ar->next->id, $article_request->id, >+ 'Returned article request matches' ); >+ >+ is( $biblio->article_requests_current()->count(), >+ 1, 'Open request returned for article_requests_current' ); >+ $article_request->set_pending(); >+ is( $biblio->article_requests_current()->count(), >+ 1, 'Pending request returned for article_requests_current' ); >+ $article_request->process(); >+ is( $biblio->article_requests_current()->count(), >+ 1, 'Processing request returned for article_requests_current' ); >+ $article_request->complete(); >+ is( $biblio->article_requests_current()->count(), >+ 0, 'Completed request not returned for article_requests_current' ); >+ $article_request->cancel(); >+ is( $biblio->article_requests_current()->count(), >+ 0, 'Canceled request not returned for article_requests_current' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'article_requests_finished() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item; >+ my $biblio = $item->biblio; >+ >+ my $article_request = Koha::ArticleRequest->new( >+ { >+ borrowernumber => $patron->id, >+ biblionumber => $biblio->id, >+ itemnumber => $item->id, >+ title => $biblio->title, >+ } >+ )->request(); >+ >+ my $ar = $biblio->article_requests(); >+ is( ref($ar), 'Koha::ArticleRequests', >+ '$biblio->article_requests returns Koha::ArticleRequests object' ); >+ is( $ar->next->id, $article_request->id, >+ 'Returned article request matches' ); >+ >+ is( $biblio->article_requests_finished->count, >+ 0, 'Open request returned for article_requests_finished' ); >+ $article_request->set_pending(); >+ is( $biblio->article_requests_finished->count, >+ 0, 'Pending request returned for article_requests_finished' ); >+ $article_request->process(); >+ is( $biblio->article_requests_finished->count, >+ 0, 'Processing request returned for article_requests_finished' ); >+ $article_request->complete(); >+ is( $biblio->article_requests_finished->count, >+ 1, 'Completed request returned for article_requests_finished' ); >+ $article_request->cancel(); >+ is( $biblio->article_requests_finished->count, >+ 1, 'Cancelled request not returned for article_requests_finished' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29084
:
125163
|
125164
|
125244
|
125245
|
125841
|
125842
|
125843