From 0b72c3c068c47efd02dd18505e6c677cf518fa4d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 17 Sep 2019 12:24:01 +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. Sponsored-by: PTFS Europe Sponsored-by: Cheshire Libraries Shared Services Signed-off-by: Maryse Simard Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- 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 f1a5597305..6870e84cc4 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 5c356c1998..d58d0592a9 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.39.5