|
Lines 142-169
ok( !$hold->is_at_destination(), "Waiting hold where hold branchcode is not the
Link Here
|
| 142 |
$item->holdingbranch( $branches[1]->{branchcode} ); |
142 |
$item->holdingbranch( $branches[1]->{branchcode} ); |
| 143 |
ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" ); |
143 |
ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" ); |
| 144 |
|
144 |
|
| 145 |
# Test setting expiration date |
145 |
$schema->storage->txn_rollback(); |
| 146 |
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdate', 1 ); |
|
|
| 147 |
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdatePeriod', 2 ); |
| 148 |
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdateUnitOfTime', 'years' ); |
| 149 |
|
146 |
|
| 150 |
my $hold_2 = Koha::Hold->new( |
147 |
subtest "store() tests" => sub { |
| 151 |
{ |
|
|
| 152 |
biblionumber => $biblionumber, |
| 153 |
itemnumber => $item->id(), |
| 154 |
reservedate => '2020-11-30', |
| 155 |
waitingdate => '2020-11-30', |
| 156 |
borrowernumber => $borrower->{borrowernumber}, |
| 157 |
branchcode => $branches[1]->{branchcode}, |
| 158 |
suspend => 0, |
| 159 |
} |
| 160 |
); |
| 161 |
$hold_2->store(); |
| 162 |
|
148 |
|
| 163 |
my $expected_date = dt_from_string( $hold_2->reservedate )->add( years => 2); |
149 |
plan tests => 5; |
| 164 |
is($hold_2->expirationdate->ymd, $expected_date->ymd,'Expiration date is correctly set.'); |
|
|
| 165 |
|
150 |
|
| 166 |
$schema->storage->txn_rollback(); |
151 |
$schema->storage->txn_begin(); |
|
|
152 |
|
| 153 |
my $item = $builder->build_sample_item; |
| 154 |
my $biblio = $item->biblio; |
| 155 |
my $borrower = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 156 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 157 |
|
| 158 |
# Test setting expiration date |
| 159 |
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdate', 1 ); |
| 160 |
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdatePeriod', 2 ); |
| 161 |
t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdateUnitOfTime', |
| 162 |
'years' ); |
| 163 |
|
| 164 |
my $hold = Koha::Hold->new( |
| 165 |
{ |
| 166 |
biblionumber => $biblio->biblionumber, |
| 167 |
itemnumber => $item->id, |
| 168 |
reservedate => '2020-11-30', |
| 169 |
waitingdate => '2020-11-30', |
| 170 |
borrowernumber => $borrower->borrowernumber, |
| 171 |
branchcode => $library->branchcode, |
| 172 |
suspend => 0, |
| 173 |
} |
| 174 |
)->store; |
| 175 |
$hold->discard_changes; |
| 176 |
|
| 177 |
my $expected_date = |
| 178 |
dt_from_string( $hold->reservedate )->add( years => 2 ); |
| 179 |
is( $hold->expirationdate, |
| 180 |
$expected_date->ymd, 'Default expiration date for new hold is correctly set.' ); |
| 181 |
|
| 182 |
my $passed_date = |
| 183 |
dt_from_string( $hold->reservedate )->add( months => 2 ); |
| 184 |
$hold = Koha::Hold->new( |
| 185 |
{ |
| 186 |
biblionumber => $biblio->biblionumber, |
| 187 |
itemnumber => $item->id, |
| 188 |
reservedate => '2020-11-30', |
| 189 |
expirationdate => $passed_date->ymd, |
| 190 |
waitingdate => '2020-11-30', |
| 191 |
borrowernumber => $borrower->borrowernumber, |
| 192 |
branchcode => $library->branchcode, |
| 193 |
suspend => 0, |
| 194 |
} |
| 195 |
)->store; |
| 196 |
$hold->discard_changes; |
| 197 |
|
| 198 |
is( $hold->expirationdate, |
| 199 |
$passed_date->ymd, 'Passed expiration date for new hold is correctly set.' ); |
| 200 |
|
| 201 |
$passed_date->add( months => 1 ); |
| 202 |
$hold->expirationdate($passed_date->ymd)->store(); |
| 203 |
$hold->discard_changes; |
| 204 |
|
| 205 |
is( $hold->expirationdate, |
| 206 |
$passed_date->ymd, 'Passed expiration date when updating hold is correctly set.' ); |
| 207 |
|
| 208 |
$hold->reservedate($passed_date->ymd)->store(); |
| 209 |
$hold->discard_changes; |
| 210 |
|
| 211 |
is( $hold->expirationdate, |
| 212 |
$passed_date->add( years => 2 )->ymd, 'Default expiration date correctly set on reservedate update.' ); |
| 213 |
|
| 214 |
$hold->set( |
| 215 |
{ |
| 216 |
reservedate => $passed_date->ymd, |
| 217 |
expirationdate => $passed_date->add( weeks => 2 )->ymd |
| 218 |
} |
| 219 |
)->store(); |
| 220 |
$hold->discard_changes; |
| 221 |
|
| 222 |
is( $hold->expirationdate, |
| 223 |
$passed_date->ymd, 'Passed expiration date when updating hold correctly set (Passing both reservedate and expirationdate.' ); |
| 224 |
|
| 225 |
$schema->storage->txn_rollback(); |
| 226 |
}; |
| 167 |
|
227 |
|
| 168 |
subtest "delete() tests" => sub { |
228 |
subtest "delete() tests" => sub { |
| 169 |
|
229 |
|
| 170 |
- |
|
|