From 69559ce0dacf61dcbe95f00957cf2e70f4ebad50 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 20 Jan 2020 09:47:18 -0300 Subject: [PATCH] Bug 24459: Regression tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- t/db_dependent/Koha/Acquisition/Invoice.t | 70 +++++++++++++++++++++++++++++++ t/db_dependent/Koha/Patron.t | 40 +++++++++++++++++- 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 t/db_dependent/Koha/Acquisition/Invoice.t diff --git a/t/db_dependent/Koha/Acquisition/Invoice.t b/t/db_dependent/Koha/Acquisition/Invoice.t new file mode 100644 index 0000000000..e99f01f1c3 --- /dev/null +++ b/t/db_dependent/Koha/Acquisition/Invoice.t @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +# Copyright 2020 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 => 2; +use Test::MockModule; + +use t::lib::TestBuilder; + +use Koha::Database; +use Koha::DateUtils qw(dt_from_string); + +use_ok('Koha::Acquisition::Invoice'); + +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'to_api() tests' => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + my $invoice_class = Test::MockModule->new('Koha::Acquisition::Invoice'); + $invoice_class->mock( + 'algo', + sub { return 'algo' } + ); + + my $invoice = $builder->build_object( + { + class => 'Koha::Acquisition::Invoices', + value => { + closedate => undef + } + } + ); + + my $closed = $invoice->to_api->{closed}; + ok( defined $closed, 'closed is defined' ); + ok( !$closed, 'closedate is undef, closed evaluates to false' ); + + $invoice->closedate( dt_from_string )->store->discard_changes; + $closed = $invoice->to_api->{closed}; + ok( defined $closed, 'closed is defined' ); + ok( $closed, 'closedate is defined, closed evaluates to true' ); + + my $invoice_json = $invoice->to_api({ embed => { algo => {} } }); + ok( exists $invoice_json->{algo} ); + is_deeply( $invoice_json->{algo}, 'algo' ); + + $schema->storage->txn_rollback; +}; diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index adfcb60898..63b77c1573 100644 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,10 +19,11 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; use Koha::Database; +use Koha::DateUtils qw(dt_from_string); use Koha::Patrons; use Koha::Patron::Relationships; @@ -154,3 +155,40 @@ subtest 'add_enrolment_fee_if_needed() tests' => sub { $schema->storage->txn_rollback; }; }; + +subtest 'to_api() tests' => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + my $patron_class = Test::MockModule->new('Koha::Patron'); + $patron_class->mock( + 'algo', + sub { return 'algo' } + ); + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + debarred => undef + } + } + ); + + my $restricted = $patron->to_api->{restricted}; + ok( defined $restricted, 'restricted is defined' ); + ok( !$restricted, 'debarred is undef, restricted evaluates to false' ); + + $patron->debarred( dt_from_string->add( days => 1 ) )->store->discard_changes; + $restricted = $patron->to_api->{restricted}; + ok( defined $restricted, 'restricted is defined' ); + ok( $restricted, 'debarred is defined, restricted evaluates to true' ); + + my $patron_json = $patron->to_api({ embed => { algo => {} } }); + ok( exists $patron_json->{algo} ); + is( $patron_json->{algo}, 'algo' ); + + $schema->storage->txn_rollback; +}; -- 2.11.0