From 0cf193f7399e452ed29a9924b46494c575df7dd4 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 1 Apr 2024 20:22:22 +0000 Subject: [PATCH] Bug 36480: Add Koha::Library->desks We add an accessor for the related desks. Tests are added. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Library.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: David Nind Signed-off-by: Pedro Amorim Signed-off-by: Katrin Fischer (cherry picked from commit 7f7f486d94e52eb50d070ccead61c94928aeff28) Signed-off-by: Fridolin Somers --- Koha/Library.pm | 14 ++++++++++++++ t/db_dependent/Koha/Library.t | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Koha/Library.pm b/Koha/Library.pm index decfa13617..65c784d683 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -24,6 +24,7 @@ use C4::Context; use Koha::Caches; use Koha::Database; +use Koha::Desks; use Koha::StockRotationStages; use Koha::SMTP::Servers; @@ -269,6 +270,19 @@ sub cash_registers { return Koha::Cash::Registers->_new_from_dbic( $rs ); } +=head3 desks + + my $desks = $library->desks; + +Returns Koha::Desks associated with this library. + +=cut + +sub desks { + my ($self) = @_; + return Koha::Desks->_new_from_dbic( scalar $self->_result->desks ); +} + =head3 get_hold_libraries Return all libraries (including self) that belong to the same hold groups diff --git a/t/db_dependent/Koha/Library.t b/t/db_dependent/Koha/Library.t index 5c16eedb54..661803d815 100755 --- a/t/db_dependent/Koha/Library.t +++ b/t/db_dependent/Koha/Library.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Koha::Database; use Koha::AdditionalContents; @@ -161,3 +161,27 @@ subtest 'opac_info tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'desks() tests' => sub { + + plan tests => 5; + + $schema->storage->txn_begin; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $rs = $library->desks; + is( ref($rs), 'Koha::Desks' ); + is( $rs->count, 0, 'No desks' ); + + my $desk_1 = $builder->build_object( { class => 'Koha::Desks', value => { branchcode => $library->id } } ); + my $desk_2 = $builder->build_object( { class => 'Koha::Desks', value => { branchcode => $library->id } } ); + + $rs = $library->desks; + + is( $rs->count, 2 ); + is( $rs->next->id, $desk_1->id ); + is( $rs->next->id, $desk_2->id ); + + $schema->storage->txn_rollback; +}; -- 2.39.5