Lines 19-28
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
|
|
23 |
|
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
23 |
|
26 |
|
24 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
25 |
|
28 |
|
|
|
29 |
use Koha::Libraries; |
30 |
|
26 |
my $schema = Koha::Database->new->schema; |
31 |
my $schema = Koha::Database->new->schema; |
27 |
my $builder = t::lib::TestBuilder->new; |
32 |
my $builder = t::lib::TestBuilder->new; |
28 |
|
33 |
|
Lines 48-50
subtest 'patron() tests' => sub {
Link Here
|
48 |
|
53 |
|
49 |
$schema->storage->txn_rollback; |
54 |
$schema->storage->txn_rollback; |
50 |
}; |
55 |
}; |
51 |
- |
56 |
|
|
|
57 |
subtest 'set_pickup_location() tests' => sub { |
58 |
|
59 |
plan tests => 10; |
60 |
|
61 |
$schema->storage->txn_begin; |
62 |
|
63 |
my $mock_biblio = Test::MockModule->new('Koha::Biblio'); |
64 |
my $mock_item = Test::MockModule->new('Koha::Item'); |
65 |
|
66 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
67 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
68 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
69 |
|
70 |
# let's control what Koha::Biblio->pickup_locations returns, for testing |
71 |
$mock_biblio->mock( 'pickup_locations', sub { |
72 |
return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } ); |
73 |
}); |
74 |
# let's mock what Koha::Item->pickup_locations returns, for testing |
75 |
$mock_item->mock( 'pickup_locations', sub { |
76 |
return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } ); |
77 |
}); |
78 |
|
79 |
my $biblio = $builder->build_sample_biblio; |
80 |
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
81 |
|
82 |
# Test biblio-level holds |
83 |
my $biblio_hold = $builder->build_object( |
84 |
{ |
85 |
class => "Koha::Holds", |
86 |
value => { |
87 |
biblionumber => $biblio->biblionumber, |
88 |
branchcode => $library_3->branchcode, |
89 |
itemnumber => undef, |
90 |
} |
91 |
} |
92 |
); |
93 |
|
94 |
throws_ok |
95 |
{ $biblio_hold->set_pickup_location({ library_id => $library_1->branchcode }); } |
96 |
'Koha::Exceptions::Hold::InvalidPickupLocation', |
97 |
'Exception thrown on invalid pickup location'; |
98 |
|
99 |
$biblio_hold->discard_changes; |
100 |
is( $biblio_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); |
101 |
|
102 |
my $ret = $biblio_hold->set_pickup_location({ library_id => $library_2->id }); |
103 |
is( ref($ret), 'Koha::Hold', 'self is returned' ); |
104 |
|
105 |
$biblio_hold->discard_changes; |
106 |
is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' ); |
107 |
|
108 |
# Test item-level holds |
109 |
my $item_hold = $builder->build_object( |
110 |
{ |
111 |
class => "Koha::Holds", |
112 |
value => { |
113 |
biblionumber => $biblio->biblionumber, |
114 |
branchcode => $library_3->branchcode, |
115 |
itemnumber => $item->itemnumber, |
116 |
} |
117 |
} |
118 |
); |
119 |
|
120 |
throws_ok |
121 |
{ $item_hold->set_pickup_location({ library_id => $library_1->branchcode }); } |
122 |
'Koha::Exceptions::Hold::InvalidPickupLocation', |
123 |
'Exception thrown on invalid pickup location'; |
124 |
|
125 |
$item_hold->discard_changes; |
126 |
is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); |
127 |
|
128 |
$ret = $item_hold->set_pickup_location({ library_id => $library_2->id }); |
129 |
is( ref($ret), 'Koha::Hold', 'self is returned' ); |
130 |
|
131 |
$item_hold->discard_changes; |
132 |
is( $item_hold->branchcode, $library_2->id, 'Pickup location changed correctly' ); |
133 |
|
134 |
throws_ok |
135 |
{ $item_hold->set_pickup_location({ library_id => undef }); } |
136 |
'Koha::Exceptions::MissingParameter', |
137 |
'Exception thrown if missing parameter'; |
138 |
|
139 |
is( "$@", 'The library_id parameter is mandatory', 'Exception message is clear' ); |
140 |
|
141 |
$schema->storage->txn_rollback; |
142 |
}; |