From 6b3640d80e10e73e460b563fabb3f12ee669bb12 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 14 Apr 2020 16:21:37 -0300 Subject: [PATCH] Bug 25131: Add C4::Context->needs_install This trivial patch adds a new convenient way to ask if Koha is installed. It uses the same approach as C4::Auth:730 To test: 1. Apply this patch 2. Run: $ kshell k$ t/Context.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: David Nind Signed-off-by: Kyle M Hall --- C4/Context.pm | 13 +++++++++++++ t/Context.t | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/C4/Context.pm b/C4/Context.pm index df4b5dbbc6..6f7baeaf2d 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -1073,6 +1073,19 @@ sub set_remote_address { 1; +=head3 needs_install + + if ( $context->needs_install ) { ... } + +This method returns a boolean representing the install status of the Koha instance. + +=cut + +sub needs_install { + my ($self) = @_; + return ($self->preference('Version')) ? 0 : 1; +} + __END__ =head1 ENVIRONMENT diff --git a/t/Context.t b/t/Context.t index ea26ac755e..c2dbbfddff 100755 --- a/t/Context.t +++ b/t/Context.t @@ -18,11 +18,13 @@ use Modern::Perl; use DBI; -use Test::More tests => 28; +use Test::More tests => 29; use Test::MockModule; use Test::Warn; use YAML; +use t::lib::Mocks; + BEGIN { use_ok('C4::Context'); } @@ -50,6 +52,17 @@ subtest 'yaml_preference() tests' => sub { $context->unmock( 'preference' ); }; +subtest 'needs_install() tests' => sub { + + plan tests => 2; + + t::lib::Mocks::mock_preference( 'Version', '3.0.0' ); + is( C4::Context->needs_install, 0, 'Preference is defined, no need to install' ); + + t::lib::Mocks::mock_preference( 'Version', undef ); # the behaviour when ->preference fails to fetch + is( C4::Context->needs_install, 1, "->preference(Version) is not defined, need to install" ); +}; + my $context = new Test::MockModule('C4::Context'); my $userenv = {}; -- 2.24.1 (Apple Git-126)