Lines 21-26
use Modern::Perl;
Link Here
|
21 |
|
21 |
|
22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 11; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
|
|
24 |
use Time::Fake; |
24 |
|
25 |
|
25 |
use C4::Circulation; |
26 |
use C4::Circulation; |
26 |
use C4::Context; |
27 |
use C4::Context; |
Lines 64-70
my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber );
Link Here
|
64 |
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' ); |
65 |
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' ); |
65 |
|
66 |
|
66 |
subtest 'store' => sub { |
67 |
subtest 'store' => sub { |
67 |
plan tests => 4; |
68 |
plan tests => 5; |
|
|
69 |
|
68 |
my $biblio = $builder->build_sample_biblio; |
70 |
my $biblio = $builder->build_sample_biblio; |
69 |
my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 ); |
71 |
my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 ); |
70 |
my $item = Koha::Item->new( |
72 |
my $item = Koha::Item->new( |
Lines 82-87
subtest 'store' => sub {
Link Here
|
82 |
is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given'); |
84 |
is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given'); |
83 |
is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' ); |
85 |
is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' ); |
84 |
$item->delete; |
86 |
$item->delete; |
|
|
87 |
|
88 |
subtest '*_on updates' => sub { |
89 |
plan tests => 9; |
90 |
|
91 |
# Once the '_on' value is set (triggered by the related field turning from false to true) |
92 |
# it should not be re-set for any changes outside of the related field being 'unset'. |
93 |
|
94 |
my @fields = qw( itemlost withdrawn damaged ); |
95 |
my $today = dt_from_string(); |
96 |
my $yesterday = $today->clone()->subtract( days => 1 ); |
97 |
|
98 |
for my $field ( @fields ) { |
99 |
my $item = $builder->build_sample_item( |
100 |
{ |
101 |
itemlost => 0, |
102 |
itemlost_on => undef, |
103 |
withdrawn => 0, |
104 |
withdrawn_on => undef, |
105 |
damaged => 0, |
106 |
damaged_on => undef |
107 |
} |
108 |
); |
109 |
my $field_on = $field . '_on'; |
110 |
|
111 |
# Set field for the first time |
112 |
Time::Fake->offset( $yesterday->epoch ); |
113 |
$item->$field(1)->store; |
114 |
$item->get_from_storage; |
115 |
is($item->$field_on, DateTime::Format::MySQL->format_datetime($yesterday), $field_on . " was set upon first truthy setting"); |
116 |
|
117 |
# Update the field to a new 'true' value |
118 |
Time::Fake->offset( $today->epoch ); |
119 |
$item->$field(2)->store; |
120 |
$item->get_from_storage; |
121 |
is($item->$field_on, DateTime::Format::MySQL->format_datetime($yesterday), $field_on . " was not updated upon second truthy setting"); |
122 |
|
123 |
# Update the field to a new 'false' value |
124 |
$item->$field(0)->store; |
125 |
$item->get_from_storage; |
126 |
is($item->$field_on, undef, $field_on . " was unset upon untruthy setting"); |
127 |
|
128 |
Time::Fake->reset; |
129 |
} |
130 |
}; |
131 |
|
85 |
}; |
132 |
}; |
86 |
|
133 |
|
87 |
subtest 'get_transfer' => sub { |
134 |
subtest 'get_transfer' => sub { |
Lines 111-117
subtest 'holds' => sub {
Link Here
|
111 |
my $item = $builder->build_sample_item({ |
158 |
my $item = $builder->build_sample_item({ |
112 |
biblionumber => $biblio->biblionumber, |
159 |
biblionumber => $biblio->biblionumber, |
113 |
}); |
160 |
}); |
114 |
$nb_of_items++; |
|
|
115 |
is($item->holds->count, 0, "Nothing returned if no holds"); |
161 |
is($item->holds->count, 0, "Nothing returned if no holds"); |
116 |
my $hold1 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'T' }}); |
162 |
my $hold1 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'T' }}); |
117 |
my $hold2 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }}); |
163 |
my $hold2 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }}); |
Lines 176-182
subtest 'can_be_transferred' => sub {
Link Here
|
176 |
homebranch => $library1->branchcode, |
222 |
homebranch => $library1->branchcode, |
177 |
holdingbranch => $library1->branchcode, |
223 |
holdingbranch => $library1->branchcode, |
178 |
}); |
224 |
}); |
179 |
$nb_of_items++; |
|
|
180 |
|
225 |
|
181 |
is(Koha::Item::Transfer::Limits->search({ |
226 |
is(Koha::Item::Transfer::Limits->search({ |
182 |
fromBranch => $library1->branchcode, |
227 |
fromBranch => $library1->branchcode, |
Lines 200-206
subtest 'can_be_transferred' => sub {
Link Here
|
200 |
'We get the same result also if we pass the from-library parameter.'); |
245 |
'We get the same result also if we pass the from-library parameter.'); |
201 |
}; |
246 |
}; |
202 |
|
247 |
|
|
|
248 |
# Reset nb_of_items prior to testing delete |
249 |
$nb_of_items = Koha::Items->search->count; |
250 |
|
251 |
# Test delete |
203 |
$retrieved_item_1->delete; |
252 |
$retrieved_item_1->delete; |
204 |
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); |
253 |
is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' ); |
205 |
|
254 |
|
206 |
$schema->storage->txn_rollback; |
255 |
$schema->storage->txn_rollback; |
207 |
- |
|
|