From 211f63ea0fb3ba9f9eb71abf7ccc8fd309ab8269 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 10 Aug 2021 13:16:53 -0300 Subject: [PATCH] Bug 27944: (QA follow-up) Rename ->open for ->set_pending Content-Type: text/plain; charset=utf-8 Signed-off-by: Tomas Cohen Arazi Signed-off-by: Marcel de Rooy --- Koha/ArticleRequest.pm | 8 +++-- .../prog/en/modules/circ/article-requests.tt | 2 +- svc/article_request | 4 +-- t/db_dependent/ArticleRequests.t | 35 +++++++++++++++---- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm index 973d7a161a..71a106d3f7 100644 --- a/Koha/ArticleRequest.pm +++ b/Koha/ArticleRequest.pm @@ -36,7 +36,7 @@ Koha::ArticleRequest - Koha Article Request Object class =head1 API -=head2 Class Methods +=head2 Class methods =cut @@ -53,11 +53,11 @@ sub request { return $self; } -=head3 open +=head3 set_pending =cut -sub open { +sub set_pending { my ($self) = @_; $self->status(Koha::ArticleRequest::Status::Pending); @@ -216,6 +216,8 @@ sub store { } } +=head2 Internal methods + =head3 _type =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt index fabf326dd2..afb4d841f5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt @@ -606,7 +606,7 @@ type: "POST", url: '/cgi-bin/koha/svc/article_request', data: { - action: 'open', + action: 'pending', id: id, }, success: function( data ) { diff --git a/svc/article_request b/svc/article_request index a372cd6199..3b5105ad0d 100755 --- a/svc/article_request +++ b/svc/article_request @@ -50,8 +50,8 @@ if ($ar) { elsif ( $action eq 'process' ) { $ar = $ar->process(); } - elsif ( $action eq 'open' ) { - $ar = $ar->open(); + elsif ( $action eq 'pending' ) { + $ar = $ar->set_pending(); } elsif ( $action eq 'complete' ) { $ar = $ar->complete(); diff --git a/t/db_dependent/ArticleRequests.t b/t/db_dependent/ArticleRequests.t index bb4b5f8b8d..c647745540 100755 --- a/t/db_dependent/ArticleRequests.t +++ b/t/db_dependent/ArticleRequests.t @@ -19,7 +19,8 @@ use Modern::Perl; use POSIX qw(strftime); -use Test::More tests => 54; +use Test::More tests => 55; +use Test::MockModule; use t::lib::TestBuilder; use t::lib::Mocks; @@ -101,8 +102,7 @@ is( $article_request->status, Koha::ArticleRequest::Status::Completed, '$ar->com # cancel $article_request->cancel(); is( $article_request->status, Koha::ArticleRequest::Status::Canceled, '$ar->complete() changes status to Canceled' ); -$article_request->status(Koha::ArticleRequest::Status::Pending); -$article_request->store(); +$article_request->set_pending(); is( $article_request->biblio->id, $biblio->id, '$ar->biblio() gets corresponding Koha::Biblio object' ); is( $article_request->item->id, $item->id, '$ar->item() gets corresponding Koha::Item object' ); @@ -120,8 +120,7 @@ is( $patron->article_requests_current()->count(), 0, 'Completed request not retu $article_request->cancel(); is( $patron->article_requests_current()->count(), 0, 'Canceled request not returned for article_requests_current' ); -$article_request->status(Koha::ArticleRequest::Status::Pending); -$article_request->store(); +$article_request->set_pending(); is( $patron->article_requests_finished()->count(), 0, 'Open request returned for article_requests_finished' ); $article_request->process(); @@ -130,8 +129,7 @@ $article_request->complete(); $article_request->cancel(); is( $patron->article_requests_finished()->count(), 1, 'Canceled request not returned for article_requests_finished' ); -$article_request->status(Koha::ArticleRequest::Status::Pending); -$article_request->store(); +$article_request->set_pending(); $ar = $biblio->article_requests(); is( ref($ar), 'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' ); @@ -253,3 +251,26 @@ subtest 'may_article_request' => sub { }; $schema->storage->txn_rollback(); + +subtest 'set_pending() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $ar_mock = Test::MockModule->new('Koha::ArticleRequest'); + $ar_mock->mock( 'notify', sub { ok( 1, '->notify() called' ); } ); + + my $ar = $builder->build_object( + { + class => 'Koha::ArticleRequests', + value => { status => Koha::ArticleRequest::Status::Requested } + } + ); + + $ar->set_pending()->discard_changes; + + is( $ar->status, Koha::ArticleRequest::Status::Pending ); + + $schema->storage->txn_rollback; +}; -- 2.20.1