Line 0
Link Here
|
0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
|
3 |
use MARC::Record; |
4 |
use C4::Biblio; |
5 |
|
6 |
use Test::More tests => 7; |
7 |
|
8 |
BEGIN { |
9 |
use_ok('C4::Items'); |
10 |
} |
11 |
|
12 |
my $dbh = C4::Context->dbh; |
13 |
$dbh->{AutoCommit} = 0; |
14 |
$dbh->{RaiseError} = 1; |
15 |
|
16 |
my ( $biblionumber, $bibitemnum ) = get_biblio(); |
17 |
|
18 |
my ( $item_bibnum, $item_bibitemnum, $itemnumber ); |
19 |
( $item_bibnum, $item_bibitemnum, $itemnumber ) = |
20 |
AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber ); |
21 |
|
22 |
my $deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } ); |
23 |
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); |
24 |
my $deleted_item = GetItem($itemnumber); |
25 |
is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." ); |
26 |
|
27 |
( $item_bibnum, $item_bibitemnum, $itemnumber ) = |
28 |
AddItem( { homebranch => 'CPL', holdingbranch => 'CPL' }, $biblionumber ); |
29 |
$deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } ); |
30 |
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" ); |
31 |
$deleted_item = GetItem($itemnumber); |
32 |
is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." ); |
33 |
|
34 |
$deleted = DelItem( { itemnumber => $itemnumber + 1} ); |
35 |
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" ); |
36 |
|
37 |
$deleted = DelItem( { itemnumber => $itemnumber + 1, biblionumber => $biblionumber } ); |
38 |
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" ); |
39 |
|
40 |
# Helper method to set up a Biblio. |
41 |
sub get_biblio { |
42 |
my $bib = MARC::Record->new(); |
43 |
$bib->append_fields( |
44 |
MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ), |
45 |
MARC::Field->new( '245', ' ', ' ', a => 'Silence in the library' ), |
46 |
); |
47 |
my ( $bibnum, $bibitemnum ) = AddBiblio( $bib, '' ); |
48 |
return ( $bibnum, $bibitemnum ); |
49 |
} |