|
Lines 22-27
use Modern::Perl;
Link Here
|
| 22 |
use Test::NoWarnings; |
22 |
use Test::NoWarnings; |
| 23 |
use Test::More tests => 12; |
23 |
use Test::More tests => 12; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
|
|
25 |
use Test::Warn; |
| 25 |
|
26 |
|
| 26 |
use Koha::Suggestions; |
27 |
use Koha::Suggestions; |
| 27 |
use Koha::Notice::Messages; |
28 |
use Koha::Notice::Messages; |
|
Lines 133-144
is( Koha::Suggestions->search->count, $nb_of_suggestions + 1, 'Delete should hav
Link Here
|
| 133 |
$schema->storage->txn_rollback; |
134 |
$schema->storage->txn_rollback; |
| 134 |
|
135 |
|
| 135 |
subtest 'constraints' => sub { |
136 |
subtest 'constraints' => sub { |
| 136 |
plan tests => 11; |
137 |
plan tests => 15; |
| 137 |
$schema->storage->txn_begin; |
138 |
$schema->storage->txn_begin; |
| 138 |
|
139 |
|
| 139 |
my $print_error = $schema->storage->dbh->{PrintError}; |
|
|
| 140 |
$schema->storage->dbh->{PrintError} = 0; |
| 141 |
|
| 142 |
my $patron = $builder->build_object( { class => "Koha::Patrons" } ); |
140 |
my $patron = $builder->build_object( { class => "Koha::Patrons" } ); |
| 143 |
my $biblio = $builder->build_sample_biblio(); |
141 |
my $biblio = $builder->build_sample_biblio(); |
| 144 |
my $branch = $builder->build_object( { class => "Koha::Libraries" } ); |
142 |
my $branch = $builder->build_object( { class => "Koha::Libraries" } ); |
|
Lines 178-193
subtest 'constraints' => sub {
Link Here
|
| 178 |
"The suggestion is not deleted when the related branch is deleted" ); |
176 |
"The suggestion is not deleted when the related branch is deleted" ); |
| 179 |
|
177 |
|
| 180 |
# managerid |
178 |
# managerid |
| 181 |
{ # hide useless warnings |
179 |
warning_like( |
| 182 |
local *STDERR; |
180 |
sub { |
| 183 |
open STDERR, '>', '/dev/null'; |
181 |
throws_ok { |
| 184 |
throws_ok { |
182 |
$suggestion->managedby($nonexistent_borrowernumber)->store; |
| 185 |
$suggestion->managedby($nonexistent_borrowernumber)->store; |
183 |
} |
| 186 |
} |
184 |
'Koha::Exceptions::Object::FKConstraint', |
| 187 |
'Koha::Exceptions::Object::FKConstraint', |
185 |
'store raises an exception on invalid managerid'; |
| 188 |
'store raises an exception on invalid managerid'; |
186 |
}, |
| 189 |
close STDERR; |
187 |
qr{a foreign key constraint fails} |
| 190 |
} |
188 |
); |
| 191 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
189 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 192 |
$suggestion->managedby( $manager->borrowernumber )->store; |
190 |
$suggestion->managedby( $manager->borrowernumber )->store; |
| 193 |
$manager->delete; |
191 |
$manager->delete; |
|
Lines 196-211
subtest 'constraints' => sub {
Link Here
|
| 196 |
"The suggestion is not deleted when the related manager is deleted" ); |
194 |
"The suggestion is not deleted when the related manager is deleted" ); |
| 197 |
|
195 |
|
| 198 |
# acceptedby |
196 |
# acceptedby |
| 199 |
{ # hide useless warnings |
197 |
warning_like( |
| 200 |
local *STDERR; |
198 |
sub { |
| 201 |
open STDERR, '>', '/dev/null'; |
199 |
throws_ok { |
| 202 |
throws_ok { |
200 |
$suggestion->acceptedby($nonexistent_borrowernumber)->store; |
| 203 |
$suggestion->acceptedby($nonexistent_borrowernumber)->store; |
201 |
} |
| 204 |
} |
202 |
'Koha::Exceptions::Object::FKConstraint', |
| 205 |
'Koha::Exceptions::Object::FKConstraint', |
203 |
'store raises an exception on invalid acceptedby id'; |
| 206 |
'store raises an exception on invalid acceptedby id'; |
204 |
}, |
| 207 |
close STDERR; |
205 |
qr{a foreign key constraint fails} |
| 208 |
} |
206 |
); |
| 209 |
my $acceptor = $builder->build_object( { class => "Koha::Patrons" } ); |
207 |
my $acceptor = $builder->build_object( { class => "Koha::Patrons" } ); |
| 210 |
$suggestion->acceptedby( $acceptor->borrowernumber )->store; |
208 |
$suggestion->acceptedby( $acceptor->borrowernumber )->store; |
| 211 |
$acceptor->delete; |
209 |
$acceptor->delete; |
|
Lines 214-229
subtest 'constraints' => sub {
Link Here
|
| 214 |
"The suggestion is not deleted when the related acceptor is deleted" ); |
212 |
"The suggestion is not deleted when the related acceptor is deleted" ); |
| 215 |
|
213 |
|
| 216 |
# rejectedby |
214 |
# rejectedby |
| 217 |
{ # hide useless warnings |
215 |
warning_like( |
| 218 |
local *STDERR; |
216 |
sub { |
| 219 |
open STDERR, '>', '/dev/null'; |
217 |
throws_ok { |
| 220 |
throws_ok { |
218 |
$suggestion->rejectedby($nonexistent_borrowernumber)->store; |
| 221 |
$suggestion->rejectedby($nonexistent_borrowernumber)->store; |
219 |
} |
| 222 |
} |
220 |
'Koha::Exceptions::Object::FKConstraint', |
| 223 |
'Koha::Exceptions::Object::FKConstraint', |
221 |
'store raises an exception on invalid rejectedby id'; |
| 224 |
'store raises an exception on invalid rejectedby id'; |
222 |
}, |
| 225 |
close STDERR; |
223 |
qr{a foreign key constraint fails} |
| 226 |
} |
224 |
); |
| 227 |
my $rejecter = $builder->build_object( { class => "Koha::Patrons" } ); |
225 |
my $rejecter = $builder->build_object( { class => "Koha::Patrons" } ); |
| 228 |
$suggestion->rejectedby( $rejecter->borrowernumber )->store; |
226 |
$suggestion->rejectedby( $rejecter->borrowernumber )->store; |
| 229 |
$rejecter->delete; |
227 |
$rejecter->delete; |
|
Lines 232-246
subtest 'constraints' => sub {
Link Here
|
| 232 |
"The suggestion is not deleted when the related rejecter is deleted" ); |
230 |
"The suggestion is not deleted when the related rejecter is deleted" ); |
| 233 |
|
231 |
|
| 234 |
# budgetid |
232 |
# budgetid |
| 235 |
{ # hide useless warnings |
233 |
warning_like( |
| 236 |
local *STDERR; |
234 |
sub { |
| 237 |
open STDERR, '>', '/dev/null'; |
235 |
throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; } |
| 238 |
|
236 |
'Koha::Exceptions::Object::FKConstraint', |
| 239 |
throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; } |
237 |
'store raises an exception on invalid budgetid'; |
| 240 |
'Koha::Exceptions::Object::FKConstraint', |
238 |
}, |
| 241 |
'store raises an exception on invalid budgetid'; |
239 |
qr{a foreign key constraint fails} |
| 242 |
close STDERR; |
240 |
); |
| 243 |
} |
|
|
| 244 |
my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } ); |
241 |
my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } ); |
| 245 |
$suggestion->budgetid( $fund->id )->store; |
242 |
$suggestion->budgetid( $fund->id )->store; |
| 246 |
$fund->delete; |
243 |
$fund->delete; |
|
Lines 248-254
subtest 'constraints' => sub {
Link Here
|
| 248 |
is( $suggestion->budgetid, undef, |
245 |
is( $suggestion->budgetid, undef, |
| 249 |
"The suggestion is not deleted when the related budget is deleted" ); |
246 |
"The suggestion is not deleted when the related budget is deleted" ); |
| 250 |
|
247 |
|
| 251 |
$schema->storage->dbh->{PrintError} = $print_error; |
|
|
| 252 |
$schema->storage->txn_rollback; |
248 |
$schema->storage->txn_rollback; |
| 253 |
}; |
249 |
}; |
| 254 |
|
250 |
|