Bug 10274: UT: Acquisition.t needs to create its own data
[koha.git] / t / db_dependent / Reserves.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use Test::More tests => 4;
6 use MARC::Record;
7
8 use C4::Branch;
9 use C4::Biblio;
10 use C4::Items;
11 use C4::Members;
12
13 BEGIN {
14     use_ok('C4::Reserves');
15 }
16
17 my $dbh = C4::Context->dbh;
18
19 # Start transaction
20 $dbh->{AutoCommit} = 0;
21 $dbh->{RaiseError} = 1;
22
23 # Setup Test------------------------
24 # Helper biblio.
25 diag("\nCreating biblio instance for testing.");
26 my $bib = MARC::Record->new();
27 my $title = 'Silence in the library';
28 $bib->append_fields(
29     MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
30     MARC::Field->new('245', ' ', ' ', a => $title),
31 );
32 my ($bibnum, $bibitemnum);
33 ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
34 # Helper item for that biblio.
35 diag("Creating item instance for testing.");
36 my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
37
38 # Modify item; setting barcode.
39 my $testbarcode = '97531';
40 ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
41
42 # Create a borrower
43 my %data = (
44     firstname =>  'my firstname',
45     surname => 'my surname',
46     categorycode => 'S',
47     branchcode => 'CPL',
48 );
49 my $borrowernumber = AddMember(%data);
50 my $borrower = GetMember( borrowernumber => $borrowernumber );
51 my $biblionumber   = $bibnum;
52 my $barcode        = $testbarcode;
53
54 my $constraint     = 'a';
55 my $bibitems       = '';
56 my $priority       = '1';
57 my $resdate        = undef;
58 my $expdate        = undef;
59 my $notes          = '';
60 my $checkitem      = undef;
61 my $found          = undef;
62
63 my @branches = GetBranchesLoop();
64 my $branch = $branches[0][0]{value};
65
66 AddReserve($branch,    $borrowernumber, $biblionumber,
67         $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
68         $title,      $checkitem, $found);
69
70 my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
71
72 is($status, "Reserved", "CheckReserves Test 1");
73
74 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
75 is($status, "Reserved", "CheckReserves Test 2");
76
77 ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
78 is($status, "Reserved", "CheckReserves Test 3");