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

(-)a/t/db_dependent/Virtualshelves.t (-49 / +34 lines)
Lines 19-25 $dbh->{AutoCommit} = 0; Link Here
19
teardown();
19
teardown();
20
20
21
subtest 'CRUD' => sub {
21
subtest 'CRUD' => sub {
22
    plan tests => 13;
22
    plan tests => 12;
23
    my $patron = $builder->build({
23
    my $patron = $builder->build({
24
        source => 'Borrower',
24
        source => 'Borrower',
25
    });
25
    });
Lines 39-47 subtest 'CRUD' => sub { Link Here
39
39
40
    $number_of_shelves = Koha::Virtualshelves->search->count;
40
    $number_of_shelves = Koha::Virtualshelves->search->count;
41
    is( $number_of_shelves, 1, '1 shelf should have been inserted' );
41
    is( $number_of_shelves, 1, '1 shelf should have been inserted' );
42
    is( $shelf->allow_add, 0, 'The default value for allow_add should be 1' );
42
    is( $shelf->allow_change_from_owner, 1, 'The default value for allow_change_from_owner should be 1' );
43
    is( $shelf->allow_delete_own, 1, 'The default value for allow_delete_own should be 0' );
43
    is( $shelf->allow_change_from_others, 0, 'The default value for allow_change_from_others should be 0' );
44
    is( $shelf->allow_delete_other, 0, 'The default value for allow_delete_other should be 0' );
45
    is( output_pref($shelf->created_on), output_pref(dt_from_string), 'The creation time should have been set to today' );
44
    is( output_pref($shelf->created_on), output_pref(dt_from_string), 'The creation time should have been set to today' );
46
45
47
    my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
46
    my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
Lines 194-243 subtest 'Shelf content' => sub { Link Here
194
    my $contents = $shelf->get_contents;
193
    my $contents = $shelf->get_contents;
195
    is( $contents->count, 2, 'There are 2 biblios on this shelf' );
194
    is( $contents->count, 2, 'There are 2 biblios on this shelf' );
196
195
197
    # Patron 2 will try to remove a content
196
    # Patron 2 will try to remove biblios
198
    # allow_add = 0, allow_delete_own = 1, allow_delete_other = 0 => Default values
197
    # allow_change_from_owner = 1, allow_change_from_others = 0 (defaults)
199
    my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
198
    my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
200
    is( $number_of_deleted_biblios, 0, 'Patron 2 removed nothing' );
199
    is( $number_of_deleted_biblios, 0, 'Patron 2 removed nothing' );
201
    # Now try with patron 1
200
    # Now try with patron 1
202
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
201
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
203
    is( $number_of_deleted_biblios, 1, 'Patron 1 removed biblio' );
202
    is( $number_of_deleted_biblios, 1, 'Patron 1 removed biblio' );
204
205
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
203
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
206
    is( $number_of_contents, 1, 'To be sure the content has been deleted' );
204
    is( $number_of_contents, 1, 'To be sure the content has been deleted' );
207
205
208
    # allow_delete_own = 0
206
    # allow_change_from_owner == 0 (readonly)
209
    $shelf->allow_delete_own(0);
207
    $shelf->allow_change_from_owner( 0 );
210
    $shelf->store;
208
    $shelf->store;
211
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
209
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } );
212
    is( $number_of_deleted_biblios, 1, 'Patron 1 removed another biblio' );
210
    is( $number_of_deleted_biblios, 0, 'Owner could not delete' );
213
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
211
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
214
    is( $number_of_contents, 0, 'The biblio should have been deleted to the shelf by the patron, it is his own content (allow_delete_own=0)' );
212
    is( $number_of_contents, 1, 'Number of entries still equal to 1' );
215
    $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
213
    $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} );
214
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
215
    is( $number_of_contents, 1, 'Biblio not added to the list' );
216
    # Add back biblio1
217
    $shelf->allow_change_from_owner( 1 );
218
    $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} );
219
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
220
    is( $number_of_contents, 2, 'Biblio added to the list' );
216
221
217
    # allow_add = 1, allow_delete_own = 1
222
    # allow_change_from_others == 1
218
    $shelf->allow_add(1);
223
    $shelf->allow_change_from_others( 1 );
219
    $shelf->allow_delete_own(1);
220
    $shelf->store;
221
222
    my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
224
    my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
223
    my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
225
    my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
224
225
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
226
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
226
    is( $number_of_contents, 3, 'The biblio should have been added to the shelf by the patron 2' );
227
    is( $number_of_contents, 4, 'The biblio should have been added to the shelf by the patron 2' );
227
228
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
228
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
229
    is( $number_of_deleted_biblios, 1, 'Biblio 3 deleted by patron 2' );
229
    is( $number_of_deleted_biblios, 1, 'Biblio 3 deleted by patron 2' );
230
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
230
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
231
    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) ' );
231
    is( $number_of_contents, 3, 'Back to three entries' );
232
233
    # allow_add = 1, allow_delete_own = 1, allow_delete_other = 1
234
    $shelf->allow_delete_other(1);
235
    $shelf->store;
