|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 6; |
|
|
23 |
use Test::Exception; |
| 23 |
|
24 |
|
| 24 |
use Koha::Suggestion; |
25 |
use Koha::Suggestion; |
| 25 |
use Koha::Suggestions; |
26 |
use Koha::Suggestions; |
|
Lines 78-80
is( Koha::Suggestions->search->count, $nb_of_suggestions + 1, 'Delete should hav
Link Here
|
| 78 |
|
79 |
|
| 79 |
$schema->storage->txn_rollback; |
80 |
$schema->storage->txn_rollback; |
| 80 |
|
81 |
|
| 81 |
- |
82 |
subtest 'constraints' => sub { |
|
|
83 |
plan tests => 11; |
| 84 |
$schema->storage->txn_begin; |
| 85 |
|
| 86 |
my $patron = $builder->build_object( { class => "Koha::Patrons" } ); |
| 87 |
my $biblio = $builder->build_sample_biblio(); |
| 88 |
my $branch = $builder->build_object( { class => "Koha::Libraries" } ); |
| 89 |
|
| 90 |
my $suggestion = $builder->build_object( |
| 91 |
{ |
| 92 |
class => "Koha::Suggestions", |
| 93 |
value => { |
| 94 |
suggestedby => $patron->borrowernumber, |
| 95 |
biblionumber => $biblio->biblionumber, |
| 96 |
branchcode => $branch->branchcode, |
| 97 |
managedby => undef, |
| 98 |
acceptedby => undef, |
| 99 |
rejectedby => undef, |
| 100 |
budgetid => undef, |
| 101 |
} |
| 102 |
} |
| 103 |
); |
| 104 |
|
| 105 |
# suggestedby |
| 106 |
$patron->delete; |
| 107 |
$suggestion = $suggestion->get_from_storage; |
| 108 |
is( $suggestion->suggestedby, undef, |
| 109 |
"The suggestion is not deleted when the related patron is deleted" ); |
| 110 |
|
| 111 |
# biblionumber |
| 112 |
$biblio->delete; |
| 113 |
$suggestion = $suggestion->get_from_storage; |
| 114 |
is( $suggestion->biblionumber, undef, |
| 115 |
"The suggestion is not deleted when the related biblio is deleted" ); |
| 116 |
|
| 117 |
# branchcode |
| 118 |
$branch->delete; |
| 119 |
$suggestion = $suggestion->get_from_storage; |
| 120 |
is( $suggestion->branchcode, undef, |
| 121 |
"The suggestion is not deleted when the related branch is deleted" ); |
| 122 |
|
| 123 |
# managerid |
| 124 |
throws_ok { $suggestion->managedby(1029384756)->store; } |
| 125 |
'Koha::Exceptions::Object::FKConstraint', |
| 126 |
'store raises an exception on invalid managerid'; |
| 127 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 128 |
$suggestion->managedby( $manager->borrowernumber )->store; |
| 129 |
$manager->delete; |
| 130 |
$suggestion = $suggestion->get_from_storage; |
| 131 |
is( $suggestion->managedby, undef, |
| 132 |
"The suggestion is not deleted when the related manager is deleted" ); |
| 133 |
|
| 134 |
# acceptedby |
| 135 |
throws_ok { $suggestion->acceptedby(1029384756)->store; } |
| 136 |
'Koha::Exceptions::Object::FKConstraint', |
| 137 |
'store raises an exception on invalid acceptedby id'; |
| 138 |
my $acceptor = $builder->build_object( { class => "Koha::Patrons" } ); |
| 139 |
$suggestion->acceptedby( $acceptor->borrowernumber )->store; |
| 140 |
$acceptor->delete; |
| 141 |
$suggestion = $suggestion->get_from_storage; |
| 142 |
is( $suggestion->acceptedby, undef, |
| 143 |
"The suggestion is not deleted when the related acceptor is deleted" ); |
| 144 |
|
| 145 |
# rejectedby |
| 146 |
throws_ok { $suggestion->rejectedby(1029384756)->store; } |
| 147 |
'Koha::Exceptions::Object::FKConstraint', |
| 148 |
'store raises an exception on invalid rejectedby id'; |
| 149 |
my $rejecter = $builder->build_object( { class => "Koha::Patrons" } ); |
| 150 |
$suggestion->rejectedby( $rejecter->borrowernumber )->store; |
| 151 |
$rejecter->delete; |
| 152 |
$suggestion = $suggestion->get_from_storage; |
| 153 |
is( $suggestion->rejectedby, undef, |
| 154 |
"The suggestion is not deleted when the related rejecter is deleted" ); |
| 155 |
|
| 156 |
# budgetid |
| 157 |
throws_ok { $suggestion->budgetid(1029384756)->store; } |
| 158 |
'Koha::Exceptions::Object::FKConstraint', |
| 159 |
'store raises an exception on invalid budgetid'; |
| 160 |
my $fund = $builder->build_object( { class => "Koha::Acquisition::Funds" } ); |
| 161 |
$suggestion->budgetid( $fund->id )->store; |
| 162 |
$fund->delete; |
| 163 |
$suggestion = $suggestion->get_from_storage; |
| 164 |
is( $suggestion->budgetid, undef, |
| 165 |
"The suggestion is not deleted when the related budget is deleted" ); |
| 166 |
|
| 167 |
$schema->storage->txn_rollback; |
| 168 |
}; |