| Lines 24-30
          use File::Temp qw( tempdir tempfile );
      
      
        Link Here | 
        
          | 24 | use FindBin qw($Bin); | 24 | use FindBin qw($Bin); | 
        
          | 25 | use Module::Load::Conditional qw(can_load); | 25 | use Module::Load::Conditional qw(can_load); | 
        
          | 26 | use Test::MockModule; | 26 | use Test::MockModule; | 
          
            
              | 27 | use Test::More tests => 50; | 27 | use Test::More tests => 16; | 
        
          | 28 | use Test::Warn; | 28 | use Test::Warn; | 
        
          | 29 |  | 29 |  | 
        
          | 30 | use C4::Context; | 30 | use C4::Context; | 
  
    | Lines 230-323
          subtest 'is_enabled() tests' => sub {
      
      
        Link Here | 
        
          | 230 |     $schema->storage->txn_rollback; | 230 |     $schema->storage->txn_rollback; | 
        
          | 231 | }; | 231 | }; | 
        
          | 232 |  | 232 |  | 
          
            
              | 233 | $schema->storage->txn_begin; | 233 | subtest 'Koha::Plugin::Test' => sub { | 
            
              | 234 | Koha::Plugins::Methods->delete; | 234 |     $schema->storage->txn_begin; | 
            
              | 235 | $schema->resultset('PluginData')->delete; | 235 |     Koha::Plugins::Methods->delete; | 
            
              | 236 |  | 236 |     $schema->resultset('PluginData')->delete; | 
            
              | 237 | warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef; | 237 |  | 
            
              | 238 |  | 238 |     warning_is { Koha::Plugins->new( { enable_plugins => 1 } )->InstallPlugins(); } undef; | 
            
              | 239 | ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' ); | 239 |  | 
            
              | 240 | is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' ); | 240 |     ok( Koha::Plugins::Methods->search( { plugin_class => 'Koha::Plugin::Test' } )->count, 'Test plugin methods added to database' ); | 
            
              | 241 |  | 241 |     is( Koha::Plugins::Methods->search({ plugin_class => 'Koha::Plugin::Test', plugin_method => '_private_sub' })->count, 0, 'Private methods are skipped' ); | 
            
              | 242 | my $mock_plugin = Test::MockModule->new( 'Koha::Plugin::Test' ); | 242 |  | 
            
              | 243 | $mock_plugin->mock( 'test_template', sub { | 243 |     my $mock_plugin = Test::MockModule->new( 'Koha::Plugin::Test' ); | 
            
              | 244 |     my ( $self, $file ) = @_; | 244 |     $mock_plugin->mock( 'test_template', sub { | 
            
              | 245 |     my $template = $self->get_template({ file => $file }); | 245 |         my ( $self, $file ) = @_; | 
            
              | 246 |     $template->param( filename => $file ); | 246 |         my $template = $self->get_template({ file => $file }); | 
            
              | 247 |     return $template->output; | 247 |         $template->param( filename => $file ); | 
            
              | 248 | }); | 248 |         return $template->output; | 
            
              | 249 |  | 249 |     }); | 
            
              | 250 | ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' ); | 250 |  | 
            
              | 251 |  | 251 |     ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' ); | 
            
              | 252 | my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new }); | 252 |  | 
            
              | 253 |  | 253 |     my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new }); | 
            
              | 254 | isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' ); | 254 |  | 
            
              | 255 | isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' ); | 255 |     isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' ); | 
            
              | 256 |  | 256 |     isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' ); | 
            
              | 257 | ok( $plugin->can('report'), 'Test plugin can report' ); | 257 |  | 
            
              | 258 | ok( $plugin->can('tool'), 'Test plugin can tool' ); | 258 |     ok( $plugin->can('report'), 'Test plugin can report' ); | 
            
              | 259 | ok( $plugin->can('to_marc'), 'Test plugin can to_marc' ); | 259 |     ok( $plugin->can('tool'), 'Test plugin can tool' ); | 
            
              | 260 | ok( $plugin->can('intranet_catalog_biblio_enhancements'), 'Test plugin can intranet_catalog_biblio_enhancements'); | 260 |     ok( $plugin->can('to_marc'), 'Test plugin can to_marc' ); | 
            
              | 261 | ok( $plugin->can('intranet_catalog_biblio_enhancements_toolbar_button'), 'Test plugin can intranet_catalog_biblio_enhancements_toolbar_button' ); | 261 |     ok( $plugin->can('intranet_catalog_biblio_enhancements'), 'Test plugin can intranet_catalog_biblio_enhancements'); | 
            
              | 262 | ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' ); | 262 |     ok( $plugin->can('intranet_catalog_biblio_enhancements_toolbar_button'), 'Test plugin can intranet_catalog_biblio_enhancements_toolbar_button' ); | 
            
              | 263 | ok( $plugin->can('after_hold_create'), 'Test plugin can after_hold_create' ); | 263 |     ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' ); | 
            
              | 264 | ok( $plugin->can('opac_online_payment_begin'), 'Test plugin can opac_online_payment_begin' ); | 264 |     ok( $plugin->can('after_hold_create'), 'Test plugin can after_hold_create' ); | 
            
              | 265 | ok( $plugin->can('opac_online_payment_end'), 'Test plugin can opac_online_payment_end' ); | 265 |     ok( $plugin->can('opac_online_payment_begin'), 'Test plugin can opac_online_payment_begin' ); | 
            
              | 266 | ok( $plugin->can('opac_head'), 'Test plugin can opac_head' ); | 266 |     ok( $plugin->can('opac_online_payment_end'), 'Test plugin can opac_online_payment_end' ); | 
            
              | 267 | ok( $plugin->can('opac_js'), 'Test plugin can opac_js' ); | 267 |     ok( $plugin->can('opac_head'), 'Test plugin can opac_head' ); | 
            
              | 268 | ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' ); | 268 |     ok( $plugin->can('opac_js'), 'Test plugin can opac_js' ); | 
            
              | 269 | ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' ); | 269 |     ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' ); | 
            
              | 270 | ok( $plugin->can('item_barcode_transform'), 'Test plugin can barcode_transform' ); | 270 |     ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' ); | 
            
              | 271 | ok( $plugin->can('configure'), 'Test plugin can configure' ); | 271 |     ok( $plugin->can('item_barcode_transform'), 'Test plugin can barcode_transform' ); | 
            
              | 272 | ok( $plugin->can('install'), 'Test plugin can install' ); | 272 |     ok( $plugin->can('configure'), 'Test plugin can configure' ); | 
            
              | 273 | ok( $plugin->can('upgrade'), 'Test plugin can upgrade' ); | 273 |     ok( $plugin->can('install'), 'Test plugin can install' ); | 
            
              | 274 | ok( $plugin->can('uninstall'), 'Test plugin can install' ); | 274 |     ok( $plugin->can('upgrade'), 'Test plugin can upgrade' ); | 
            
              | 275 |  | 275 |     ok( $plugin->can('uninstall'), 'Test plugin can install' ); | 
            
              | 276 | is( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }), "Koha::Plugin::Test::report", 'Test run plugin report method' ); | 276 |  | 
            
              | 277 |  | 277 |     is( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 }), "Koha::Plugin::Test::report", 'Test run plugin report method' ); | 
            
              | 278 | my $metadata = $plugin->get_metadata(); | 278 |  | 
            
              | 279 | is( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' ); | 279 |     my $metadata = $plugin->get_metadata(); | 
            
              | 280 |  | 280 |     is( $metadata->{'name'}, 'Test Plugin', 'Test $plugin->get_metadata()' ); | 
            
              | 281 | is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' ); | 281 |  | 
            
              | 282 | is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' ); | 282 |     is( $plugin->get_qualified_table_name('mytable'), 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' ); | 
            
              | 283 |  | 283 |     is( $plugin->get_plugin_http_path(), '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' ); | 
            
              | 284 | # test absolute path change in get_template with Koha::Plugin::Test | 284 |  | 
            
              | 285 | # using the mock set before | 285 |     # test absolute path change in get_template with Koha::Plugin::Test | 
            
              | 286 | # we also add tmpdir as an approved template dir | 286 |     # using the mock set before | 
            
              | 287 | t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context->temporary_directory ] ); | 287 |     # we also add tmpdir as an approved template dir | 
            
              | 288 | my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context->temporary_directory ); | 288 |     t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context->temporary_directory ] ); | 
            
              | 289 | print $fh 'I am [% filename %]'; | 289 |     my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context->temporary_directory ); | 
            
              | 290 | close $fh; | 290 |     print $fh 'I am [% filename %]'; | 
            
              | 291 | my $classname = ref($plugin); | 291 |     close $fh; | 
            
              | 292 | like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' ); | 292 |     my $classname = ref($plugin); | 
            
              | 293 |  | 293 |     like( $plugin->test_template($fn), qr/^I am $fn/, 'Template works' ); | 
            
              | 294 | my $result = $plugin->enable; | 294 |  | 
            
              | 295 | is( ref($result), 'Koha::Plugin::Test' ); | 295 |     my $result = $plugin->enable; | 
            
              | 296 |  | 296 |     is( ref($result), 'Koha::Plugin::Test' ); | 
            
              | 297 | # testing GetPlugins | 297 |  | 
            
              | 298 | my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ | 298 |     # testing GetPlugins | 
            
              | 299 |     method => 'report' | 299 |     my @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ | 
            
              | 300 | }); | 300 |         method => 'report' | 
            
              | 301 |  | 301 |     }); | 
            
              | 302 | my @names = map { $_->get_metadata()->{'name'} } @plugins; | 302 |  | 
            
              | 303 | is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" ); | 303 |     my @names = map { $_->get_metadata()->{'name'} } @plugins; | 
            
              | 304 | @plugins =  Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ | 304 |     is( scalar grep( /^Test Plugin$/, @names), 1, "Koha::Plugins::GetPlugins functions correctly" ); | 
            
              | 305 |     metadata => { my_example_tag  => 'find_me' }, | 305 |     @plugins =  Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ | 
            
              | 306 | }); | 306 |         metadata => { my_example_tag  => 'find_me' }, | 
            
              | 307 |  | 307 |     }); | 
            
              | 308 | @names = map { $_->get_metadata()->{'name'} } @plugins; | 308 |  | 
            
              | 309 | is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" ); | 309 |     @names = map { $_->get_metadata()->{'name'} } @plugins; | 
            
              | 310 |  | 310 |     is( scalar grep( /^Test Plugin$/, @names), 1, "GetPlugins also found Test Plugin via a metadata tag" ); | 
            
              | 311 | $result = $plugin->disable; | 311 |  | 
            
              | 312 | is( ref($result), 'Koha::Plugin::Test' ); | 312 |     $result = $plugin->disable; | 
            
              | 313 |  | 313 |     is( ref($result), 'Koha::Plugin::Test' ); | 
            
              | 314 | @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins(); | 314 |  | 
            
              | 315 | @names = map { $_->get_metadata()->{'name'} } @plugins; | 315 |     @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins(); | 
            
              | 316 | is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disabled Test Plugin" ); | 316 |     @names = map { $_->get_metadata()->{'name'} } @plugins; | 
            
              | 317 |  | 317 |     is( scalar grep( /^Test Plugin$/, @names), 0, "GetPlugins does not found disabled Test Plugin" ); | 
            
              | 318 | @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ all => 1 }); | 318 |  | 
            
              | 319 | @names = map { $_->get_metadata()->{'name'} } @plugins; | 319 |     @plugins = Koha::Plugins->new({ enable_plugins => 1 })->GetPlugins({ all => 1 }); | 
            
              | 320 | is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" ); | 320 |     @names = map { $_->get_metadata()->{'name'} } @plugins; | 
            
              |  |  | 321 |     is( scalar grep( /^Test Plugin$/, @names), 1, "With all param, GetPlugins found disabled Test Plugin" ); | 
            
              | 322 |  | 
            
              | 323 |     $schema->storage->txn_rollback; | 
            
              | 324 | }; | 
            
              | 325 |  | 
            
              | 326 | $schema->storage->txn_begin;    # matching rollback at the very end | 
        
          | 321 |  | 327 |  | 
        
          | 322 | subtest 'output and output_html tests' => sub { | 328 | subtest 'output and output_html tests' => sub { | 
        
          | 323 |  | 329 |  | 
            
              | 324 | -  |  |  |