|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
use utf8; |
21 |
use utf8; |
| 22 |
|
22 |
|
| 23 |
use Test::More tests => 17; |
23 |
use Test::More tests => 25; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
| 26 |
|
26 |
|
|
Lines 41-46
use t::lib::Mocks;
Link Here
|
| 41 |
my $schema = Koha::Database->new->schema; |
41 |
my $schema = Koha::Database->new->schema; |
| 42 |
my $builder = t::lib::TestBuilder->new; |
42 |
my $builder = t::lib::TestBuilder->new; |
| 43 |
|
43 |
|
|
|
44 |
subtest 'return_claims relationship' => sub { |
| 45 |
plan tests => 3; |
| 46 |
|
| 47 |
$schema->storage->txn_begin; |
| 48 |
|
| 49 |
my $biblio = $builder->build_sample_biblio(); |
| 50 |
my $item = $builder->build_sample_item({ |
| 51 |
biblionumber => $biblio->biblionumber, |
| 52 |
}); |
| 53 |
my $return_claims = $item->return_claims; |
| 54 |
is( ref($return_claims), 'Koha::Checkouts::ReturnClaims', 'return_claims returns a Koha::Checkouts::ReturnClaims object set' ); |
| 55 |
is($item->return_claims->count, 0, "Empty Koha::Checkouts::ReturnClaims set returned if no return_claims"); |
| 56 |
my $claim1 = $builder->build({ source => 'ReturnClaim', value => { itemnumber => $item->itemnumber }}); |
| 57 |
my $claim2 = $builder->build({ source => 'ReturnClaim', value => { itemnumber => $item->itemnumber }}); |
| 58 |
|
| 59 |
is($item->return_claims()->count,2,"Two ReturnClaims found for item"); |
| 60 |
|
| 61 |
$schema->storage->txn_rollback; |
| 62 |
}; |
| 63 |
|
| 64 |
subtest 'return_claim accessor' => sub { |
| 65 |
plan tests => 5; |
| 66 |
|
| 67 |
$schema->storage->txn_begin; |
| 68 |
|
| 69 |
my $biblio = $builder->build_sample_biblio(); |
| 70 |
my $item = $builder->build_sample_item({ |
| 71 |
biblionumber => $biblio->biblionumber, |
| 72 |
}); |
| 73 |
my $return_claim = $item->return_claim; |
| 74 |
is( $return_claim, undef, 'return_claim returned undefined if there are no claims for this item' ); |
| 75 |
|
| 76 |
my $claim1 = $builder->build_object( |
| 77 |
{ |
| 78 |
class => 'Koha::Checkouts::ReturnClaims', |
| 79 |
value => { itemnumber => $item->itemnumber, resolution => undef, created_on => dt_from_string()->subtract( minutes => 10 ) } |
| 80 |
} |
| 81 |
); |
| 82 |
my $claim2 = $builder->build_object( |
| 83 |
{ |
| 84 |
class => 'Koha::Checkouts::ReturnClaims', |
| 85 |
value => { itemnumber => $item->itemnumber, resolution => undef, created_on => dt_from_string()->subtract( minutes => 5 ) } |
| 86 |
} |
| 87 |
); |
| 88 |
|
| 89 |
$return_claim = $item->return_claim; |
| 90 |
is( ref($return_claim), 'Koha::Checkouts::ReturnClaim', 'return_claim returned a Koha::Checkouts::ReturnClaim object' ); |
| 91 |
is( $return_claim->id, $claim2->id, 'return_claim returns the most recent unresolved claim'); |
| 92 |
|
| 93 |
$claim2->resolution('test')->store(); |
| 94 |
$return_claim = $item->return_claim; |
| 95 |
is( $return_claim->id, $claim1->id, 'return_claim returns the only unresolved claim'); |
| 96 |
|
| 97 |
$claim1->resolution('test')->store(); |
| 98 |
$return_claim = $item->return_claim; |
| 99 |
is( $return_claim, undef, 'return_claim returned undefined if there are no active claims for this item' ); |
| 100 |
|
| 101 |
$schema->storage->txn_rollback; |
| 102 |
}; |
| 103 |
|
| 44 |
subtest 'tracked_links relationship' => sub { |
104 |
subtest 'tracked_links relationship' => sub { |
| 45 |
plan tests => 3; |
105 |
plan tests => 3; |
| 46 |
|
106 |
|
|
Lines 57-62
subtest 'tracked_links relationship' => sub {
Link Here
|
| 57 |
is($item->tracked_links()->count,2,"Two tracked links found"); |
117 |
is($item->tracked_links()->count,2,"Two tracked links found"); |
| 58 |
}; |
118 |
}; |
| 59 |
|
119 |
|
|
|
120 |
subtest 'is_bundle tests' => sub { |
| 121 |
plan tests => 2; |
| 122 |
|
| 123 |
$schema->storage->txn_begin; |
| 124 |
|
| 125 |
my $item = $builder->build_sample_item(); |
| 126 |
|
| 127 |
my $is_bundle = $item->is_bundle; |
| 128 |
is($is_bundle, 0, 'is_bundle returns 0 when there are no items attached'); |
| 129 |
|
| 130 |
my $item2 = $builder->build_sample_item(); |
| 131 |
$schema->resultset('ItemBundle') |
| 132 |
->create( { host => $item->itemnumber, item => $item2->itemnumber } ); |
| 133 |
|
| 134 |
$is_bundle = $item->is_bundle; |
| 135 |
is($is_bundle, 1, 'is_bundle returns 1 when there is at least one item attached'); |
| 136 |
|
| 137 |
$schema->storage->txn_rollback; |
| 138 |
}; |
| 139 |
|
| 140 |
subtest 'in_bundle tests' => sub { |
| 141 |
plan tests => 2; |
| 142 |
|
| 143 |
$schema->storage->txn_begin; |
| 144 |
|
| 145 |
my $item = $builder->build_sample_item(); |
| 146 |
|
| 147 |
my $in_bundle = $item->in_bundle; |
| 148 |
is($in_bundle, 0, 'in_bundle returns 0 when the item is not in a bundle'); |
| 149 |
|
| 150 |
my $host_item = $builder->build_sample_item(); |
| 151 |
$schema->resultset('ItemBundle') |
| 152 |
->create( { host => $host_item->itemnumber, item => $item->itemnumber } ); |
| 153 |
|
| 154 |
$in_bundle = $item->in_bundle; |
| 155 |
is($in_bundle, 1, 'in_bundle returns 1 when the item is in a bundle'); |
| 156 |
|
| 157 |
$schema->storage->txn_rollback; |
| 158 |
}; |
| 159 |
|
| 160 |
subtest 'bundle_items tests' => sub { |
| 161 |
plan tests => 3; |
| 162 |
|
| 163 |
$schema->storage->txn_begin; |
| 164 |
|
| 165 |
my $host_item = $builder->build_sample_item(); |
| 166 |
my $bundle_items = $host_item->bundle_items; |
| 167 |
is( ref($bundle_items), 'Koha::Items', |
| 168 |
'bundle_items returns a Koha::Items object set' ); |
| 169 |
is( $bundle_items->count, 0, |
| 170 |
'bundle_items set is empty when no items are bundled' ); |
| 171 |
|
| 172 |
my $bundle_item1 = $builder->build_sample_item(); |
| 173 |
my $bundle_item2 = $builder->build_sample_item(); |
| 174 |
my $bundle_item3 = $builder->build_sample_item(); |
| 175 |
$schema->resultset('ItemBundle') |
| 176 |
->create( |
| 177 |
{ host => $host_item->itemnumber, item => $bundle_item1->itemnumber } ); |
| 178 |
$schema->resultset('ItemBundle') |
| 179 |
->create( |
| 180 |
{ host => $host_item->itemnumber, item => $bundle_item2->itemnumber } ); |
| 181 |
$schema->resultset('ItemBundle') |
| 182 |
->create( |
| 183 |
{ host => $host_item->itemnumber, item => $bundle_item3->itemnumber } ); |
| 184 |
|
| 185 |
$bundle_items = $host_item->bundle_items; |
| 186 |
is( $bundle_items->count, 3, |
| 187 |
'bundle_items returns all the bundled items in the set' ); |
| 188 |
|
| 189 |
$schema->storage->txn_rollback; |
| 190 |
}; |
| 191 |
|
| 192 |
subtest 'bundle_host tests' => sub { |
| 193 |
plan tests => 3; |
| 194 |
|
| 195 |
$schema->storage->txn_begin; |
| 196 |
|
| 197 |
my $host_item = $builder->build_sample_item(); |
| 198 |
my $bundle_item1 = $builder->build_sample_item(); |
| 199 |
my $bundle_item2 = $builder->build_sample_item(); |
| 200 |
$schema->resultset('ItemBundle') |
| 201 |
->create( |
| 202 |
{ host => $host_item->itemnumber, item => $bundle_item2->itemnumber } ); |
| 203 |
|
| 204 |
my $bundle_host = $bundle_item1->bundle_host; |
| 205 |
is( $bundle_host, undef, 'bundle_host returns undefined when the item it not part of a bundle'); |
| 206 |
$bundle_host = $bundle_item2->bundle_host; |
| 207 |
is( ref($bundle_host), 'Koha::Item', 'bundle_host returns a Koha::Item object when the item is in a bundle'); |
| 208 |
is( $bundle_host->id, $host_item->id, 'bundle_host returns the host item when called against an item in a bundle'); |
| 209 |
|
| 210 |
$schema->storage->txn_rollback; |
| 211 |
}; |
| 212 |
|
| 213 |
subtest 'add_to_bundle tests' => sub { |
| 214 |
plan tests => 3; |
| 215 |
|
| 216 |
$schema->storage->txn_begin; |
| 217 |
|
| 218 |
t::lib::Mocks::mock_preference( 'BundleNotLoanValue', 1 ); |
| 219 |
|
| 220 |
my $host_item = $builder->build_sample_item(); |
| 221 |
my $bundle_item1 = $builder->build_sample_item(); |
| 222 |
my $bundle_item2 = $builder->build_sample_item(); |
| 223 |
|
| 224 |
ok($host_item->add_to_bundle($bundle_item1), 'bundle_item1 added to bundle'); |
| 225 |
is($bundle_item1->notforloan, 1, 'add_to_bundle sets notforloan to BundleNotLoanValue'); |
| 226 |
|
| 227 |
throws_ok { $host_item->add_to_bundle($bundle_item1) } |
| 228 |
'Koha::Exceptions::Object::DuplicateID', |
| 229 |
'Exception thrown if you try to add the same item twice'; |
| 230 |
|
| 231 |
$schema->storage->txn_rollback; |
| 232 |
}; |
| 233 |
|
| 234 |
subtest 'remove_from_bundle tests' => sub { |
| 235 |
plan tests => 3; |
| 236 |
|
| 237 |
$schema->storage->txn_begin; |
| 238 |
|
| 239 |
my $host_item = $builder->build_sample_item(); |
| 240 |
my $bundle_item1 = $builder->build_sample_item({ notforloan => 1 }); |
| 241 |
$schema->resultset('ItemBundle') |
| 242 |
->create( |
| 243 |
{ host => $host_item->itemnumber, item => $bundle_item1->itemnumber } ); |
| 244 |
|
| 245 |
is($bundle_item1->remove_from_bundle(), 1, 'remove_from_bundle returns 1 when item is removed from a bundle'); |
| 246 |
is($bundle_item1->notforloan, 0, 'remove_from_bundle resets notforloan to 0'); |
| 247 |
$bundle_item1 = $bundle_item1->get_from_storage; |
| 248 |
is($bundle_item1->remove_from_bundle(), 0, 'remove_from_bundle returns 0 when item is not in a bundle'); |
| 249 |
|
| 250 |
$schema->storage->txn_rollback; |
| 251 |
}; |
| 252 |
|
| 60 |
subtest 'hidden_in_opac() tests' => sub { |
253 |
subtest 'hidden_in_opac() tests' => sub { |
| 61 |
|
254 |
|
| 62 |
plan tests => 4; |
255 |
plan tests => 4; |
| 63 |
- |
|
|