236
237
    $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } );
238
    is( $number_of_deleted_biblios, 1, 'Biblio 2 deleted by patron 2' );
239
    $number_of_contents = Koha::Virtualshelfcontents->search->count;
240
    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)' );
241
232
242
    teardown();
233
    teardown();
243
};
234
};
Lines 257-265 subtest 'Shelf permissions' => sub { Link Here
257
        {   shelfname    => "my first shelf",
248
        {   shelfname    => "my first shelf",
258
            owner        => $patron1->{borrowernumber},
249
            owner        => $patron1->{borrowernumber},
259
            category     => 2,
250
            category     => 2,
260
            allow_add          => 0,
251
            allow_change_from_owner => 0,
261
            allow_delete_own   => 0,
252
            allow_change_from_others => 0,
262
            allow_delete_other => 0,
263
        }
253
        }
264
    )->store;
254
    )->store;
265
255
Lines 272-287 subtest 'Shelf permissions' => sub { Link Here
272
    is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
262
    is( $public_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
273
    is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
263
    is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
274
264
275
    is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
265
    is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to his list' );
276
    is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
266
    is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
277
267
278
    is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
268
    is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to his list' );
279
    is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
269
    is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
280
270
281
271
282
    $public_shelf->allow_add(1);
272
    $public_shelf->allow_change_from_owner(1);
283
    $public_shelf->allow_delete_own(1);
284
    $public_shelf->allow_delete_other(1);
285
    $public_shelf->store;
273
    $public_shelf->store;
286
274
287
    is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
275
    is( $public_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his public list' );
Lines 294-312 subtest 'Shelf permissions' => sub { Link Here
294
    is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
282
    is( $public_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Public list should not be managed by someone else' );
295
283
296
    is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
284
    is( $public_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
297
    is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 1, 'Public list should not be modified (add) by someone else' );
285
    is( $public_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (add) by someone else' );
298
286
299
    is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
287
    is( $public_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
300
    is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 1, 'Public list should not be modified (remove) by someone else' );
288
    is( $public_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Public list should not be modified (remove) by someone else' );
301
289
302
290
303
    my $private_shelf = Koha::Virtualshelf->new(
291
    my $private_shelf = Koha::Virtualshelf->new(
304
        {   shelfname    => "my first shelf",
292
        {   shelfname    => "my first shelf",
305
            owner        => $patron1->{borrowernumber},
293
            owner        => $patron1->{borrowernumber},
306
            category     => 1,
294
            category     => 1,
307
            allow_add          => 0,
295
            allow_change_from_owner => 0,
308
            allow_delete_own   => 0,
296
            allow_change_from_others => 0,
309
            allow_delete_other => 0,
310
        }
297
        }
311
    )->store;
298
    )->store;
312
299
Lines 319-334 subtest 'Shelf permissions' => sub { Link Here
319
    is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
306
    is( $private_shelf->can_be_managed( $patron1->{borrowernumber} ), 1, 'The owner should be able to manage his list' );
320
    is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
307
    is( $private_shelf->can_be_managed( $patron2->{borrowernumber} ), 0, 'Private list should not be managed by someone else' );
321
308
322
    is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 1, 'The owner should be able to add biblios to his list' );
309
    is( $private_shelf->can_biblios_be_added( $patron1->{borrowernumber} ), 0, 'The owner should not be able to add biblios to his list' );
323
    is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (add) by someone else' );
310
    is( $private_shelf->can_biblios_be_added( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (add) by someone else' );
324
311
325
    is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 1, 'The owner should be able to remove biblios to his list' );
312
    is( $private_shelf->can_biblios_be_removed( $patron1->{borrowernumber} ), 0, 'The owner should not be able to remove biblios to his list' );
326
    is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (remove) by someone else' );
313
    is( $private_shelf->can_biblios_be_removed( $patron2->{borrowernumber} ), 0, 'Private list should not be modified (remove) by someone else' );
327
314
328
315
329
    $private_shelf->allow_add(1);
316
    $private_shelf->allow_change_from_owner(1);
330
    $private_shelf->allow_delete_own(1);
317
    $private_shelf->allow_change_from_others(1);
331
    $private_shelf->allow_delete_other(1);
332
    $private_shelf->store;
318
    $private_shelf->store;
333
319
334
    is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
320
    is( $private_shelf->can_be_viewed( $patron1->{borrowernumber} ), 1, 'The owner should be able to view his list' );
Lines 438-444 subtest 'Get shelves containing biblios' => sub { Link Here
438
    my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} );
424
    my $content3 = $shelf2->add_biblio( $biblio2->{biblionumber}, $patron2->{borrowernumber} );
439
    my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
425
    my $content4 = $shelf2->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} );
440
    my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
426
    my $content5 = $shelf2->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
441
    my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} );
427
    my $content6 = $shelf3->add_biblio( $biblio4->{biblionumber}, $patron1->{borrowernumber} );
442
428
443
    my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
429
    my $shelves_with_biblio1_for_any_patrons = Koha::Virtualshelves->get_shelves_containing_record(
444
        {
430
        {
445
- 

Return to bug 18228