View | Details | Raw Unified | Return to bug 14544
Collapse All | Expand All

(-)a/C4/VirtualShelves.pm (-84 / +2 lines)
Lines 41-49 BEGIN { Link Here
41
    @ISA    = qw(Exporter);
41
    @ISA    = qw(Exporter);
42
    @EXPORT = qw(
42
    @EXPORT = qw(
43
            &GetShelves &GetShelfContents
43
            &GetShelves &GetShelfContents
44
            &AddToShelf
45
            &ShelfPossibleAction
44
            &ShelfPossibleAction
46
            &DelFromShelf
47
            &GetBibliosShelves
45
            &GetBibliosShelves
48
    );
46
    );
49
        @EXPORT_OK = qw(
47
        @EXPORT_OK = qw(
Lines 234-274 sub GetShelfContents { Link Here
234
    # or newer, for your version of DBI.
232
    # or newer, for your version of DBI.
235
}
233
}
236
234
237
=head2 AddToShelf
238
239
  &AddToShelf($biblionumber, $shelfnumber, $borrower);
240
241
Adds bib number C<$biblionumber> to virtual virtualshelves number
242
C<$shelfnumber>, unless that bib is already on that shelf.
243
244
=cut
245
246
sub AddToShelf {
247
    my ($biblionumber, $shelfnumber, $borrowernumber) = @_;
248
    return unless $biblionumber;
249
    my $dbh = C4::Context->dbh;
250
    my $query = qq(
251
        SELECT *
252
        FROM   virtualshelfcontents
253
        WHERE  shelfnumber=? AND biblionumber=?
254
    );
255
    my $sth = $dbh->prepare($query);
256
257
    $sth->execute( $shelfnumber, $biblionumber );
258
    ($sth->rows) and return; # already on shelf
259
    $query = qq(
260
        INSERT INTO virtualshelfcontents
261
            (shelfnumber, biblionumber, flags, borrowernumber)
262
        VALUES (?, ?, 0, ?));
263
    $sth = $dbh->prepare($query);
264
    $sth->execute( $shelfnumber, $biblionumber, $borrowernumber);
265
    $query = qq(UPDATE virtualshelves
266
                SET lastmodified = CURRENT_TIMESTAMP
267
                WHERE shelfnumber = ?);
268
    $sth = $dbh->prepare($query);
269
    $sth->execute( $shelfnumber );
270
}
271
272
=head2 ShelfPossibleAction
235
=head2 ShelfPossibleAction
273
236
274
ShelfPossibleAction($loggedinuser, $shelfnumber, $action);
237
ShelfPossibleAction($loggedinuser, $shelfnumber, $action);
Lines 280-286 New additional actions are: invite, acceptshare. Link Here
280
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage.
243
Note that add/delete here refers to adding/deleting entries from the list. Deleting the list itself falls under manage.
281
new_public and new_private refers to creating a new public or private list.
244
new_public and new_private refers to creating a new public or private list.
282
The distinction between deleting your own entries from the list or entries from
245
The distinction between deleting your own entries from the list or entries from
283
others is made in DelFromShelf.
246
others is made when deleting a content from the shelf.
284
247
285
Returns 1 if the user can do the $action in the $shelfnumber shelf.
248
Returns 1 if the user can do the $action in the $shelfnumber shelf.
286
Returns 0 otherwise.
249
Returns 0 otherwise.
Lines 339-345 sub ShelfPossibleAction { Link Here
339
        #this answer is just diplomatic: it says that you may be able to delete
302
        #this answer is just diplomatic: it says that you may be able to delete
340
        #some items from that shelf
303
        #some items from that shelf
341
        #it does not answer the question about a specific biblio
304
        #it does not answer the question about a specific biblio
342
        #DelFromShelf checks the situation per biblio
305
        #Koha::Virtualshelf->remove_biblios checks the situation per biblio
343
        return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1);
306
        return 1 if $user>0 && ($shelf->{allow_delete_own}==1 || $shelf->{allow_delete_other}==1);
344
    }
307
    }
