Added a couple of tests.
This commit is contained in:
parent
d0a060afb5
commit
a0df2d5ea3
2 changed files with 40 additions and 3 deletions
20
C4/Shelf.pm
20
C4/Shelf.pm
|
@ -247,6 +247,23 @@ sub bibliocontents {
|
|||
return \@return;
|
||||
}
|
||||
|
||||
|
||||
=head2 C<itemcounter()>
|
||||
|
||||
returns the number of items on the shelf
|
||||
|
||||
my $itemcount=$shelf->itemcounter();
|
||||
|
||||
=cut
|
||||
sub itemcounter {
|
||||
my $self=shift;
|
||||
unless ($self->{ITEMCONTENTS}->{orderby}->{'natural'}) {
|
||||
$self->loadcontents();
|
||||
}
|
||||
my @temparray=@{$self->{ITEMCONTENTS}->{orderby}->{'natural'}};
|
||||
return $#temparray+1;
|
||||
}
|
||||
|
||||
sub shelfcontents {
|
||||
my $self=shift;
|
||||
}
|
||||
|
@ -341,7 +358,7 @@ sub attribute {
|
|||
my $sti=$dbh->prepare("update bookshelfattributes set value=? where bookshelfid=? and attribute=?");
|
||||
$sti->execute($value, $self->{ID}, $attribute);
|
||||
} else {
|
||||
my $sti=$dbh->prepare("inesrt into bookshelfattributes (bookshelfid, attribute, value) values (?, ?, ?)");
|
||||
my $sti=$dbh->prepare("insert into bookshelfattributes (bookshelfid, attribute, value) values (?, ?, ?)");
|
||||
$sti->execute($self->{ID}, $attribute, $value);
|
||||
}
|
||||
}
|
||||
|
@ -408,6 +425,7 @@ sub loadcontents {
|
|||
($orderby,$startat,$number)=@_;
|
||||
}
|
||||
my $bookshelfid=$self->{ID};
|
||||
($orderby) || ($orderby='natural');
|
||||
$self->{ITEMCONTENTS}->{orderby}->{$orderby}=$self->{CACHE}->get( "$bookshelfid\_ITEMCONTENTS_$orderby" );
|
||||
$self->{BIBLIOITEMCONTENTS}->{orderby}->{$orderby}=$self->{CACHE}->get( "$bookshelfid\_BIBLIOITEMCONTENTS_$orderby" );
|
||||
$self->{BIBLIOCONTENTS}->{orderby}->{$orderby}=$self->{CACHE}->get( "$bookshelfid\_BIBLIOCONTENTS_$orderby" );
|
||||
|
|
23
t/Shelf.t
23
t/Shelf.t
|
@ -36,12 +36,31 @@ if (defined $shelf) {
|
|||
}
|
||||
|
||||
|
||||
# Add an item to a shelf
|
||||
# Add some items to the shelves
|
||||
|
||||
|
||||
for ($i=1; $i<20; $i++) {
|
||||
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";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue