Koha/t/Shelf.t
2002-10-24 04:12:10 +00:00

66 lines
1.6 KiB
Perl

BEGIN { $| = 1; print "1..25\n"; }
END {print "not ok 1\n" unless $loaded;}
use C4::Shelf;
use C4::Context;
$loaded = 1;
print "ok 1\n";
# Load some sample data from the items table
my $itemdata;
my $dbh=C4::Context->dbh();
my $sth=$dbh->prepare("select biblionumber,biblioitemnumber,itemnumber from items limit 30");
$sth->execute;
while (my ($biblionumber, $biblioitemnumber, $itemnumber) = $sth->fetchrow) {
push @$itemdata, { biblionumber=>$biblionumber, biblioitemnumber=>$biblioitemnumber, itemnumber=>$itemnumber };
}
if ($itemdata=~/^ARRAY/) {
print "ok 2\n";
} else {
print "not ok 2\n";
}
# Create a couple of new shelves
my $shelf=Shelf->new('Shelf1', -1);
my $shelf2=Shelf->new('Shelf2', -1);
if (defined $shelf) {
print "ok 3\n";
} else {
print "not ok 3\n";
}
# Add some items to the shelves
for ($i=0; $i<20; $i++) {
$shelf->addtoshelf( -add => [[ $$itemdata[$i]->{biblionumber},
$$itemdata[$i]->{biblioitemnumber},
$$itemdata[$i]->{itemnumber} ]]);
}
for ($i=20; $i<30; $i++) {
$shelf2->addtoshelf( -add => [[ $$itemdata[$i]->{biblionumber},
$$itemdata[$i]->{biblioitemnumber},
$$itemdata[$i]->{itemnumber} ]]);
}
if ($shelf->itemcounter() == 20 && $shelf2->itemcounter() == 10 ) {
print "ok 4\n";
} else {
print "not ok 4\n";
}
$shelf->attribute('testattribute1', 'testvalue1');
$shelf->attribute('testattribute2', 'testvalue2');
if ($shelf->attribute('testattribute1') eq 'testvalue1' && $shelf->attribute('testattribute2') eq 'testvalue2') {
print "ok 5\n";
} else {
print "not ok 5\n";
}