Bug 21073: (QA follow-up) Add ->is_enabled and tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 17 Jun 2019 11:06:23 +0000 (08:06 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 18 Jun 2019 16:30:25 +0000 (17:30 +0100)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Plugins/Base.pm
t/db_dependent/Plugins.t

index 392ab4c..b311a77 100644 (file)
@@ -272,6 +272,20 @@ sub _version_compare {
     return 0;
 }
 
+=head2 is_enabled
+
+Method that returns wether the plugin is enabled or not
+
+$plugin->enable
+
+=cut
+
+sub is_enabled {
+    my ($self) = @_;
+
+    return $self->retrieve_data( '__ENABLED__' );
+}
+
 =head2 enable
 
 Method for enabling plugin
index 53ae26e..5723d02 100755 (executable)
@@ -23,7 +23,7 @@ use File::Temp qw( tempdir tempfile );
 use FindBin qw($Bin);
 use Module::Load::Conditional qw(can_load);
 use Test::MockModule;
-use Test::More tests => 50;
+use Test::More tests => 51;
 
 use C4::Context;
 use Koha::Database;
@@ -109,6 +109,29 @@ subtest 'Version upgrade tests' => sub {
     $schema->storage->txn_rollback;
 };
 
+subtest 'is_enabled() tests' => sub {
+
+    plan tests => 3;
+    $schema->storage->txn_begin;
+
+    # Make sure there's no previous installs or leftovers on DB
+    Koha::Plugins::Methods->delete;
+    $schema->resultset('PluginData')->delete;
+
+    my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new });
+    ok( $plugin->is_enabled, 'Plugins enabled by default' );
+
+    # disable
+    $plugin->disable;
+    ok( !$plugin->is_enabled, 'Calling ->disable disables the plugin' );
+
+    # enable
+    $plugin->enable;
+    ok( $plugin->is_enabled, 'Calling ->enable enabled the plugin' );
+
+    $schema->storage->txn_rollback;
+};
+
 $schema->storage->txn_begin;
 Koha::Plugins::Methods->delete;