Bug 22053: (QA follow-up) Fix tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 10 May 2019 14:52:34 +0000 (11:52 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 10 May 2019 16:57:46 +0000 (16:57 +0000)
This patch makes the tests enable the plugins that are required for
them. Otherwise unexpected failures can happen

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

t/db_dependent/ImportBatch.t
t/db_dependent/Koha/Template/Plugin/KohaPlugins.t

index f42e0d8..bcc25ef 100644 (file)
@@ -187,7 +187,8 @@ subtest "RecordsFromMarcPlugin" => sub {
     close $fh;
 
     t::lib::Mocks::mock_config( 'enable_plugins', 1 );
-    my ( $plugin ) = Koha::Plugins->new->GetPlugins({ metadata => { name => 'MarcFieldValues' } });
+    t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
+    my ($plugin) = Koha::Plugins->new->GetPlugins({ all => 1, metadata => { name => 'MarcFieldValues' } });
     isnt( $plugin, undef, "Plugin found" );
     my $records = C4::ImportBatch::RecordsFromMarcPlugin( $name, ref $plugin, 'UTF-8' );
     is( @$records, 2, 'Two results returned' );
index b0d50e6..5ecc1cd 100755 (executable)
@@ -24,6 +24,16 @@ BEGIN {
     use_ok('Koha::Plugin::Test');
 }
 
+t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 );
+t::lib::Mocks::mock_config( 'enable_plugins', 1 );
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+# Enable all plugins
+my @plugins = Koha::Plugins->new->GetPlugins({ all => 1, class => 'Koha::Plugin::Test' });
+map { $_->enable; } @plugins;
+
 my $mock_plugin = Test::MockModule->new( 'Koha::Plugin::Test' );
 $mock_plugin->mock( 'test_template', sub {
     my ( $self, $file ) = @_;
@@ -36,8 +46,6 @@ use_ok( 'Koha::Template::Plugin::KohaPlugins', 'Can use Koha::Template::Plugin::
 
 ok( my $plugin = Koha::Template::Plugin::KohaPlugins->new(), 'Able to instantiate template plugin' );
 
-t::lib::Mocks::mock_preference('UseKohaPlugins',1);
-t::lib::Mocks::mock_config('enable_plugins',1);
 ok( index( $plugin->get_plugins_opac_js, 'Koha::Plugin::Test::opac_js' ) != -1, 'Test plugin opac_js return value is part of code returned by get_plugins_opac_js' );
 ok( index( $plugin->get_plugins_opac_head, 'Koha::Plugin::Test::opac_head' ) != -1, 'Test plugin opac_head return value is part of code returned by get_plugins_opac_head' );
 ok( index( $plugin->get_plugins_intranet_js, 'Koha::Plugin::Test::intranet_js' ) != -1, 'Test plugin intranet_js return value is part of code returned by get_plugins_intranet_js' );
@@ -49,3 +57,5 @@ is( $plugin->get_plugins_opac_js, q{}, 'Test plugin opac_js return value is empt
 is( $plugin->get_plugins_opac_head, q{}, 'Test plugin opac_head return value is empty' );
 is( $plugin->get_plugins_intranet_js, q{}, 'Test plugin intranet_js return value is empty' );
 is( $plugin->get_plugins_intranet_head, q{}, 'Test plugin intranet_head return value is empty' );
+
+$schema->storage->txn_rollback;