@@ -, +, @@ $ kshell k$ t/Context.t --- C4/Context.pm | 13 +++++++++++++ t/Context.t | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) --- a/C4/Context.pm +++ a/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 --- a/t/Context.t +++ a/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 = {}; --