View | Details | Raw Unified | Return to bug 39092
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Plugins/ILL/Backends.t (+68 lines)
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::BackendClass');
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('BackendClass');
51
52
    is(
53
        ref($plugin), 'Koha::Plugin::BackendClass',
54
        'Returns our Test Plugin which implements the Test Plugin backend'
55
    );
56
    my $backend = $plugin->new_ill_backend();
57
    is( ref($backend), 'Koha::Plugin::ILL::TestClass', 'Returns the right object class' );
58
59
    my $request = Koha::ILL::Request->new->load_backend('BackendClass');
60
    ok( $request->{_plugin}, 'Instantiated plugin stored for later use' );
61
    is( ref( $request->{_plugin} ), 'Koha::Plugin::BackendClass', 'Class is correct' );
62
63
    ok( $request->{_my_backend}, 'Instantiated backend stored for later use' );
64
    is( ref( $request->{_my_backend} ), 'Koha::Plugin::ILL::TestClass', 'Returns the right object class' );
65
66
    Koha::Plugins::Methods->delete;
67
    $schema->storage->txn_rollback;
68
};
(-)a/t/lib/plugins/Koha/Plugin/BackendClass.pm (+38 lines)
Line 0 Link Here
1
package Koha::Plugin::BackendClass;
2
3
use Modern::Perl;
4
5
use base qw(Koha::Plugins::Base);
6
7
our $VERSION  = "v1.01";
8
our $metadata = {
9
    name            => 'BackendClass',
10
    author          => 'Koha Community',
11
    description     => 'Plugin testing backends as their own class',
12
    date_authored   => '2013-01-14',
13
    date_updated    => '2013-01-14',
14
    minimum_version => '3.11',
15
    maximum_version => undef,
16
    version         => $VERSION,
17
    namespace       => 'backend_class',
18
};
19
20
sub new {
21
    my ( $class, $args ) = @_;
22
    $args->{'metadata'} = $metadata;
23
    my $self = $class->SUPER::new($args);
24
    return $self;
25
}
26
27
sub ill_backend {
28
    my ($self) = @_;
29
    return 'BackendClass';
30
}
31
32
sub new_ill_backend {
33
    my ( $self, $args ) = @_;
34
    require Koha::Plugin::ILL::TestClass;
35
    return Koha::Plugin::ILL::TestClass->new($args);
36
}
37
38
1;
(-)a/t/lib/plugins/Koha/Plugin/ILL/TestClass.pm (-1 / +42 lines)
Line 0 Link Here
0
- 
1
package Koha::Plugin::ILL::TestClass;
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
19
=head1 NAME
20
21
Koha::Plugin::ILL::TestClass - Dummy ILL backend class
22
23
=head1 API
24
25
=head2 Class methods
26
27
=head3 new
28
29
    my $backend = Koha::Plugin::ILL::TestClass->new;
30
31
Constructor.
32
33
=cut
34
35
sub new {
36
    my ( $class, $args ) = @_;
37
    my $self = \$args;
38
    bless( $self, $class );
39
    return $self;
40
}
41
42
1;

Return to bug 39092