Browse Source
Get rid of AddToShelf and DelFromShelf Bug 14544: Allow a user to delete his own contents Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>3.22.x
10 changed files with 278 additions and 246 deletions
@ -0,0 +1,45 @@ |
|||
package Koha::Virtualshelfcontent; |
|||
|
|||
# This file is part of Koha. |
|||
# |
|||
# Koha is free software; you can redistribute it and/or modify it under the |
|||
# terms of the GNU General Public License as published by the Free Software |
|||
# Foundation; either version 3 of the License, or (at your option) any later |
|||
# version. |
|||
# |
|||
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
|||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License along |
|||
# with Koha; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use Carp; |
|||
|
|||
use Koha::Database; |
|||
use Koha::Exceptions; |
|||
|
|||
use base qw(Koha::Object); |
|||
|
|||
=head1 NAME |
|||
|
|||
Koha::Virtualshelfcontent - Koha Virtualshelfcontent Object class |
|||
|
|||
=head1 API |
|||
|
|||
=head2 Class Methods |
|||
|
|||
=cut |
|||
|
|||
=head3 type |
|||
|
|||
=cut |
|||
|
|||
sub type { |
|||
return 'Virtualshelfcontent'; |
|||
} |
|||
|
|||
1; |
@ -0,0 +1,50 @@ |
|||
package Koha::Virtualshelfcontents; |
|||
|
|||
# This file is part of Koha. |
|||
# |
|||
# Koha is free software; you can redistribute it and/or modify it under the |
|||
# terms of the GNU General Public License as published by the Free Software |
|||
# Foundation; either version 3 of the License, or (at your option) any later |
|||
# version. |
|||
# |
|||
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
|||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License along |
|||
# with Koha; if not, write to the Free Software Foundation, Inc., |
|||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use Carp; |
|||
|
|||
use Koha::Database; |
|||
|
|||
use Koha::Virtualshelf; |
|||
|
|||
use base qw(Koha::Objects); |
|||
|
|||
=head1 NAME |
|||
|
|||
Koha::Virtualshelfcontents - Koha Virtualshelfcontents Object class |
|||
|
|||
=head1 API |
|||
|
|||
=head2 Class Methods |
|||
|
|||
=cut |
|||
|
|||
=head3 type |
|||
|
|||
=cut |
|||
|
|||
sub type { |
|||
return 'Virtualshelfcontent'; |
|||
} |
|||
|
|||
sub object_class { |
|||
return 'Koha::Virtualshelfcontent'; |
|||
} |
|||
|
|||
1; |
@ -1,135 +0,0 @@ |
|||
#!/usr/bin/perl |
|||
|
|||
# This file is a test script for C4::VirtualShelves.pm |
|||
# Author : Antoine Farnault, antoine@koha-fr.org |
|||
# Larger modifications by Jonathan Druart and Marcel de Rooy |
|||
|
|||
use Modern::Perl; |
|||
use Test::More tests => 56; |
|||
use MARC::Record; |
|||
|
|||
use C4::Biblio qw( AddBiblio DelBiblio ); |
|||
use C4::Context; |
|||
use C4::Members qw( AddMember ); |
|||
|
|||
use Koha::Virtualshelves; |
|||
|
|||
|
|||
my $dbh = C4::Context->dbh; |
|||
$dbh->{RaiseError} = 1; |
|||
$dbh->{AutoCommit} = 0; |
|||
|
|||
# Create some borrowers |
|||
my @borrowernumbers; |
|||
for my $i ( 1 .. 10 ) { |
|||
my $borrowernumber = AddMember( |
|||
firstname => 'my firstname', |
|||
surname => 'my surname ' . $i, |
|||
categorycode => 'S', |
|||
branchcode => 'CPL', |
|||
); |
|||
push @borrowernumbers, $borrowernumber; |
|||
} |
|||
|
|||
# Creating some biblios |
|||
my @biblionumbers; |
|||
foreach(0..9) { |
|||
my ($biblionumber)= AddBiblio(MARC::Record->new, ''); |
|||
#item number ignored |
|||
push @biblionumbers, $biblionumber; |
|||
} |
|||
|
|||
#----------------------------------------------------------------------# |
|||
# |
|||
# TESTS START HERE |
|||
# |
|||
#----------------------------------------------------------------------# |
|||
|
|||
use_ok('C4::VirtualShelves'); |
|||
|
|||
#-----------------------TEST Virtualshelf constructor------------------------# |
|||
|
|||
# creating shelves (could be <10 when names are not unique) |
|||
my @shelves; |
|||
for my $i (0..9){ |
|||
my $name= randomname(); |
|||
my $catg= int(rand(2))+1; |
|||
my $shelf = eval { |
|||
Koha::Virtualshelf->new( |
|||
{ |
|||
shelfname => $name, |
|||
category => $catg, |
|||
owner =>$borrowernumbers[$i], |
|||
} |
|||
)->store; |
|||
}; |
|||
if ( $@ or not $shelf ) { |
|||
my $valid_name = Koha::Virtualshelf->new( |
|||
{ |
|||
shelfname => $name, |
|||
category => $catg, |
|||
owner =>$borrowernumbers[$i], |
|||
} |
|||
)->is_shelfname_valid; |
|||
is( $valid_name, 0, 'If the insert has failed, it should be caused by an invalid shelfname (or maybe not?)' ); |
|||
} else { |
|||
ok($shelf->shelfnumber > -1, "The shelf $i should have been inserted"); |
|||
} |
|||
push @shelves, { |
|||
number => $shelf->shelfnumber, |
|||
name => $shelf->shelfname, |
|||
catg => $shelf->category, |
|||
owner => $borrowernumbers[$i], |
|||
}; |
|||
} |
|||
|
|||
#-----------TEST AddToShelf & GetShelfContents & DelFromShelf functions--------------# |
|||
# usage : &AddToShelf($biblionumber, $shelfnumber); |
|||
# usage : $biblist = &GetShelfContents($shelfnumber); |
|||
# usage : $biblist = GetShelfContents($shelfnumber); |
|||
|
|||
my %used = (); |
|||
for my $i (0..9){ |
|||
my $bib = $biblionumbers[int(rand(9))]; |
|||
my $shelfnumber = $shelves[int(rand(9))]->{number}; |
|||
if($shelfnumber<0) { |
|||
ok(1, 'skip add to list-test for shelf -1'); |
|||
ok(1, 'skip counting list entries for shelf -1'); |
|||
next; |
|||
} |
|||
|
|||
my $key = "$bib\t$shelfnumber"; |
|||
my $should_fail = exists($used{$key}) ? 1 : 0; |
|||
#FIXME We assume here that we have permission to add.. |
|||
#The different permissions could be tested too. |
|||
|
|||
my ($biblistBefore,$countbefore) = GetShelfContents($shelfnumber); |
|||
my $status = AddToShelf($bib,$shelfnumber,$borrowernumbers[$i]); |
|||
my ($biblistAfter,$countafter) = GetShelfContents($shelfnumber); |
|||
|
|||
if ($should_fail) { |
|||
ok(!defined($status), 'failed to add to list when we should'); |
|||
} else { |
|||
ok(defined($status), 'added to list when we should'); |
|||
} |
|||
|
|||
if (defined $status) { |
|||
is($countbefore, $countafter - 1, 'added bib to list'); # the bib has been successfully added. |
|||
} else { |
|||
is($countbefore, $countafter, 'did not add duplicate bib to list'); |
|||
} |
|||
|
|||
$used{$key}++; |
|||
} |
|||
|
|||
#----------------------- SOME SUBS --------------------------------------------# |
|||
|
|||
sub randomname { |
|||
my $rv=''; |
|||
for(0..19) { |
|||
$rv.= ('a'..'z','A'..'Z',0..9) [int(rand()*62)]; |
|||
} |
|||
return $rv; |
|||
} |
|||
|
|||
$dbh->rollback; |
Loading…
Reference in new issue