345
    elsif($action eq 'invite') {
308
    elsif($action eq 'invite') {
Lines 370-420 sub ShelfPossibleAction { Link Here
370
    return 0;
333
    return 0;
371
}
334
}
372
335
373
=head2 DelFromShelf
374
375
    $result= &DelFromShelf( $bibref, $shelfnumber, $user);
376
377
Removes biblionumbers in passed arrayref from shelf C<$shelfnumber>.
378
If the bib wasn't on that virtualshelves to begin with, nothing happens.
379
380
Returns 0 if no items have been deleted.
381
382
=cut
383
384
sub DelFromShelf {
385
    my ($bibref, $shelfnumber, $user) = @_;
386
    my $dbh = C4::Context->dbh;
387
    my $query = qq(SELECT allow_delete_own, allow_delete_other FROM virtualshelves WHERE shelfnumber=?);
388
    my $sth= $dbh->prepare($query);
389
    $sth->execute($shelfnumber);
390
    my ($del_own, $del_oth)= $sth->fetchrow;
391
    my $r; my $t=0;
392
393
    if($del_own) {
394
        $query = qq(DELETE FROM virtualshelfcontents
395
            WHERE shelfnumber=? AND biblionumber=? AND borrowernumber=?);
396
        $sth= $dbh->prepare($query);
397
        foreach my $biblionumber (@$bibref) {
398
            $sth->execute($shelfnumber, $biblionumber, $user);
399
            $r= $sth->rows; #Expect -1, 0 or 1 (-1 means Don't know; count as 1)
400
            $t+= ($r==-1)? 1: $r;
401
        }
402
    }
403
    if($del_oth) {
404
        #includes a check if borrowernumber is null (deleted patron)
405
        $query = qq/DELETE FROM virtualshelfcontents
406
            WHERE shelfnumber=? AND biblionumber=? AND
407
            (borrowernumber IS NULL OR borrowernumber<>?)/;
408
        $sth= $dbh->prepare($query);
409
        foreach my $biblionumber (@$bibref) {
410
            $sth->execute($shelfnumber, $biblionumber, $user);
411
            $r= $sth->rows;
412
            $t+= ($r==-1)? 1: $r;
413
        }
414
    }
415
    return $t;
416
}
417
418
=head2 GetBibliosShelves
336
=head2 GetBibliosShelves
419
337
420
This finds all the public lists that this bib record is in.
338
This finds all the public lists that this bib record is in.
(-)a/C4/VirtualShelves/Page.pm (-4 / +4 lines)
Lines 120-136 sub shelfpage { Link Here
120
            elsif(grep { /REM-(\d+)/ } $query->param) {
120
            elsif(grep { /REM-(\d+)/ } $query->param) {
121
            #remove item(s) from shelf
121
            #remove item(s) from shelf
122
                if(ShelfPossibleAction($loggedinuser, $shelfnumber, 'delete')) {
122
                if(ShelfPossibleAction($loggedinuser, $shelfnumber, 'delete')) {
123
                #This is just a general okay; DelFromShelf checks further
124
                    my @bib;
123
                    my @bib;
125
                    foreach($query->param) {
124
                    foreach($query->param) {
126
                        /REM-(\d+)/ or next;
125
                        /REM-(\d+)/ or next;
127
                        push @bib, $1; #$1 is biblionumber
126
                        push @bib, $1; #$1 is biblionumber
128
                    }
127
                    }
129
                    my $t= DelFromShelf(\@bib, $shelfnumber, $loggedinuser);
128
                    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
130
                    if($t==0) {
129
                    my $number_of_biblios_removed = $shelf->remove_biblios( { biblionumbers => \@bib, borrowernumber => $loggedinuser } );
130
                    if( $number_of_biblios_removed == 0) {
131
                        push @paramsloop, {nothingdeleted => $shelfnumber};
131
                        push @paramsloop, {nothingdeleted => $shelfnumber};
132
                    }
132
                    }
133
                    elsif($t<@bib) {
133
                    elsif( $number_of_biblios_removed < @bib ) {
134
                        push @paramsloop, {somedeleted => $shelfnumber};
134
                        push @paramsloop, {somedeleted => $shelfnumber};
135
                    }
135
                    }
136
                }
136
                }
(-)a/Koha/Virtualshelf.pm (+64 lines)
Lines 23-28 use Koha::Database; Link Here
23
use Koha::DateUtils qw( dt_from_string );
23
use Koha::DateUtils qw( dt_from_string );
24
use Koha::Exceptions;
24
use Koha::Exceptions;
25
use Koha::Virtualshelfshare;
25
use Koha::Virtualshelfshare;
26
use Koha::Virtualshelfcontent;
26
27
27
use base qw(Koha::Object);
28
use base qw(Koha::Object);
28
29
Lines 99-104 sub get_shares { Link Here
99
    return $self->{_result}->virtualshelfshares;
100
    return $self->{_result}->virtualshelfshares;
100
}
101
}
101
102
103
sub get_contents {
104
    my ( $self ) = @_;
105
    return $self->{_result}->virtualshelfcontents;
106
}
107
102
sub share {
108
sub share {
103
    my ( $self, $key ) = @_;
109
    my ( $self, $key ) = @_;
104
    unless ( $key ) {
110
    unless ( $key ) {
Lines 136-141 sub remove_share { Link Here
136
    return $shelves->next->delete;
142
    return $shelves->next->delete;
137
}
143
}
138
144
145
sub add_biblio {
146
    my ( $self, $biblionumber, $borrowernumber ) = @_;
147
    return unless $biblionumber;
148
    my $already_exists = $self->get_contents->search(
149
        {
150
            biblionumber => $biblionumber,
151
        }
152
    )->count;
153
    return if $already_exists;
154
    my $content = Koha::Virtualshelfcontent->new(
155
        {
156
            shelfnumber => $self->shelfnumber,
157
            biblionumber => $biblionumber,
158
            borrowernumber => $borrowernumber,
159
        }
160
    )->store;
161
    $self->lastmodified(dt_from_string);
162
    $self->store;
163
164
    return $content;
165
}
166
167
sub remove_biblios {
168
    my ( $self, $params ) = @_;
169
    my $biblionumbers = $params->{biblionumbers} || [];
170
    my $borrowernumber = $params->{borrowernumber};
171
    return unless @$biblionumbers;
172
173
    my $number_deleted = 0;
174
    for my $biblionumber ( @$biblionumbers ) {
175
        if ( $self->allow_delete_own ) {
176
            $number_deleted += $self->get_contents->search(
177
                {
178
                    biblionumber => $biblionumber,
179
                    borrowernumber => $borrowernumber,
180
                }
181
            )->delete;
182
        }
183
        if ( $self->allow_delete_other ) {
184
            $number_deleted += $self->get_contents->search(
185
                {
186
                    biblionumber => $biblionumber,
187
                    # FIXME
188
                    # This does not make sense, but it's has been backported from DelFromShelf.
189
                    # Why shouldn't we allow to remove his own contribution if allow_delete_other is on?
190
                    borrowernumber => {
191
                        -or => {
192
                            '!=' => $borrowernumber,
193
                            '=' => undef
194
                        }
195
                    },
196
                }
197
            )->delete;
198
        }
199
    }
200
    return $number_deleted;
201
}
202
139
sub type {
203
sub type {
140
    return 'Virtualshelve';
204
    return 'Virtualshelve';
141
}
205
}
(-)a/Koha/Virtualshelfcontent.pm (+45 lines)
Line 0 Link Here
1
package Koha::Virtualshelfcontent;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
use Koha::Exceptions;
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::Virtualshelfcontent - Koha Virtualshelfcontent Object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub type {
42
    return 'Virtualshelfcontent';
43
}
44
45
1;
(-)a/Koha/Virtualshelfcontents.pm (+50 lines)
Line 0 Link Here
1
package Koha::Virtualshelfcontents;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::Virtualshelf;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Virtualshelfcontents - Koha Virtualshelfcontents Object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub type {
43
    return 'Virtualshelfcontent';
44
}
45
46
sub object_class {
47
    return 'Koha::Virtualshelfcontent';
48
}
49
50
1;
(-)a/t/db_dependent/VirtualShelves.t (-135 lines)
Lines 1-135 Link Here
1
#!/usr/bin/perl
2
3
# This file is a test script for C4::VirtualShelves.pm
4
# Author : Antoine Farnault, antoine@koha-fr.org
5
# Larger modifications by Jonathan Druart and Marcel de Rooy
6
7
use Modern::Perl;
8
use Test::More tests => 56;
9
use MARC::Record;
10
11
use C4::Biblio qw( AddBiblio DelBiblio );
12
use C4::Context;
13
use C4::Members qw( AddMember );
14
15
use Koha::Virtualshelves;
16
17
18
my $dbh = C4::Context->dbh;
19
$dbh->{RaiseError} = 1;
20
$dbh->{AutoCommit} = 0;
21
22
# Create some borrowers
23
my @borrowernumbers;
24
for my $i ( 1 .. 10 ) {
25
    my $borrowernumber = AddMember(
26
        firstname =>  'my firstname',
27
        surname => 'my surname ' . $i,
28
        categorycode => 'S',
29
        branchcode => 'CPL',
30
    );
31
    push @borrowernumbers, $borrowernumber;
32
}
33
34
# Creating some biblios
35
my @biblionumbers;
36
foreach(0..9) {
37
    my ($biblionumber)= AddBiblio(MARC::Record->new, '');
38
        #item number ignored
39
    push @biblionumbers, $biblionumber;
40
}
41
42
#----------------------------------------------------------------------#
43
#
44
#           TESTS START HERE
45
#
46
#----------------------------------------------------------------------#
47
48
use_ok('C4::VirtualShelves');
49
50
#-----------------------TEST Virtualshelf constructor------------------------#
51
52
# creating shelves (could be <10 when names are not unique)
53
my @shelves;
54
for my $i (0..9){
55
    my $name= randomname();
56
    my $catg= int(rand(2))+1;
57
    my $shelf = eval {
58
        Koha::Virtualshelf->new(
59
            {
60
                shelfname => $name,
61
                category  => $catg,
62
                owner     =>$borrowernumbers[$i],
63
            }
64
        )->store;
65
    };
66
    if ( $@ or not $shelf ) {
67
        my $valid_name = Koha::Virtualshelf->new(
68
            {
69
                shelfname => $name,
70
                category  => $catg,
71
                owner     =>$borrowernumbers[$i],
72
            }
73
        )->is_shelfname_valid;
74
        is( $valid_name, 0, 'If the insert has failed, it should be caused by an invalid shelfname (or maybe not?)' );
75
    } else {
76
        ok($shelf->shelfnumber > -1, "The shelf $i should have been inserted");
77
    }
78
    push @shelves, {
79
        number => $shelf->shelfnumber,
80
        name   => $shelf->shelfname,
81
        catg   => $shelf->category,
82
        owner  => $borrowernumbers[$i],
83
    };
84
}
85
86
#-----------TEST AddToShelf & GetShelfContents &  DelFromShelf functions--------------#
87
# usage : &AddToShelf($biblionumber, $shelfnumber);
88
# usage : $biblist = &GetShelfContents($shelfnumber);
89
# usage : $biblist = GetShelfContents($shelfnumber);
90
91
my %used = ();
92
for my $i (0..9){
93
    my $bib = $biblionumbers[int(rand(9))];
94
    my $shelfnumber = $shelves[int(rand(9))]->{number};
95
    if($shelfnumber<0) {
96
        ok(1, 'skip add to list-test for shelf -1');
97
        ok(1, 'skip counting list entries for shelf -1');
98
        next;
99
    }
100
101
    my $key = "$bib\t$shelfnumber";
102
    my $should_fail = exists($used{$key}) ? 1 : 0;
103
    #FIXME We assume here that we have permission to add..
104
    #The different permissions could be tested too.
105
106
    my ($biblistBefore,$countbefore) = GetShelfContents($shelfnumber);
107
    my $status = AddToShelf($bib,$shelfnumber,$borrowernumbers[$i]);
108
    my ($biblistAfter,$countafter) = GetShelfContents($shelfnumber);
109
110
    if ($should_fail) {
111
        ok(!defined($status), 'failed to add to list when we should');
112
    } else {
113
        ok(defined($status), 'added to list when we should');
114
    }
115
116
    if (defined $status) {
117
        is($countbefore, $countafter - 1, 'added bib to list');  # the bib has been successfully added.
118
    } else {
119
        is($countbefore, $countafter, 'did not add duplicate bib to list');
120
    }
121
122
    $used{$key}++;
123
}
124
125
#----------------------- SOME SUBS --------------------------------------------#
126
127
sub randomname {
128
    my $rv='';
129
    for(0..19) {
130
        $rv.= ('a'..'z','A'..'Z',0..9) [int(rand()*62)];
131
    }
132
    return $rv;
133
}
134
135
$dbh->rollback;
(-)a/t/db_dependent/Virtualshelves.t (-3 / +90 lines)
Lines 1-20 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 2;
4
use Test::More tests => 3;
5
use DateTime::Duration;
5
6
6
use C4::Context;
7
use C4::Context;
7
use Koha::DateUtils;
8
use Koha::DateUtils;
8
use Koha::Virtualshelves;
9
use Koha::Virtualshelves;
9
use Koha::Virtualshelfshares;
10
use Koha::Virtualshelfshares;
11
use Koha::Virtualshelfcontents;
10
12
11
use t::lib::TestBuilder;
13
use t::lib::TestBuilder;
12
14
13
my $dbh = C4::Context->dbh;
15
my $dbh = C4::Context->dbh;
14
$dbh->{AutoCommit} = 0;
16
$dbh->{AutoCommit} = 0;
15
17
16
$dbh->do(q|DELETE FROM virtualshelves|);
17
$dbh->do(q|DELETE FROM virtualshelfshares|);
18
$dbh->do(q|DELETE FROM virtualshelfshares|);
19
$dbh->do(q|DELETE FROM virtualshelfcontents|);
20
$dbh->do(q|DELETE FROM virtualshelves|);
18
21
19
my $builder = t::lib::TestBuilder->new;
22
my $builder = t::lib::TestBuilder->new;
20
23
Lines 143-145 subtest 'Sharing' => sub { Link Here
143
    $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
146
    $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
144
    is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' );
147
    is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' );
145
};
148
};
146
- 
149
150
subtest 'Shelf content' => sub {
151
152
    plan tests => 18;
153
    my $patron1 = $builder->build( { source => 'Borrower', } );
154
    my $patron2 = $builder->build( { source => 'Borrower', } );
155
    my $biblio1 = $builder->build( { source => 'Biblio', } );
156
    my $biblio2 = $builder->build( { source => 'Biblio', } );
157
    my $biblio3 = $builder->build( { source => 'Biblio', } );
158
    my $biblio4 = $builder->build( { source => 'Biblio', } );
159
    my $number_of_contents = Koha::Virtualshelfcontents->search->count;
160
161
    is( $number_of_contents, 0, 'No content should exist' );
162
163
    my $dt_yesterday = dt_from_string->subtract_duration( DateTime::Duration->new( days => 1 ) );
164
    my $shelf = Koha::Virtualshelf->new(
165
        {   shelfname    => "my first shelf",
166
            owner        => $patron1->{borrowernumber},
167
            category     => 1,
168
            lastmodified => $dt_yesterday,
169
        }
170
    )->store;
171
172
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
173
    is( output_pref( dt_from_string $shelf->lastmodified ), output_pref($dt_yesterday), 'The lastmodified has been set to yesterday, will be useful for another test later' );
174
    my $content1 = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
175
    is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' );
176
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
177
    is( output_pref( dt_from_string( $shelf->lastmodified ) ), output_pref(dt_from_string), 'Adding a biblio to a shelf should update the lastmodified for the shelf' );
178
    my $content2 = $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
179
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
180
    is( $number_of_contents, 2, '2 biblio should have been inserted' );
181
182
    my $content1_bis = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
183
    is( $content1_bis, undef, 'add_biblio should return undef on duplicate' );    # Or an exception ?
184
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
185
    is( $number_of_contents, 2, 'The biblio should not have been duplicated' );
186
187
    $shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
188
    my @contents = $shelf->get_contents;
189
    is( scalar(@contents), 2, 'There are 2 biblios on this shelf' );
190
191
    # Patron 2 will try to remove a content
192
    # allow_add = 0, allow_delete_own = 1, allow_delete_other = 0 => Default values
193
    my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
194
    is( $number_of_deleted_biblios, 0, );
195
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
196
    is( $number_of_deleted_biblios, 1, );
197
198
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
199
    is( $number_of_contents, 1, 'To be sure the content has been deleted' );
200
201
    # allow_delete_own = 0
202
    $shelf->allow_delete_own(0);
203
    $shelf->store;
204
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
205
    is( $number_of_deleted_biblios, 0, );
206
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
207
    is( $number_of_contents, 1, 'The biblio should not have been deleted to the shelf by the patron, even if it is his own content (allow_delete_own=0)' );
208
209
    # allow_add = 1, allow_delete_own = 1
210
    $shelf->allow_add(1);
211
    $shelf->allow_delete_own(1);
212
    $shelf->store;
213
214
    my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
215
    my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
216
217
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
218
    is( $number_of_contents, 3, 'The biblio should have been added to the shelf by the patron 2' );
219
220
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
221
    is( $number_of_deleted_biblios, 1, );
222
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
223
    is( $number_of_contents, 2, 'The biblio should have been deleted to the shelf by the patron, it is his own content (allow_delete_own=1) ' );
224
225
    # allow_add = 1, allow_delete_own = 1, allow_delete_other = 1
226
    $shelf->allow_delete_other(1);
227
    $shelf->store;
228
229
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
230
    is( $number_of_deleted_biblios, 1, );
231
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
232
    is( $number_of_contents, 1, 'The biblio should have been deleted to the shelf by the patron 2, even if it is not his own content (allow_delete_other=1)' );
233
};

Return to bug 14544