From ac0ad9ddfd21fd0ed65e6f49429002274455a994 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Tue, 21 Jul 2020 11:06:27 +0200 Subject: [PATCH] Bug 25951: Add tests for Holds and Item related Objects Test plan: 1. apply patch 2. `prove t/db_dependent/Koha/Holds.t` and `t/db_dependent/Koha/Item/RelatedObjects.t` 3. all should be OK --- t/db_dependent/Koha/Holds.t | 15 +++++++-- t/db_dependent/Koha/Item/RelatedObjects.t | 55 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 t/db_dependent/Koha/Item/RelatedObjects.t diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t index 055dd18..6a8a4b4 100644 --- a/t/db_dependent/Koha/Holds.t +++ b/t/db_dependent/Koha/Holds.t @@ -35,7 +35,7 @@ $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; subtest 'DB constraints' => sub { - plan tests => 1; + plan tests => 2; my $patron = $builder->build_object({ class => 'Koha::Patrons' }); my $item = $builder->build_sample_item; @@ -55,7 +55,18 @@ subtest 'DB constraints' => sub { eval { $hold->priority(undef)->store } } qr{.*DBD::mysql::st execute failed: Column 'priority' cannot be null.*}, - 'DBD should have raised an error about priority that cannot be null'; + 'DBD should have raised an error about priority that cannot be null'; + + subtest 'Related objects' => sub { + plan tests => 3; + my $item = $hold->item; + is(ref($item), 'Koha::Item', 'Returns a Koha::Item resultset' ); + my $patron = $hold->borrower; + is(ref($patron), 'Koha::Patron', 'Returns a Koha::Patron resultset' ); + my $library = $hold->branch; + is(ref($library), 'Koha::Library', 'Returns a Koha::Branch resultset' ); + }; + }; subtest 'cancel' => sub { diff --git a/t/db_dependent/Koha/Item/RelatedObjects.t b/t/db_dependent/Koha/Item/RelatedObjects.t new file mode 100644 index 0000000..fff4119 --- /dev/null +++ b/t/db_dependent/Koha/Item/RelatedObjects.t @@ -0,0 +1,55 @@ +#!/usr/bin/perl + +# Copyright 2020 BULAC +# +# 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 C4::Biblio; +use C4::Circulation; + +use Koha::Items; +use Koha::Database; +use Koha::Old::Items; + +use List::MoreUtils qw(all); + +use t::lib::TestBuilder; +use t::lib::Mocks; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + + +$schema->storage->txn_begin; +my $library = $builder->build( { source => 'Branch' } ); +my $nb_of_items = Koha::Items->search->count; +my $biblio = $builder->build_sample_biblio(); +my $new_item = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + homebranch => $library->{branchcode}, + holdingbranch => $library->{branchcode}, + }); +my $home_branch = $new_item->home_branch; +is(ref($home_branch), 'Koha::Library', 'Returns a Koha::Library resultset' ); +my $holding_branch = $new_item->holding_branch; +is(ref($holding_branch), 'Koha::Library', 'Returns a Koha::Library resultset' ); +$schema->storage->txn_rollback; + + -- 2.1.4