Bugzilla – Attachment 92878 Details for
Bug 23354
Add a 'Point of sale' screen to allow anonymous payments
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23354: Add tests for Koha::Charges::Sales
Bug-23354-Add-tests-for-KohaChargesSales.patch (text/plain), 9.74 KB, created by
Martin Renvoize (ashimema)
on 2019-09-17 11:15:44 UTC
(
hide
)
Description:
Bug 23354: Add tests for Koha::Charges::Sales
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2019-09-17 11:15:44 UTC
Size:
9.74 KB
patch
obsolete
>From 6c26b91ab5c99b5db1c010a947411fbf9260b0eb Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 16 Sep 2019 14:47:28 +0100 >Subject: [PATCH] Bug 23354: Add tests for Koha::Charges::Sales > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Charges/Sales.pm | 267 +++++++++++++++++++++++++++ > 1 file changed, 267 insertions(+) > create mode 100644 t/db_dependent/Koha/Charges/Sales.pm > >diff --git a/t/db_dependent/Koha/Charges/Sales.pm b/t/db_dependent/Koha/Charges/Sales.pm >new file mode 100644 >index 0000000000..8e637abb1d >--- /dev/null >+++ b/t/db_dependent/Koha/Charges/Sales.pm >@@ -0,0 +1,267 @@ >+#!/usr/bin/perl >+# >+# Copyright 2018 ByWater Solutions >+# >+# 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 Test::More tests => 5; >+use Test::Exception; >+ >+use Koha::Database; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+BEGIN { >+ use_ok('Koha::Charges::Sales'); >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new(); >+ >+subtest 'new' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ throws_ok { Koha::Charges::Sales->new( { staff_id => 1 } ) } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if cash_register parameter missing'; >+ >+ throws_ok { Koha::Charges::Sales->new( { cash_register => 1 } ) } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if staff_id parameter missing'; >+ >+ throws_ok { >+ Koha::Charges::Sales->new( { staff_id => 1, cash_register => 1 } ) >+ } >+ qr/Koha::Cash::Register/, >+ 'Exception thrown if cash_register is not a Koha::Cash::Register'; >+ >+ my $cash_register = >+ $builder->build_object( { class => 'Koha::Cash::Registers' } ); >+ >+ my $sale = Koha::Charges::Sales->new( >+ { staff_id => 1, cash_register => $cash_register } ); >+ ok( >+ $sale->isa('Koha::Charges::Sales'), >+ 'New returns a Koha::Charges::Sales object' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'payment_type (_get_valid_payments) tests' => sub { >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $cash_register = $builder->build_object( >+ { >+ class => 'Koha::Cash::Registers', >+ value => { branchcode => $library1->branchcode } >+ } >+ ); >+ >+ my $sale = Koha::Charges::Sales->new( >+ { staff_id => 1, cash_register => $cash_register } ); >+ >+ is( $sale->payment_type, undef, "payment_type does not have a default" ); >+ >+ throws_ok { $sale->payment_type('BOBBYRANDOM') } >+ 'Koha::Exceptions::Account::UnrecognisedType', >+ "Exception thrown if passed a payment type that doesn't exist"; >+ >+ my $av = Koha::AuthorisedValue->new( >+ { >+ category => 'PAYMENT_TYPE', >+ authorised_value => 'BOBBYRANDOM', >+ lib => 'Test bobbyrandom', >+ lib_opac => 'Test bobbyrandom', >+ } >+ )->store; >+ $av->replace_library_limits( [ $library2->branchcode ] ); >+ >+ throws_ok { $sale->payment_type('BOBBYRANDOM') } >+ 'Koha::Exceptions::Account::UnrecognisedType', >+'Exception thrown if passed payment type that is not valid for the cash registers branch'; >+ >+ $av->replace_library_limits(); >+ $sale->{valid_payments} = undef; # Flush object cache for 'valid_payments' >+ >+ my $pt = $sale->payment_type('BOBBYRANDOM'); >+ is( $pt, 'BOBBYRANDOM', 'Payment type set successfully' ); >+ is( $sale->payment_type, 'BOBBYRANDOM', >+ 'Getter returns the current payment_type' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'add_item (_get_valid_items) tests' => sub { >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $staff = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $cash_register = $builder->build_object( >+ { >+ class => 'Koha::Cash::Registers', >+ value => { branchcode => $library1->branchcode } >+ } >+ ); >+ >+ my $sale = Koha::Charges::Sales->new( >+ { staff_id => $staff->borrowernumber, cash_register => $cash_register } >+ ); >+ >+ throws_ok { $sale->add_item( { price => 1.00, quantity => 1 } ) } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if `code` parameter is missing'; >+ >+ my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $av = Koha::AuthorisedValue->new( >+ { >+ category => 'MANUAL_INV', >+ authorised_value => 'BOBBYRANDOM', >+ lib => 'Test bobbyrandom', >+ lib_opac => 'Test bobbyrandom', >+ } >+ )->store; >+ $av->replace_library_limits( [ $library2->branchcode ] ); >+ >+ throws_ok { $sale->add_item( { code => 'BOBBYRANDOM' } ) } >+ 'Koha::Exceptions::Account::UnrecognisedType', >+'Exception thrown if passed an item code that is not valid for the cash registers branch'; >+ >+ $av->replace_library_limits(); >+ $sale->{valid_items} = undef; # Flush object cache for 'valid_items' >+ >+ throws_ok { >+ $sale->add_item( { code => 'BOBBYRANDOM', quantity => 1 } ) >+ } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if `price` parameter is missing'; >+ >+ throws_ok { >+ $sale->add_item( { code => 'BOBBYRANDOM', price => 1.00 } ) >+ } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if `quantity` parameter is missing'; >+ >+ is( >+ ref( >+ $sale->add_item( >+ { code => 'BOBBYRANDOM', price => 1.00, quantity => 1 } >+ ) >+ ), >+ 'Koha::Charges::Sales', >+ 'Original object returned succesfully' >+ ); >+ >+ is( scalar @{ $sale->{items} }, 1, 'Item added successfully' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'purchase tests' => sub { >+ plan tests => 12; >+ >+ $schema->storage->txn_begin; >+ >+ my $staff = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $cash_register = $builder->build_object( >+ { >+ class => 'Koha::Cash::Registers', >+ value => { branchcode => $library->branchcode } >+ } >+ ); >+ >+ my $payment_type = Koha::AuthorisedValue->new( >+ { >+ category => 'PAYMENT_TYPE', >+ authorised_value => 'CASH', >+ lib => 'Cash transaction', >+ lib_opac => 'Cash transaction', >+ } >+ )->store; >+ >+ my $item1 = Koha::AuthorisedValue->new( >+ { >+ category => 'MANUAL_INV', >+ authorised_value => 'COPYRANDOM', >+ lib => 'Copier fee', >+ lib_opac => 'Copier fee', >+ } >+ )->store; >+ my $item2 = Koha::AuthorisedValue->new( >+ { >+ category => 'MANUAL_INV', >+ authorised_value => 'CARDRANDOM', >+ lib => 'New card fee', >+ lib_opac => 'New card fee', >+ } >+ )->store; >+ >+ my $sale = Koha::Charges::Sales->new( >+ { staff_id => $staff->borrowernumber, cash_register => $cash_register } >+ ); >+ >+ throws_ok { >+ $sale->purchase() >+ } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if `payment_type` is neither set nor passed'; >+ >+ $sale->payment_type('CASH'); # Set payment_type >+ throws_ok { >+ $sale->purchase() >+ } >+ 'Koha::Exceptions::NoChanges', >+ 'Exception thrown if `add_item` is not called before `purchase`'; >+ >+ $sale->add_item( { code => 'COPYRANDOM', price => 1.00, quantity => 1 } ); >+ $sale->add_item( { code => 'CARDRANDOM', price => 2.00, quantity => 2 } ); >+ >+ $sale->{payment_type} = undef; # Flush payment_type cache in object >+ >+ my $credit; >+ ok( $credit = $sale->purchase( { payment_type => 'CASH' } ), >+ "No exception when payment_type passed" ); >+ >+ is(ref($credit), 'Koha::Account::Line', "Koha::Account::Line returned"); >+ ok($credit->is_credit, "return is a credit for payment"); >+ is($credit->accounttype, 'Purchase', "accounttype set correctly to 'Purchase' for payment"); >+ is($credit->amount, -5.00, "amount is calculated correctly for payment"); >+ is($credit->amountoutstanding, 0.00, "amountoutstanding is set to zero for payment"); >+ is($credit->manager_id, $staff->borrowernumber, "manager_id set correctionly for payment"); >+ is($credit->register_id, $cash_register->id, "register_id set correctly for payment"); >+ is($credit->payment_type, 'CASH', "payment_type set correctly for payment"); >+ >+ my $offsets = Koha::Account::Offsets->search({credit_id => $credit->accountlines_id}); >+ is($offsets->count, 2, "One offset was added for each item added"); >+ >+#ensure relevant fields are set >+#ensure register_id is only ever set with a corresponding payment_type having been set >+ >+ $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 23354
:
92066
|
92431
|
92432
|
92433
|
92502
|
92830
|
92831
|
92832
|
92833
|
92834
|
92873
|
92874
|
92875
|
92876
|
92877
|
92878
|
92890
|
92891
|
92892
|
92893
|
92894
|
92895
|
93116
|
93117
|
93118
|
93119
|
93120
|
93121
|
93122
|
93123
|
93124
|
93465
|
93466
|
93467
|
93468
|
93469
|
93470
|
93471
|
93472
|
93473
|
93604
|
93605
|
93606
|
93607
|
93608
|
93609
|
93610
|
93611
|
93612
|
94689
|
94690
|
94691
|
94692
|
94693
|
94694
|
94695
|
94696
|
94697
|
94698
|
94699
|
95678
|
95679
|
95680
|
95681
|
95682
|
95683
|
95684
|
95685
|
95686
|
95687
|
95688
|
95689
|
95690
|
95691
|
95692
|
95693
|
97013
|
97014
|
97015
|
97016
|
97017
|
97018
|
97019
|
97020
|
97021
|
97022
|
97023
|
97024
|
97025
|
97026
|
97027
|
97028
|
97029
|
97169
|
97170
|
97171
|
97188
|
97189
|
97200
|
97201
|
97202
|
97203
|
97204
|
97205
|
97206
|
97207
|
97208
|
97209
|
97210
|
97211
|
97212
|
97213
|
97214
|
97215
|
97216
|
97217
|
97218
|
97219
|
97271
|
97272
|
97273
|
97274
|
97275
|
97276
|
97277
|
97278
|
97279
|
97280
|
97281
|
97282
|
97283
|
97284
|
97285
|
97286
|
97287
|
97288
|
97289
|
97290
|
97291
|
97292
|
97725
|
97726
|
100167