Bugzilla – Attachment 47253 Details for
Bug 13906
TestObjectFactory(ies) for Koha objects. Enable easy Test object creation from HASHes or from preconfigured test groups.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13906 (follow-up) - New TestObjectFactory for creating fines into accountlines
Bug-13906-follow-up---New-TestObjectFactory-for-cr.patch (text/plain), 5.81 KB, created by
Lari Taskula
on 2016-01-25 13:50:36 UTC
(
hide
)
Description:
Bug 13906 (follow-up) - New TestObjectFactory for creating fines into accountlines
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2016-01-25 13:50:36 UTC
Size:
5.81 KB
patch
obsolete
>From 0f7c2e8bec35bf37b62f1fc5454021c2f6869c23 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <larit@student.uef.fi> >Date: Tue, 15 Dec 2015 09:01:42 +0000 >Subject: [PATCH] Bug 13906 (follow-up) - New TestObjectFactory for creating > fines into accountlines > >--- > t/lib/TestObjects/FinesFactory.pm | 150 +++++++++++++++++++++++++++++++++++++ > t/lib/TestObjects/ObjectFactory.pm | 6 ++ > 2 files changed, 156 insertions(+) > create mode 100644 t/lib/TestObjects/FinesFactory.pm > >diff --git a/t/lib/TestObjects/FinesFactory.pm b/t/lib/TestObjects/FinesFactory.pm >new file mode 100644 >index 0000000..2d307d9 >--- /dev/null >+++ b/t/lib/TestObjects/FinesFactory.pm >@@ -0,0 +1,150 @@ >+package t::lib::TestObjects::FinesFactory; >+ >+# Copyright Vaara-kirjastot 2015 >+# >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+# >+ >+use Modern::Perl; >+use Carp; >+use Scalar::Util qw(blessed); >+ >+use C4::Members; >+use C4::Accounts; >+use Koha::Borrowers; >+ >+use base qw(t::lib::TestObjects::ObjectFactory); >+ >+use Koha::Exception::ObjectExists; >+ >+sub new { >+ my ($class) = @_; >+ >+ my $self = {}; >+ bless($self, $class); >+ return $self; >+} >+ >+sub getDefaultHashKey { >+ return 'note'; >+} >+sub getObjectType { >+ return 'HASH'; >+} >+ >+=head createTestGroup( $data [, $hashKey, $testContexts...] ) >+@OVERLOADED >+ >+ FinesFactory creates new fines into accountlines. >+ After testing, all fines created by the FinesFactory will be >+ deleted at tearDown. >+ >+ my $fines = t::lib::TestObjects::FinesFactory->createTestGroup([ >+ amount => 10.0, >+ cardnumber => $borrowers->{'superuberadmin'}->cardnumber, >+ accounttype => 'FU', >+ note => 'unique identifier', >+ }, >+ ], undef, $testContext1, $testContext2, $testContext3); >+ >+ #Do test stuff... >+ >+ t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext1); >+ t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext2); >+ t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext3); >+ >+See t::lib::TestObjects::ObjectFactory for more documentation >+=cut >+ >+sub handleTestObject { >+ my ($class, $fine, $stashes) = @_; >+ >+ my $borrower = Koha::Borrowers->cast($fine->{cardnumber}); >+ >+ my $accountno = C4::Accounts::getnextacctno($borrower->borrowernumber); >+ >+ C4::Accounts::manualinvoice( >+ $borrower->borrowernumber, # borrowernumber >+ undef, # itemnumber >+ "Test payment", # description >+ $fine->{accounttype}, # accounttype >+ $fine->{amount}, # amountoutstanding >+ $fine->{note} # note, unique identifier >+ ); >+ >+ my $new_fine = $fine; >+ >+ $new_fine->{accountno} = $accountno; >+ >+ return $new_fine; >+} >+ >+=head validateAndPopulateDefaultValues >+@OVERLOAD >+ >+Validates given Object parameters and makes sure that critical fields are given >+and populates defaults for missing values. >+=cut >+ >+sub validateAndPopulateDefaultValues { >+ my ($class, $object, $hashKey) = @_; >+ $class->SUPER::validateAndPopulateDefaultValues($object, $hashKey); >+ >+ unless ($object->{cardnumber}) { >+ Koha::Exception::BadParameter->throw(error => __PACKAGE__."->createTestGroup():> 'cardnumber' is a mandatory parameter!"); >+ } >+ unless ($object->{note}) { >+ Koha::Exception::BadParameter->throw(error => __PACKAGE__."->createTestGroup():> 'note' is a mandatory parameter!"); >+ } >+ >+ $object->{accounttype} = "FU" unless defined $object->{accounttype}; >+} >+ >+=head deleteTestGroup >+@OVERLOADED >+ >+ my $records = createTestGroup(); >+ ##Do funky stuff >+ deleteTestGroup($prefs); >+ >+Removes the given test group from the DB. >+ >+=cut >+ >+sub deleteTestGroup { >+ my ($class, $acct) = @_; >+ >+ my $schema = Koha::Database->new_schema(); >+ while( my ($key, $val) = each %$acct) { >+ if ($schema->resultset('Accountline')->find({"accountno" => $val->{accountno}, "borrowernumber" => $val->{borrowernumber} })) { >+ $schema->resultset('Accountline')->find({"accountno" => $val->{accountno}, "borrowernumber" => $val->{borrowernumber} })->delete(); >+ } >+ } >+} >+ >+sub _deleteTestGroupFromIdentifiers { >+ my ($self, $testGroupIdentifiers) = @_; >+ >+ my $schema = Koha::Database->new_schema(); >+ foreach my $key (@$testGroupIdentifiers) { >+ if ($schema->resultset('Accountline')->find({"note" => $key})) { >+ $schema->resultset('Accountline')->find({"note" => $key})->delete(); >+ } >+ } >+} >+ >+ >+1; >diff --git a/t/lib/TestObjects/ObjectFactory.pm b/t/lib/TestObjects/ObjectFactory.pm >index 8c92b69..b117334 100644 >--- a/t/lib/TestObjects/ObjectFactory.pm >+++ b/t/lib/TestObjects/ObjectFactory.pm >@@ -196,6 +196,12 @@ sub tearDownTestContext { > t::lib::TestObjects::MessageQueueFactory->deleteTestGroup($stash->{messagequeue}); > delete $stash->{messagequeue}; > } >+ if ($stash->{fines}) { >+ require t::lib::TestObjects::FinesFactory; >+ t::lib::TestObjects::FinesFactory->deleteTestGroup($stash->{fines}); >+ delete $stash->{fines}; >+ } >+ > } > > =head getHashKey >-- >1.9.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 13906
:
37216
|
40071
|
40072
|
40078
|
41021
|
41119
|
41154
|
41251
|
41459
|
41531
|
42108
|
42141
|
42161
|
42169
|
42430
|
42552
|
42563
|
42602
|
44293
|
47244
|
47253
|
63244