3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Test
::More tests
=> 8;
26 use t
::lib
::TestBuilder
;
27 use Data
::Dumper qw
|Dumper
|;
29 my $schema = Koha
::Database
->new->schema;
30 $schema->storage->txn_begin;
31 my $builder = t
::lib
::TestBuilder
->new;
33 # NOTE This is a trick, if we want to populate the biblioitems table, we should not create a Biblio but a Biblioitem
34 my $param = { source
=> 'Biblioitem' };
36 biblionumber
=> $builder->build($param)->{biblionumber
},
39 biblionumber
=> $builder->build($param)->{biblionumber
},
42 my $item1 = $builder->build(
44 value
=> { biblionumber
=> $from_biblio->{biblionumber
}, },
47 my $item2 = $builder->build(
49 value
=> { biblionumber
=> $from_biblio->{biblionumber
}, },
52 my $item3 = $builder->build(
54 value
=> { biblionumber
=> $to_biblio->{biblionumber
}, },
58 my $bib_level_hold_not_to_move = $builder->build(
59 { source
=> 'Reserve',
60 value
=> { biblionumber
=> $from_biblio->{biblionumber
}, },
63 my $item_level_hold_not_to_move = $builder->build(
64 { source
=> 'Reserve',
65 value
=> { biblionumber
=> $from_biblio->{biblionumber
}, itemnumber
=> $item1->{itemnumber
} },
68 my $item_level_hold_to_move = $builder->build(
69 { source
=> 'Reserve',
70 value
=> { biblionumber
=> $from_biblio->{biblionumber
}, itemnumber
=> $item2->{itemnumber
} },
74 my $to_biblionumber_after_moved = C4
::Items
::MoveItemFromBiblio
( $item2->{itemnumber
}, $from_biblio->{biblionumber
}, $to_biblio->{biblionumber
} );
76 is
( $to_biblionumber_after_moved, $to_biblio->{biblionumber
}, 'MoveItemFromBiblio should return the to_biblionumber if success' );
78 $to_biblionumber_after_moved = C4
::Items
::MoveItemFromBiblio
( $item2->{itemnumber
}, $from_biblio->{biblionumber
}, $to_biblio->{biblionumber
} );
80 is
( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' );
82 my $get_item1 = C4
::Items
::GetItem
( $item1->{itemnumber
} );
83 is
( $get_item1->{biblionumber
}, $from_biblio->{biblionumber
}, 'The item1 should not have been moved' );
84 my $get_item2 = C4
::Items
::GetItem
( $item2->{itemnumber
} );
85 is
( $get_item2->{biblionumber
}, $to_biblio->{biblionumber
}, 'The item2 should have been moved' );
86 my $get_item3 = C4
::Items
::GetItem
( $item3->{itemnumber
} );
87 is
( $get_item3->{biblionumber
}, $to_biblio->{biblionumber
}, 'The item3 should not have been moved' );
89 my $get_bib_level_hold = Koha
::Holds
->find( $bib_level_hold_not_to_move->{reserve_id
} );
90 my $get_item_level_hold_1 = Koha
::Holds
->find( $item_level_hold_not_to_move->{reserve_id
} );
91 my $get_item_level_hold_2 = Koha
::Holds
->find( $item_level_hold_to_move->{reserve_id
} );
93 is
( $get_bib_level_hold->biblionumber, $from_biblio->{biblionumber
}, 'MoveItemFromBiblio should not have moved the biblio-level hold' );
94 is
( $get_item_level_hold_1->biblionumber, $from_biblio->{biblionumber
}, 'MoveItemFromBiblio should not have moved the item-level hold placed on item 1' );
95 is
( $get_item_level_hold_2->biblionumber, $to_biblio->{biblionumber
}, 'MoveItemFromBiblio should have moved the item-level hold placed on item 2' );
97 $schema->storage->txn_rollback;