From 0623a4ea4a0a8481dca834cb4a0ff6123d19517b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 17 Jul 2019 12:39:49 +0100 Subject: [PATCH] Bug 23321: Koha::Library additions This patch adds the relationship accessor for Cash::Registers to the Koha::Library class and include the relevant tests. Signed-off-by: Maryse Simard --- Koha/Library.pm | 12 ++++++++++++ t/db_dependent/Koha/Libraries.t | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Koha/Library.pm b/Koha/Library.pm index f1a5597..6870e84 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -77,6 +77,18 @@ sub library_groups { return Koha::Library::Groups->_new_from_dbic( $rs ); } +=head3 cash_registers + +Return Cash::Registers associated with this Library + +=cut + +sub cash_registers { + my ( $self ) = @_; + my $rs = $self->_result->cash_registers; + return Koha::Cash::Registers->_new_from_dbic( $rs ); +} + =head2 Internal methods =head3 _type diff --git a/t/db_dependent/Koha/Libraries.t b/t/db_dependent/Koha/Libraries.t index 5c356c1..d58d059 100644 --- a/t/db_dependent/Koha/Libraries.t +++ b/t/db_dependent/Koha/Libraries.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use C4::Biblio; use C4::Context; @@ -451,3 +451,38 @@ subtest '->get_effective_marcorgcode' => sub { $schema->storage->txn_rollback; }; + +subtest 'cash_registers' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $register1 = $builder->build_object( + { + class => 'Koha::Cash::Registers', + value => { branch => $library->branchcode }, + } + ); + my $register2 = $builder->build_object( + { + class => 'Koha::Cash::Registers', + value => { branch => $library->branchcode }, + } + ); + + my $registers = $library->cash_registers; + is( ref($registers), 'Koha::Cash::Registers', +'Koha::Library->cash_registers should return a set of Koha::Cash::Registers' + ); + is( $registers->count, 2, + 'Koha::Library->cash_registers should return the correct cash registers' + ); + + $register1->delete; + is( $library->cash_registers->next->id, $register2->id, + 'Koha::Library->cash_registers should return the correct cash registers' + ); + + $schema->storage->txn_rollback; +}; -- 2.7.4