@@ -, +, @@ --- Koha/Libraries.pm | 18 ++++++++++++++++++ t/db_dependent/Koha/Libraries.t | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) --- a/Koha/Libraries.pm +++ a/Koha/Libraries.pm @@ -64,6 +64,24 @@ sub search_filtered { return $self->SUPER::search( $params, $attributes ); } +=head3 singleLibraryMode + + Aka singleBranchMode. + + my $boolean = Koha::Libraries->singleLibaryMode; + + Returns 1 if there is only one library marked public. + +=cut + +sub singleLibraryMode { # formerly called singleBranchMode + my $self = shift; + if( $self->search({ public => 1 })->count == 1 ) { # Historically we test number==1 instead of number<2 + return 1; + } + return 0; +} + =head3 type =cut --- a/t/db_dependent/Koha/Libraries.t +++ a/t/db_dependent/Koha/Libraries.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 13; use C4::Biblio; use C4::Context; @@ -365,3 +365,17 @@ subtest 'outgoing_transfers' => sub { $schema->storage->txn_rollback; }; + +subtest 'singleLibrarymode aka singleBranchMode' => sub { + plan tests => 3; + $schema->storage->txn_begin; + + Koha::Libraries->new->update({ public => 0 }); + is( Koha::Libraries->singleLibraryMode, 0, 'No public libraries' ); + my $library1 = $builder->build_object({ class => 'Koha::Libraries', value => { public => 1 } }); + is( Koha::Libraries->singleLibraryMode, 1, 'One public library' ); + my $library2 = $builder->build_object({ class => 'Koha::Libraries', value => { public => 1 } }); + is( Koha::Libraries->singleLibraryMode, 0, 'Two public libraries' ); + + $schema->storage->txn_rollback; +}; --