|
Lines 16-23
Link Here
|
| 16 |
|
16 |
|
| 17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
| 18 |
|
18 |
|
| 19 |
use Test::More tests => 4; |
19 |
use Test::More tests => 5; |
| 20 |
use Test::Warn; |
20 |
use Test::Warn; |
|
|
21 |
use Test::NoWarnings; |
| 21 |
|
22 |
|
| 22 |
use File::Basename; |
23 |
use File::Basename; |
| 23 |
|
24 |
|
|
Lines 44-85
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
Link Here
|
| 44 |
|
45 |
|
| 45 |
subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { |
46 |
subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { |
| 46 |
|
47 |
|
| 47 |
plan tests => 6; |
48 |
plan tests => 12; |
| 48 |
|
49 |
|
| 49 |
$schema->storage->txn_begin; |
50 |
$schema->storage->txn_begin; |
| 50 |
|
51 |
|
|
|
52 |
my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 53 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
| 54 |
|
| 51 |
my $plugins = Koha::Plugins->new; |
55 |
my $plugins = Koha::Plugins->new; |
| 52 |
$plugins->InstallPlugins; |
56 |
$plugins->InstallPlugins; |
| 53 |
|
57 |
|
| 54 |
my $plugin = Koha::Plugin::Test->new->enable; |
58 |
my $plugin = Koha::Plugin::Test->new->enable; |
| 55 |
|
59 |
|
| 56 |
my $biblio_id; |
60 |
my $biblio_id_1; |
|
|
61 |
my $itemnumber_1; |
| 57 |
|
62 |
|
| 58 |
warning_like { ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); } |
63 |
warning_like { ( $biblio_id_1, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); } |
| 59 |
qr/after_biblio_action called with action: create, ref: Koha::Biblio/, |
64 |
qr/after_biblio_action called with action: create, ref: Koha::Biblio/, |
| 60 |
'AddBiblio calls the hook with action=create'; |
65 |
'AddBiblio calls the hook with action=create'; |
| 61 |
|
66 |
|
| 62 |
warning_like { C4::Biblio::ModBiblio( MARC::Record->new(), $biblio_id, '' ); } |
67 |
warning_like { C4::Biblio::ModBiblio( MARC::Record->new(), $biblio_id_1, '' ); } |
| 63 |
qr/after_biblio_action called with action: modify, ref: Koha::Biblio/, |
68 |
qr/after_biblio_action called with action: modify, ref: Koha::Biblio/, |
| 64 |
'ModBiblio calls the hook with action=modify'; |
69 |
'ModBiblio calls the hook with action=modify'; |
| 65 |
|
70 |
|
| 66 |
my $item; |
71 |
warning_like { |
| 67 |
warning_like { $item = $builder->build_sample_item({ biblionumber => $biblio_id }); } |
72 |
( undef, undef, $itemnumber_1 ) = C4::Items::AddItem( |
| 68 |
qr/after_item_action called with action: create, ref: Koha::Item/, |
73 |
{ homebranch => $library->branchcode, |
| 69 |
'AddItem calls the hook with action=create'; |
74 |
holdingbranch => $library->branchcode, |
| 70 |
|
75 |
itype => $item_type->itemtype |
| 71 |
warning_like { C4::Items::ModItem({ location => 'shelves' }, $biblio_id, $item->itemnumber); } |
76 |
}, |
|
|
77 |
$biblio_id_1 |
| 78 |
); |
| 79 |
} |
| 80 |
qr/after_item_action called with action: create, ref: Koha::Item/, |
| 81 |
'AddItem calls the hook with action=create'; |
| 82 |
|
| 83 |
warning_like { C4::Items::ModItem({ location => 'shelves' }, $biblio_id_1, $itemnumber_1); } |
| 72 |
qr/after_item_action called with action: modify, ref: Koha::Item/, |
84 |
qr/after_item_action called with action: modify, ref: Koha::Item/, |
| 73 |
'ModItem calls the hook with action=modify'; |
85 |
'ModItem calls the hook with action=modify'; |
| 74 |
|
86 |
|
| 75 |
warning_like { C4::Items::DelItem({ itemnumber => $item->itemnumber }); } |
87 |
warning_like { C4::Items::DelItem({ itemnumber => $itemnumber_1 }); } |
| 76 |
qr/after_item_action called with action: delete/, |
88 |
qr/after_item_action called with action: delete/, |
| 77 |
'DelItem calls the hook with action=delete, item_id passed'; |
89 |
'DelItem calls the hook with action=delete, item_id passed'; |
| 78 |
|
90 |
|
| 79 |
warning_like { C4::Biblio::DelBiblio( $biblio_id ); } |
91 |
warning_like { C4::Biblio::DelBiblio( $biblio_id_1 ); } |
| 80 |
qr/after_biblio_action called with action: delete/, |
92 |
qr/after_biblio_action called with action: delete/, |
| 81 |
'DelBiblio calls the hook with action=delete biblio_id passed'; |
93 |
'DelBiblio calls the hook with action=delete biblio_id passed'; |
| 82 |
|
94 |
|
|
|
95 |
my $biblio_id_2; |
| 96 |
my $itemnumber_2; |
| 97 |
|
| 98 |
warning_like { ( $biblio_id_2, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '', { plugins => [ $plugin ] } ); } |
| 99 |
qr/after_biblio_action called with action: create, ref: Koha::Biblio/, |
| 100 |
'AddBiblio calls the hook with action=create'; |
| 101 |
|
| 102 |
warning_like { C4::Biblio::ModBiblio( MARC::Record->new(), $biblio_id_2, '', undef, [ $plugin ] ); } |
| 103 |
qr/after_biblio_action called with action: modify, ref: Koha::Biblio/, |
| 104 |
'ModBiblio calls the hook with action=modify'; |
| 105 |
|
| 106 |
warning_like { |
| 107 |
( undef, undef, $itemnumber_2 ) = C4::Items::AddItem( |
| 108 |
{ homebranch => $library->branchcode, |
| 109 |
holdingbranch => $library->branchcode, |
| 110 |
itype => $item_type->itemtype |
| 111 |
}, |
| 112 |
$biblio_id_2, |
| 113 |
C4::Context->dbh, |
| 114 |
C4::Biblio::GetFrameworkCode($biblio_id_2), |
| 115 |
undef, |
| 116 |
[ $plugin ] |
| 117 |
); |
| 118 |
} |
| 119 |
qr/after_item_action called with action: create, ref: Koha::Item/, |
| 120 |
'AddItem calls the hook with action=create'; |
| 121 |
|
| 122 |
warning_like { |
| 123 |
C4::Items::ModItem( { location => 'shelves' }, |
| 124 |
$biblio_id_2, $itemnumber_2, { plugins => [$plugin] } ); |
| 125 |
} |
| 126 |
qr/after_item_action called with action: modify, ref: Koha::Item/, |
| 127 |
'ModItem calls the hook with action=modify'; |
| 128 |
|
| 129 |
warning_like { C4::Items::DelItem( { itemnumber => $itemnumber_2, plugins => [ $plugin ] } ); } |
| 130 |
qr/after_item_action called with action: delete/, |
| 131 |
'DelItem calls the hook with action=delete, item_id passed'; |
| 132 |
|
| 133 |
warning_like { C4::Biblio::DelBiblio( $biblio_id_2, [ $plugin ] ); } |
| 134 |
qr/after_biblio_action called with action: delete/, |
| 135 |
'DelBiblio calls the hook with action=delete biblio_id passed'; |
| 136 |
|
| 137 |
# Call C4::Biblio::{Add|Mod|Del}Biblio with an empty list of plugins, pairing |
| 138 |
# with Test::NoWarnings to test no warnings are raised by plugins |
| 139 |
my ( $biblio_id_3, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '', { plugins => [] } ); |
| 140 |
C4::Biblio::ModBiblio( MARC::Record->new(), $biblio_id_3, '', undef, [] ); |
| 141 |
my ( undef, undef, $itemnumber_3 ) = C4::Items::AddItem( |
| 142 |
{ homebranch => $library->branchcode, |
| 143 |
holdingbranch => $library->branchcode, |
| 144 |
itype => $item_type->itemtype |
| 145 |
}, |
| 146 |
$biblio_id_3, |
| 147 |
C4::Context->dbh, |
| 148 |
C4::Biblio::GetFrameworkCode($biblio_id_3), |
| 149 |
undef, |
| 150 |
[] |
| 151 |
); |
| 152 |
C4::Items::DelItem( { itemnumber => $itemnumber_3, plugins => [] } ); |
| 153 |
C4::Biblio::DelBiblio( $biblio_id_3, [] ); |
| 154 |
|
| 83 |
$schema->storage->txn_rollback; |
155 |
$schema->storage->txn_rollback; |
| 84 |
Koha::Plugins::Methods->delete; |
156 |
Koha::Plugins::Methods->delete; |
| 85 |
}; |
157 |
}; |
| 86 |
- |
|
|