From afc7f979437c43815310fda42feceab4676cd895 Mon Sep 17 00:00:00 2001 From: Florent Mara Date: Tue, 31 May 2016 16:32:56 +1200 Subject: [PATCH] bug 15896 - A few tests for Koha::Account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc VĂ©ron --- t/db_dependent/Koha/Account.t | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 t/db_dependent/Koha/Account.t diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t new file mode 100644 index 0000000..47a3c44 --- /dev/null +++ b/t/db_dependent/Koha/Account.t @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +# Copyright 2015 Koha Development team +# +# 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 . + +use Modern::Perl; +use Test::More tests => 5; + +# use t::lib::Mocks; +use Koha::Database; + +use t::lib::TestBuilder; +my $builder = t::lib::TestBuilder->new(); + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +# ########## Tests start here ############################# +# Given ... we can use the module +BEGIN { use_ok('Koha::Account'); } + +subtest 'test_methods' => sub { + plan tests => 1; + + # Given ... we can reach the method(s) + my @methods = ( + 'pay', + ); + can_ok('Koha::Account', @methods); +}; + +# Given ... a random patron_id, a Koha::Account object can be created +my $patron_id_0 = 654321; + +# When ... +my $koha_account_0 = Koha::Account->new( { patron_id => $patron_id_0 } ); + +# Then ... +isa_ok($koha_account_0, 'Koha::Account'); +is($koha_account_0->{patron_id}, $patron_id_0, 'Got the expected patron_id value from calling Koha:;Account->new()'); + +# FIXME pay() method does not deal with absence of parameters and die on +# Use of uninitialized value $amount in subtraction (-) at /var/koha/Koha/Koha/Account.pm line 175 +# ... +# Given ... calling on pay() with no params - just for fun. +# my $params_1 = {}; + +# When ... Then ... +# my $payment_id_1 = $koha_account_0->pay($params_1); +# is($payment_id_1, undef, 'Got the expected undef payment id from Koha account pay with no params'); + +# Given ... an amount parameter and a borrower number +my $amount_2 = 90; +my $params_2 = { amount => $amount_2, }; + +$dbh->do("INSERT INTO borrowers(borrowernumber, surname, address, city, branchcode, categorycode, userid) VALUES ('.$patron_id_0.','Washington','address','city', 'IPT', 'HB', 'userid')"); + +# When ... +my $payment_id_2 = $koha_account_0->pay($params_2); + +# Then ... +ok($payment_id_2, 'Got some data back from Koha account pay with an amount'); + +# my $sth_2 = $dbh->prepare('SELECT * FROM accountlines WHERE borrowernumber = ?'); +# my $acc_line = $sth_2->execute($patron_id_0); +# my $result_2 = $sth_2->fetchrow(); + + +$schema->storage->txn_rollback; + +1; -- 2.1.4