|
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 142-153
is( Koha::Suggestions->search->count, $nb_of_suggestions + 1, 'Delete should hav
Link Here
|
| 142 |
$schema->storage->txn_rollback; |
143 |
$schema->storage->txn_rollback; |
| 143 |
|
144 |
|
| 144 |
subtest 'constraints' => sub { |
145 |
subtest 'constraints' => sub { |
| 145 |
plan tests => 11; |
146 |
plan tests => 15; |
| 146 |
$schema->storage->txn_begin; |
147 |
$schema->storage->txn_begin; |
| 147 |
|
148 |
|
| 148 |
my $print_error = $schema->storage->dbh->{PrintError}; |
|
|
| 149 |
$schema->storage->dbh->{PrintError} = 0; |
| 150 |
|
| 151 |
my $patron = $builder->build_object( { class => "Koha::Patrons" } ); |
149 |
my $patron = $builder->build_object( { class => "Koha::Patrons" } ); |
| 152 |
my $biblio = $builder->build_sample_biblio(); |
150 |
my $biblio = $builder->build_sample_biblio(); |
| 153 |
my $branch = $builder->build_object( { class => "Koha::Libraries" } ); |
151 |
my $branch = $builder->build_object( { class => "Koha::Libraries" } ); |
|
Lines 194-209
subtest 'constraints' => sub {
Link Here
|
| 194 |
); |
192 |
); |
| 195 |
|
193 |
|
| 196 |
# managerid |
194 |
# managerid |
| 197 |
{ # hide useless warnings |
195 |
warning_like( |
| 198 |
local *STDERR; |
196 |
sub { |
| 199 |
open STDERR, '>', '/dev/null'; |
197 |
throws_ok { |
| 200 |
throws_ok { |
198 |
$suggestion->managedby($nonexistent_borrowernumber)->store; |
| 201 |
$suggestion->managedby($nonexistent_borrowernumber)->store; |
199 |
} |
| 202 |
} |
200 |
'Koha::Exceptions::Object::FKConstraint', |
| 203 |
'Koha::Exceptions::Object::FKConstraint', |
201 |
'store raises an exception on invalid managerid'; |
| 204 |
'store raises an exception on invalid managerid'; |
202 |
}, |
| 205 |
close STDERR; |
203 |
qr{a foreign key constraint fails} |
| 206 |
} |
204 |
); |
| 207 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
205 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 208 |
$suggestion->managedby( $manager->borrowernumber )->store; |
206 |
$suggestion->managedby( $manager->borrowernumber )->store; |
| 209 |
$manager->delete; |
207 |
$manager->delete; |
|
Lines 214-229
subtest 'constraints' => sub {
Link Here
|
| 214 |
); |
212 |
); |
| 215 |
|
213 |
|
| 216 |
# acceptedby |
214 |
# acceptedby |
| 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->acceptedby($nonexistent_borrowernumber)->store; |
| 221 |
$suggestion->acceptedby($nonexistent_borrowernumber)->store; |
219 |
} |
| 222 |
} |
220 |
'Koha::Exceptions::Object::FKConstraint', |
| 223 |
'Koha::Exceptions::Object::FKConstraint', |
221 |
'store raises an exception on invalid acceptedby id'; |
| 224 |
'store raises an exception on invalid acceptedby id'; |
222 |
}, |
| 225 |
close STDERR; |
223 |
qr{a foreign key constraint fails} |
| 226 |
} |
224 |
); |
| 227 |
my $acceptor = $builder->build_object( { class => "Koha::Patrons" } ); |
225 |
my $acceptor = $builder->build_object( { class => "Koha::Patrons" } ); |
| 228 |
$suggestion->acceptedby( $acceptor->borrowernumber )->store; |
226 |
$suggestion->acceptedby( $acceptor->borrowernumber )->store; |
| 229 |
$acceptor->delete; |
227 |
$acceptor->delete; |
|
Lines 234-249
subtest 'constraints' => sub {
Link Here
|
| 234 |
); |
232 |
); |
| 235 |
|
233 |
|
| 236 |
# rejectedby |
234 |
# rejectedby |
| 237 |
{ # hide useless warnings |
235 |
warning_like( |
| 238 |
local *STDERR; |
236 |
sub { |
| 239 |
open STDERR, '>', '/dev/null'; |
237 |
throws_ok { |
| 240 |
throws_ok { |
238 |
$suggestion->rejectedby($nonexistent_borrowernumber)->store; |
| 241 |
$suggestion->rejectedby($nonexistent_borrowernumber)->store; |
239 |
} |
| 242 |
} |
240 |
'Koha::Exceptions::Object::FKConstraint', |
| 243 |
'Koha::Exceptions::Object::FKConstraint', |
241 |
'store raises an exception on invalid rejectedby id'; |
| 244 |
'store raises an exception on invalid rejectedby id'; |
242 |
}, |
| 245 |
close STDERR; |
243 |
qr{a foreign key constraint fails} |
| 246 |
} |
244 |
); |
| 247 |
my $rejecter = $builder->build_object( { class => "Koha::Patrons" } ); |
245 |
my $rejecter = $builder->build_object( { class => "Koha::Patrons" } ); |
| 248 |
$suggestion->rejectedby( $rejecter->borrowernumber )->store; |
246 |
$suggestion->rejectedby( $rejecter->borrowernumber )->store; |
| 249 |
$rejecter->delete; |
247 |
$rejecter->delete; |
|
Lines 254-268
subtest 'constraints' => sub {
Link Here
|
| 254 |
); |
252 |
); |
| 255 |
|
253 |
|
| 256 |
# budgetid |
254 |
# budgetid |
| 257 |
{ # hide useless warnings |
255 |
warning_like( |
| 258 |
local *STDERR; |
256 |
sub { |
| 259 |
open STDERR, '>', '/dev/null'; |
257 |
throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; } |
| 260 |
|
258 |
'Koha::Exceptions::Object::FKConstraint', |
| 261 |
throws_ok { $suggestion->budgetid($nonexistent_borrowernumber)->store; } |
259 |
'store raises an exception on invalid budgetid'; |
| 262 |
'Koha::Exceptions::Object::FKConstraint', |
260 |
}, |
| 263 |
'store raises an exception on invalid budgetid'; |
261 |
qr{a foreign key constraint fails} |
| 264 |
close STDERR; |
262 |
); |
| 265 |
} |
|
|
| 266 |
my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } ); |
263 |
my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } ); |
| 267 |
$suggestion->budgetid( $fund->id )->store; |
264 |
$suggestion->budgetid( $fund->id )->store; |
| 268 |
$fund->delete; |
265 |
$fund->delete; |
|
Lines 272-278
subtest 'constraints' => sub {
Link Here
|
| 272 |
"The suggestion is not deleted when the related budget is deleted" |
269 |
"The suggestion is not deleted when the related budget is deleted" |
| 273 |
); |
270 |
); |
| 274 |
|
271 |
|
| 275 |
$schema->storage->dbh->{PrintError} = $print_error; |
|
|
| 276 |
$schema->storage->txn_rollback; |
272 |
$schema->storage->txn_rollback; |
| 277 |
}; |
273 |
}; |
| 278 |
|
274 |
|