Fixes discrepency between bibid and biblionumber. Thanks to Tomasz Wolniewicz for
[koha.git] / t / Shelf.t
1 BEGIN { $| = 1; print "1..25\n"; }
2 END {print "not ok 1\n" unless $loaded;}
3 use C4::Shelf;
4 use C4::Context;
5 $loaded = 1;
6 print "ok 1\n";
7
8
9
10 # Load some sample data from the items table
11 my $itemdata;
12 my $dbh=C4::Context->dbh();
13 my $sth=$dbh->prepare("select biblionumber,biblioitemnumber,itemnumber from items limit 30");
14 $sth->execute;
15 while (my ($biblionumber, $biblioitemnumber, $itemnumber) = $sth->fetchrow) {
16     push @$itemdata, { biblionumber=>$biblionumber, biblioitemnumber=>$biblioitemnumber, itemnumber=>$itemnumber };
17 }
18
19 if ($itemdata=~/^ARRAY/) {
20     print "ok 2\n";
21 } else {
22     print "not ok 2\n";
23 }
24
25
26
27 # Create a couple of new shelves
28
29 my $shelf=Shelf->new('Shelf1', -1);
30 my $shelf2=Shelf->new('Shelf2', -1);
31
32 if (defined $shelf) {
33     print "ok 3\n";
34 } else {
35     print "not ok 3\n";
36 }
37
38
39 # Add some items to the shelves
40
41
42 for ($i=0; $i<20; $i++) {
43     $shelf->addtoshelf( -add => [[ $$itemdata[$i]->{biblionumber},
44                                    $$itemdata[$i]->{biblioitemnumber},
45                                    $$itemdata[$i]->{itemnumber} ]]);
46 }
47 for ($i=20; $i<30; $i++) {
48     $shelf2->addtoshelf( -add => [[ $$itemdata[$i]->{biblionumber},
49                                    $$itemdata[$i]->{biblioitemnumber},
50                                    $$itemdata[$i]->{itemnumber} ]]);
51 }
52
53 if ($shelf->itemcounter() == 20 && $shelf2->itemcounter() == 10 ) {
54     print "ok 4\n";
55 } else {
56     print "not ok 4\n";
57 }
58
59 $shelf->attribute('testattribute1', 'testvalue1');
60 $shelf->attribute('testattribute2', 'testvalue2');
61
62 if ($shelf->attribute('testattribute1') eq 'testvalue1' && $shelf->attribute('testattribute2') eq 'testvalue2') {
63     print "ok 5\n";
64 } else {
65     print "not ok 5\n";
66 }