Bugzilla – Attachment 125284 Details for
Bug 29110
Refactor Koha::ArticleRequest->store
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29110: Unit tests
Bug-29110-Unit-tests.patch (text/plain), 6.99 KB, created by
David Nind
on 2021-09-24 16:00:37 UTC
(
hide
)
Description:
Bug 29110: Unit tests
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-09-24 16:00:37 UTC
Size:
6.99 KB
patch
obsolete
>From 38839df9566d39392f2e0fd38156e2850392a281 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 24 Sep 2021 12:00:21 -0300 >Subject: [PATCH] Bug 29110: Unit tests > >Signed-off-by: David Nind <david@davidnind.com> >--- > t/db_dependent/ArticleRequests.t | 25 +--- > t/db_dependent/Koha/ArticleRequest.t | 178 +++++++++++++++++++++++++++ > 2 files changed, 179 insertions(+), 24 deletions(-) > create mode 100755 t/db_dependent/Koha/ArticleRequest.t > >diff --git a/t/db_dependent/ArticleRequests.t b/t/db_dependent/ArticleRequests.t >index d740008172..c1e16d9424 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 => 37; >+use Test::More tests => 36; > use Test::MockModule; > > use t::lib::TestBuilder; >@@ -208,26 +208,3 @@ 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; >-}; >diff --git a/t/db_dependent/Koha/ArticleRequest.t b/t/db_dependent/Koha/ArticleRequest.t >new file mode 100755 >index 0000000000..cb057ff7c7 >--- /dev/null >+++ b/t/db_dependent/Koha/ArticleRequest.t >@@ -0,0 +1,178 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 5; >+use Test::Exception; >+use Test::MockModule; >+ >+use Koha::ArticleRequest::Status; >+use Koha::ArticleRequests; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'store() tests' => sub { >+ >+ plan tests => 8; >+ >+ $schema->storage->txn_begin; >+ >+ my $mock_article_request = Test::MockModule->new('Koha::ArticleRequest'); >+ my $notify_called; >+ $mock_article_request->mock( 'notify', sub { $notify_called = 1; } ); >+ >+ my $item = $builder->build_sample_item; >+ my $article_request = Koha::ArticleRequest->new( >+ { itemnumber => $item->id, biblionumber => $item->biblionumber } ); >+ >+ throws_ok { $article_request->store; } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown because of missing borrowernumber parameter'; >+ >+ my $deleted_patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $deleted_patron_id = $deleted_patron->id; >+ $deleted_patron->delete; >+ >+ # use the invalid patron to trigger fk exception >+ $article_request->borrowernumber($deleted_patron_id); >+ >+ throws_ok { $article_request->store; } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'Exception thrown because of missing borrowernumber parameter'; >+ >+ is( $@->broken_fk, 'borrowernumber', 'Exception build correctly (1/2)' ); >+ is( $@->value, $deleted_patron_id, 'Exception build correctly (1/2)' ); >+ >+ my $patron_can_request = 0; >+ >+ my $mocked_patron = Test::MockModule->new('Koha::Patron'); >+ $mocked_patron->mock( 'can_request_article', sub { return $patron_can_request; } ); >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ $article_request->borrowernumber( $patron->id ); >+ >+ throws_ok >+ { $article_request->store; } >+ 'Koha::Exceptions::ArticleRequest::LimitReached', >+ 'Exception thrown because patron reached its limit'; >+ >+ # allow the patron to place requests >+ $patron_can_request = 1; >+ $article_request->store->discard_changes; >+ >+ is( $article_request->status, Koha::ArticleRequest::Status::Requested, 'Status set correctly' ); >+ isnt( $article_request->created_on, undef, 'created_on set correctly' ); >+ ok( $notify_called, 'Notify was called' ); >+ >+ $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; >+}; >+ >+subtest 'request() 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::Pending } >+ } >+ ); >+ >+ $ar->request()->discard_changes; >+ >+ is( $ar->status, Koha::ArticleRequest::Status::Requested ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'process() 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->process()->discard_changes; >+ >+ is( $ar->status, Koha::ArticleRequest::Status::Processing ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'complete() 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->complete()->discard_changes; >+ >+ is( $ar->status, Koha::ArticleRequest::Status::Completed ); >+ >+ $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 29110
:
125256
|
125257
| 125284 |
125285