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

(-)a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t (-13 / +21 lines)
Lines 40-53 my $builder = t::lib::TestBuilder->new; Link Here
40
40
41
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
41
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
42
42
43
subtest '() hook tests' => sub {
43
subtest 'patron_barcode_transform() and item_barcode_transform() hook tests' => sub {
44
44
45
    plan tests => 4;
45
    plan tests => 6;
46
46
47
    $schema->storage->txn_begin;
47
    $schema->storage->txn_begin;
48
48
49
    # Avoid testing useless warnings
50
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
51
    $test_plugin->mock( 'after_item_action',   undef );
52
    $test_plugin->mock( 'after_biblio_action', undef );
53
49
    my $plugins = Koha::Plugins->new;
54
    my $plugins = Koha::Plugins->new;
50
    $plugins->InstallPlugins;
55
56
    warnings_are
57
     { $plugins->InstallPlugins; }
58
     [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall",
59
       "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ];
60
51
    C4::Context->dbh->do("DELETE FROM plugin_methods WHERE plugin_class LIKE '%TestBarcodes%'");
61
    C4::Context->dbh->do("DELETE FROM plugin_methods WHERE plugin_class LIKE '%TestBarcodes%'");
52
62
53
    my $plugin = Koha::Plugin::Test->new->enable;
63
    my $plugin = Koha::Plugin::Test->new->enable;
Lines 81-98 subtest '() hook tests' => sub { Link Here
81
        }
91
        }
82
    );
92
    );
83
93
84
    # Avoid testing useless warnings
94
    my $item;
85
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
95
    warning_like { $item = $builder->build_sample_item(); }
86
    $test_plugin->mock( 'after_item_action',   undef );
96
        qr/Plugin error \(Test Plugin\): item_barcode_transform called with parameter: /,
87
    $test_plugin->mock( 'after_biblio_action', undef );
97
        'Koha::Item->store calls the item_barcode_transform hook';
88
98
89
    my $biblio = $builder->build_sample_biblio();
99
    $item->barcode('THISISATEST');
90
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
91
    $item_1->barcode('THISISATEST');
92
100
93
    warning_like { $item_1->store(); }
101
    warning_is { $item->store(); }
94
        qr/item_barcode_transform called with parameter: THISISATEST/,
102
        'Plugin error (Test Plugin): item_barcode_transform called with parameter: THISISATEST',
95
        'AddReserve calls the after_hold_create hook';
103
        'Koha::Item->store calls the item_barcode_transform hook';
96
104
97
    $schema->storage->txn_rollback;
105
    $schema->storage->txn_rollback;
98
    Koha::Plugins::Methods->delete;
106
    Koha::Plugins::Methods->delete;
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-5 / +17 lines)
Lines 88-94 subtest 'call() tests' => sub { Link Here
88
};
88
};
89
89
90
subtest 'more call() tests' => sub {
90
subtest 'more call() tests' => sub {
91
    plan tests => 3;
91
92
    plan tests => 6;
92
93
93
    $schema->storage->txn_begin;
94
    $schema->storage->txn_begin;
94
    # Temporarily remove any installed plugins data
95
    # Temporarily remove any installed plugins data
Lines 96-102 subtest 'more call() tests' => sub { Link Here
96
97
97
    t::lib::Mocks::mock_config('enable_plugins', 1);
98
    t::lib::Mocks::mock_config('enable_plugins', 1);
98
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
99
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
99
    my @plugins = $plugins->InstallPlugins;
100
    my @plugins;
101
102
    warnings_are
103
     { @plugins = $plugins->InstallPlugins; }
104
     [ "Calling 'install' died for plugin Koha::Plugin::BrokenInstall",
105
       "Calling 'upgrade' died for plugin Koha::Plugin::BrokenUpgrade" ];
106
100
    foreach my $plugin (@plugins) {
107
    foreach my $plugin (@plugins) {
101
        $plugin->enable();
108
        $plugin->enable();
102
    }
109
    }
Lines 104-114 subtest 'more call() tests' => sub { Link Here
104
    # Barcode is multiplied by 2 by Koha::Plugin::Test, and again by 4 by Koha::Plugin::TestItemBarcodeTransform
111
    # Barcode is multiplied by 2 by Koha::Plugin::Test, and again by 4 by Koha::Plugin::TestItemBarcodeTransform
105
    # showing that call has passed the same ref to multiple plugins to operate on
112
    # showing that call has passed the same ref to multiple plugins to operate on
106
    my $bc = 1;
113
    my $bc = 1;
107
    Koha::Plugins->call('item_barcode_transform', \$bc);
114
    warnings_are
115
        { Koha::Plugins->call('item_barcode_transform', \$bc); }
116
        [ 'Plugin error (Test Plugin): item_barcode_transform called with parameter: 1',
117
          'Plugin error (Test Plugin for item_barcode_transform): item_barcode_transform called with parameter: 2' ];
108
    is( $bc, 8, "Got expected response" );
118
    is( $bc, 8, "Got expected response" );
109
119
110
    my $cn = 'abcd';
120
    my $cn = 'abcd';
111
    Koha::Plugins->call('item_barcode_transform', \$cn);
121
    warnings_are
122
        { Koha::Plugins->call('item_barcode_transform', \$bc); }
123
        [ 'Plugin error (Test Plugin): item_barcode_transform called with parameter: 8',
124
          'Plugin error (Test Plugin for item_barcode_transform): item_barcode_transform called with parameter: 16' ];
112
    is( $cn, 'abcd', "Got expected response" );
125
    is( $cn, 'abcd', "Got expected response" );
113
126
114
    t::lib::Mocks::mock_config('enable_plugins', 0);
127
    t::lib::Mocks::mock_config('enable_plugins', 0);
115
- 

Return to bug 28211