| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
            
               | 
               | 
              1 | 
              #!/usr/bin/perl  | 
            
            
              | 2 | 
               | 
            
            
              | 3 | 
              # This file is part of Koha.  | 
            
            
              | 4 | 
              #  | 
            
            
              | 5 | 
              # Koha is free software; you can redistribute it and/or modify it under the  | 
            
            
              | 6 | 
              # terms of the GNU General Public License as published by the Free Software  | 
            
            
              | 7 | 
              # Foundation; either version 3 of the License, or (at your option) any later  | 
            
            
              | 8 | 
              # version.  | 
            
            
              | 9 | 
              #  | 
            
            
              | 10 | 
              # Koha is distributed in the hope that it will be useful, but WITHOUT ANY  | 
            
            
              | 11 | 
              # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR  | 
            
            
              | 12 | 
              # A PARTICULAR PURPOSE. See the GNU General Public License for more details.  | 
            
            
              | 13 | 
              #  | 
            
            
              | 14 | 
              # You should have received a copy of the GNU General Public License along  | 
            
            
              | 15 | 
              # with Koha; if not, see <http://www.gnu.org/licenses>.  | 
            
            
              | 16 | 
               | 
            
            
              | 17 | 
              use Modern::Perl;  | 
            
            
              | 18 | 
              use File::Basename;  | 
            
            
              | 19 | 
              use Test::More tests => 4;  | 
            
            
              | 20 | 
               | 
            
            
              | 21 | 
              use t::lib::Mocks;  | 
            
            
              | 22 | 
              use t::lib::TestBuilder;  | 
            
            
              | 23 | 
               | 
            
            
              | 24 | 
              use Koha::Database;  | 
            
            
              | 25 | 
               | 
            
            
              | 26 | 
              BEGIN { | 
            
            
              | 27 | 
                  # Mock pluginsdir before loading Plugins module  | 
            
            
              | 28 | 
                  my $path = dirname(__FILE__) . '/../../../../lib/plugins';  | 
            
            
              | 29 | 
                  t::lib::Mocks::mock_config( 'pluginsdir', $path );  | 
            
            
              | 30 | 
               | 
            
            
              | 31 | 
                  use_ok('Koha::Plugins'); | 
            
            
              | 32 | 
                  use_ok('Koha::Plugins::Handler'); | 
            
            
              | 33 | 
                  use_ok('Koha::Plugin::Test'); | 
            
            
              | 34 | 
              }  | 
            
            
              | 35 | 
               | 
            
            
              | 36 | 
              my $schema  = Koha::Database->new->schema;  | 
            
            
              | 37 | 
              my $builder = t::lib::TestBuilder->new;  | 
            
            
              | 38 | 
               | 
            
            
              | 39 | 
              t::lib::Mocks::mock_config( 'enable_plugins', 1 );  | 
            
            
              | 40 | 
               | 
            
            
              | 41 | 
              subtest 'get_backend_plugin(), new_ill_backend() and load_backend() tests' => sub { | 
            
            
              | 42 | 
               | 
            
            
              | 43 | 
                  plan tests => 6;  | 
            
            
              | 44 | 
               | 
            
            
              | 45 | 
                  $schema->storage->txn_begin;  | 
            
            
              | 46 | 
               | 
            
            
              | 47 | 
                  my $plugins = Koha::Plugins->new;  | 
            
            
              | 48 | 
                  $plugins->InstallPlugins;  | 
            
            
              | 49 | 
               | 
            
            
              | 50 | 
                  my $plugin = Koha::ILL::Request->new->get_backend_plugin('Test Plugin'); | 
            
            
              | 51 | 
               | 
            
            
              | 52 | 
                  is( ref($plugin), 'Koha::Plugin::Test', 'Returns our Test Plugin which implements the Test Plugin backend' );  | 
            
            
              | 53 | 
                  my $backend = $plugin->new_ill_backend();  | 
            
            
              | 54 | 
                  is( ref($backend), 'Koha::Plugin::Test::ILLBackend', 'Returns the right object class' );  | 
            
            
              | 55 | 
               | 
            
            
              | 56 | 
                  my $request = Koha::ILL::Request->new->load_backend('Test Plugin'); | 
            
            
              | 57 | 
                  ok( $request->{plugin}, 'Instantiated plugin stored for later use' ); | 
            
            
              | 58 | 
                  is( ref( $request->{plugin} ), 'Koha::Plugin::Test', 'Class is correct' ); | 
            
            
              | 59 | 
               | 
            
            
              | 60 | 
                  ok( $request->{_my_backend}, 'Instantiated backend stored for later use' ); | 
            
            
              | 61 | 
                  is( ref( $request->{_my_backend} ), 'Koha::Plugin::Test::ILLBackend', 'Returns the right object class' ); | 
            
            
              | 62 | 
               | 
            
            
              | 63 | 
                  Koha::Plugins::Methods->delete;  | 
            
            
              | 64 | 
                  $schema->storage->txn_rollback;  | 
            
            
              | 65 | 
              };  |