Lines 44-50
my $location = 'My Location';
Link Here
|
44 |
|
44 |
|
45 |
subtest 'General Add, Get and Del tests' => sub { |
45 |
subtest 'General Add, Get and Del tests' => sub { |
46 |
|
46 |
|
47 |
plan tests => 16; |
47 |
plan tests => 25; |
|
|
48 |
|
49 |
my $item_barcode = 123; |
48 |
|
50 |
|
49 |
$schema->storage->txn_begin; |
51 |
$schema->storage->txn_begin; |
50 |
|
52 |
|
Lines 61-88
subtest 'General Add, Get and Del tests' => sub {
Link Here
|
61 |
my ($bibnum, $bibitemnum) = get_biblio(); |
63 |
my ($bibnum, $bibitemnum) = get_biblio(); |
62 |
|
64 |
|
63 |
# Add an item. |
65 |
# Add an item. |
64 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum); |
66 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ |
|
|
67 |
homebranch => $library->{branchcode}, |
68 |
holdingbranch => $library->{branchcode}, |
69 |
location => $location, |
70 |
itype => $itemtype->{itemtype}, |
71 |
barcode => $item_barcode |
72 |
}, $bibnum |
73 |
); |
65 |
cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); |
74 |
cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); |
66 |
cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); |
75 |
cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); |
67 |
|
76 |
|
68 |
# Get item. |
77 |
# Get item. |
69 |
my $getitem = GetItem($itemnumber); |
78 |
my $getitem = GetItem($itemnumber); |
70 |
cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); |
79 |
cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); |
|
|
80 |
cmp_ok($getitem->{'barcode'}, '==', $item_barcode, "Retrieved item has correct barcode."); |
71 |
cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); |
81 |
cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); |
72 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
82 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
73 |
is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to the location value" ); |
83 |
is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to the location value" ); |
74 |
|
84 |
|
|
|
85 |
$getitem = GetItem(undef, $item_barcode); |
86 |
cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Item retrieved by barcode has correct itemnumber."); |
87 |
|
75 |
# Modify item; setting barcode. |
88 |
# Modify item; setting barcode. |
76 |
ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); |
89 |
$item_barcode = '987654321'; |
|
|
90 |
ModItem({ barcode => $item_barcode }, $bibnum, $itemnumber); |
77 |
my $moditem = GetItem($itemnumber); |
91 |
my $moditem = GetItem($itemnumber); |
78 |
cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); |
92 |
cmp_ok($moditem->{'barcode'}, '==', $item_barcode, 'Modified item barcode successfully to: ' . $moditem->{'barcode'} . '.'); |
|
|
93 |
|
94 |
# Update some more properties to get larger coverage |
95 |
my $item_properties = { |
96 |
'dateaccessioned' => '2012-12-12', |
97 |
'datelastborrowed' => '2013-12-12', |
98 |
'datelastseen' => '2013-12-12', |
99 |
'notforloan' => '0', |
100 |
'damaged' => '0', |
101 |
'itemlost' => '0', |
102 |
'itemcallnumber' => '1234', |
103 |
'restricted' => '0', |
104 |
}; |
105 |
|
106 |
# Clone item propreties since ModItem modifies this argument |
107 |
# causing later tests to fail |
108 |
ModItem({%{$item_properties}}, $bibnum, $itemnumber); |
109 |
|
110 |
# Search unblessed tests |
111 |
my $search_conditions = { |
112 |
'itemnumber' => $itemnumber, |
113 |
}; |
114 |
my ($item_object) = Koha::Items->search($search_conditions); |
115 |
my $item_object_data = $item_object->unblessed; |
116 |
cmp_ok($item_object_data->{'itemnumber'}, '==', $itemnumber, "Item object retrieved by Koha::Items->search using \"itemnumber\" condition has correct itemnumber."); |
117 |
|
118 |
# Intersect with updated properties |
119 |
my $updated_item_properties = { map { ($_ => $item_object_data->{$_}) } keys %{$item_properties} }; |
120 |
|
121 |
is_deeply($updated_item_properties, $item_properties, "Updated item properties have correct values."); |
122 |
|
123 |
my ($item_data) = Koha::Items->search_unblessed($search_conditions); |
124 |
cmp_ok( |
125 |
$item_data->{'itemnumber'}, |
126 |
'==', |
127 |
$itemnumber, |
128 |
"Item data retrieved by Koha::Items->search_unblessed using \"itemnumber\" condition has correct itemnumber." |
129 |
); |
130 |
|
131 |
($item_data) = Koha::Items->search_unblessed({ 'barcode' => $item_barcode }); |
132 |
cmp_ok( |
133 |
$item_data->{'itemnumber'}, |
134 |
'==', |
135 |
$itemnumber, |
136 |
"Item data retrieved by Koha::Items->search_unblessed using \"barcode\" condition has correct itemnumber." |
137 |
); |
138 |
|
139 |
is_deeply($item_object_data, $item_data, "Item data retrieved by unblessing item object is identical to item data from Koha::Items->search_unblessed."); |
79 |
|
140 |
|
80 |
# Delete item. |
141 |
# Delete item. |
81 |
DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber }); |
142 |
DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber }); |
82 |
my $getdeleted = GetItem($itemnumber); |
143 |
my $getdeleted = GetItem($itemnumber); |
83 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
144 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
84 |
|
145 |
|
85 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum); |
146 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ |
|
|
147 |
homebranch => $library->{branchcode}, |
148 |
holdingbranch => $library->{branchcode}, |
149 |
location => $location, |
150 |
permanent_location => 'my permanent location', |
151 |
itype => $itemtype->{itemtype}, |
152 |
barcode => $item_barcode |
153 |
}, |
154 |
$bibnum |
155 |
); |
86 |
$getitem = GetItem($itemnumber); |
156 |
$getitem = GetItem($itemnumber); |
87 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
157 |
is( $getitem->{location}, $location, "The location should not have been modified" ); |
88 |
is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" ); |
158 |
is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" ); |
Lines 100-105
subtest 'General Add, Get and Del tests' => sub {
Link Here
|
100 |
t::lib::Mocks::mock_preference('item-level_itypes', '1'); |
170 |
t::lib::Mocks::mock_preference('item-level_itypes', '1'); |
101 |
$getitem = GetItem($itemnumber); |
171 |
$getitem = GetItem($itemnumber); |
102 |
is( $getitem->{itype}, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" ); |
172 |
is( $getitem->{itype}, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" ); |
|
|
173 |
# Good to test this since different code for retrieving items is run in GetItems() depending on item-level_itypes preference |
174 |
is( $getitem->{itemnumber}, $itemnumber, "Item successfully retrieved by itemnumber when using item-level_itypes" ); |
175 |
$getitem = GetItem(undef, $item_barcode); |
176 |
is( $getitem->{itemnumber}, $itemnumber, "Item successfully retrieved by barcode when using item-level_itypes" ); |
177 |
|
103 |
t::lib::Mocks::mock_preference('item-level_itypes', '0'); |
178 |
t::lib::Mocks::mock_preference('item-level_itypes', '0'); |
104 |
$getitem = GetItem($itemnumber); |
179 |
$getitem = GetItem($itemnumber); |
105 |
is( $getitem->{itype}, undef, "Itemtype set correctly when not using item-level_itypes" ); |
180 |
is( $getitem->{itype}, undef, "Itemtype set correctly when not using item-level_itypes" ); |
106 |
- |
|
|