Bug 27209: Unit tests
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> (cherry picked from commit295787223e) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> (cherry picked from commit7ac140820b)
This commit is contained in:
parent
d58beb621e
commit
61df2e7898
|
|
@ -19,10 +19,15 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 2;
|
||||
|
||||
use Test::Exception;
|
||||
use Test::MockModule;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
|
||||
use Koha::Libraries;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
my $builder = t::lib::TestBuilder->new;
|
||||
|
||||
|
|
@ -48,3 +53,90 @@ subtest 'patron() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'set_pickup_location() tests' => sub {
|
||||
|
||||
plan tests => 10;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $mock_biblio = Test::MockModule->new('Koha::Biblio');
|
||||
my $mock_item = Test::MockModule->new('Koha::Item');
|
||||
|
||||
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
|
||||
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
|
||||
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' });
|
||||
|
||||
# let's control what Koha::Biblio->pickup_locations returns, for testing
|
||||
$mock_biblio->mock( 'pickup_locations', sub {
|
||||
return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } );
|
||||
});
|
||||
# let's mock what Koha::Item->pickup_locations returns, for testing
|
||||
$mock_item->mock( 'pickup_locations', sub {
|
||||
return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } );
|
||||
});
|
||||
|
||||
my $biblio = $builder->build_sample_biblio;
|
||||
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
|
||||
|
||||
# Test biblio-level holds
|
||||
my $biblio_hold = $builder->build_object(
|
||||
{
|
||||
class => "Koha::Holds",
|
||||
value => {
|
||||
biblionumber => $biblio->biblionumber,
|
||||
branchcode => $library_3->branchcode,
|
||||
itemnumber => undef,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
throws_ok
|
||||
{ $biblio_hold->set_pickup_location({ library_id => $library_1->branchcode }); }
|
||||
'Koha::Exceptions::Hold::InvalidPickupLocation',
|
||||
'Exception thrown on invalid pickup location';
|
||||
|
||||
$biblio_hold->discard_changes;
|
||||
is( $biblio_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' );
|
||||
|
||||
my $ret = $biblio_hold->set_pickup_location({ library_id => $library_2->id });
|
||||
is( ref($ret), 'Koha::Hold', 'self is returned' );
|
||||
|
||||
$biblio_hold->discard_changes;
|
||||
is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
|
||||
|
||||
# Test item-level holds
|
||||
my $item_hold = $builder->build_object(
|
||||
{
|
||||
class => "Koha::Holds",
|
||||
value => {
|
||||
biblionumber => $biblio->biblionumber,
|
||||
branchcode => $library_3->branchcode,
|
||||
itemnumber => $item->itemnumber,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
throws_ok
|
||||
{ $item_hold->set_pickup_location({ library_id => $library_1->branchcode }); }
|
||||
'Koha::Exceptions::Hold::InvalidPickupLocation',
|
||||
'Exception thrown on invalid pickup location';
|
||||
|
||||
$item_hold->discard_changes;
|
||||
is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' );
|
||||
|
||||
$ret = $item_hold->set_pickup_location({ library_id => $library_2->id });
|
||||
is( ref($ret), 'Koha::Hold', 'self is returned' );
|
||||
|
||||
$item_hold->discard_changes;
|
||||
is( $item_hold->branchcode, $library_2->id, 'Pickup location changed correctly' );
|
||||
|
||||
throws_ok
|
||||
{ $item_hold->set_pickup_location({ library_id => undef }); }
|
||||
'Koha::Exceptions::MissingParameter',
|
||||
'Exception thrown if missing parameter';
|
||||
|
||||
is( "$@", 'The library_id parameter is mandatory', 'Exception message is clear' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue