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

(-)a/t/db_dependent/Koha/Plugins/Patron.t (-1 / +41 lines)
Lines 16-23 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 5;
19
use Test::More tests => 6;
20
use Test::Exception;
20
use Test::Exception;
21
use Test::Warn;
21
22
22
use File::Basename;
23
use File::Basename;
23
24
Lines 91-94 subtest 'check_password hook tests' => sub { Link Here
91
    Koha::Plugins::Methods->delete;
92
    Koha::Plugins::Methods->delete;
92
};
93
};
93
94
95
subtest 'after_patron_action hook tests' => sub {
96
97
    plan tests => 4;
98
99
    $schema->storage->txn_begin;
100
101
    my $plugins = Koha::Plugins->new;
102
    $plugins->InstallPlugins;
103
104
    my $plugin = Koha::Plugin::Test->new->enable;
105
106
    ok( $plugin->can('after_patron_action'), 'Test plugin can after_patron_action' );
107
108
    my $library  = $builder->build( { source => 'Branch' } );
109
    my $category = $builder->build( { source => 'Category' } );
110
    my $patron   = Koha::Patron->new(
111
        {
112
            cardnumber => 'test_cn_after_patron_action', # Only this cardnumber is set to react to after_patron_action hook
113
            branchcode   => $library->{branchcode},
114
            categorycode => $category->{categorycode},
115
        }
116
    );
117
118
    warning_like { $patron->store->discard_changes; }
119
            qr/after_patron_action called with action: create, ref: Koha::Patron/,
120
            'Koha::Patron->store calls the hook with action=create';
121
122
    warning_like { $patron->store; }
123
            qr/after_patron_action called with action: modify, ref: Koha::Patron/,
124
            'If patron exists, Koha::Patron->store calls the hook with action=modify';
125
126
    warning_like { $patron->delete; }
127
            qr/after_patron_action called with action: delete/,
128
            'Koha::Patron->delete calls the hook with action=delete';
129
130
    $schema->storage->txn_rollback;
131
    Koha::Plugins::Methods->delete;
132
};
133
94
1;
134
1;
(-)a/t/lib/Koha/Plugin/Test.pm (-1 / +17 lines)
Lines 164-169 sub after_item_action { Link Here
164
    }
164
    }
165
}
165
}
166
166
167
sub after_patron_action {
168
    my ( $self, $params ) = @_;
169
    my $action    = $params->{action} // '';
170
    my $patron    = $params->{patron};
171
    my $patron_id = $params->{patron_id};
172
173
    # Continue only when testing after_patron_action hook
174
    return unless (defined $patron->cardnumber && $patron->cardnumber eq "test_cn_after_patron_action");
175
176
    if ( $action ne 'delete' ) {
177
        Koha::Exceptions::Exception->throw("after_patron_action called with action: $action, ref: " . ref($patron) );
178
    }
179
    else {
180
        Koha::Exceptions::Exception->throw("after_patron_action called with action: $action") if $patron_id;
181
    }
182
}
183
167
sub after_circ_action {
184
sub after_circ_action {
168
    my ( $self, $params ) = @_;
185
    my ( $self, $params ) = @_;
169
186
170
- 

Return to bug 27066