@@ -, +, @@ $ ktd --shell k$ prove t/db_dependent/Koha/Library.t --- Koha/Library.pm | 14 ++++++++++++++ t/db_dependent/Koha/Library.t | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) --- a/Koha/Library.pm +++ a/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 --- a/t/db_dependent/Koha/Library.t +++ a/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; +}; --