|
Lines 40-46
my $dbh = C4::Context->dbh;
Link Here
|
| 40 |
teardown(); |
40 |
teardown(); |
| 41 |
|
41 |
|
| 42 |
subtest 'CRUD' => sub { |
42 |
subtest 'CRUD' => sub { |
| 43 |
plan tests => 15; |
43 |
plan tests => 16; |
| 44 |
my $patron = $builder->build( |
44 |
my $patron = $builder->build( |
| 45 |
{ |
45 |
{ |
| 46 |
source => 'Borrower', |
46 |
source => 'Borrower', |
|
Lines 54-60
subtest 'CRUD' => sub {
Link Here
|
| 54 |
my $shelf = Koha::Virtualshelf->new( |
54 |
my $shelf = Koha::Virtualshelf->new( |
| 55 |
{ |
55 |
{ |
| 56 |
shelfname => "my first shelf", |
56 |
shelfname => "my first shelf", |
| 57 |
owner => $patron->{borrowernumber}, |
57 |
owner_id => $patron->{borrowernumber}, |
| 58 |
public => 0, |
58 |
public => 0, |
| 59 |
} |
59 |
} |
| 60 |
)->store; |
60 |
)->store; |
|
Lines 75-80
subtest 'CRUD' => sub {
Link Here
|
| 75 |
'The creation time should have been set to today' |
75 |
'The creation time should have been set to today' |
| 76 |
); |
76 |
); |
| 77 |
|
77 |
|
|
|
78 |
# Test owner accessor is working as expected |
| 79 |
my $owner = $shelf->owner; |
| 80 |
is( |
| 81 |
$owner->borrowernumber, $shelf->owner_id, |
| 82 |
'The owner accessor\'s borrowenumber should match the shelf\'s owner_id' |
| 83 |
); |
| 84 |
|
| 78 |
# Test if creation date will not be overwritten by store |
85 |
# Test if creation date will not be overwritten by store |
| 79 |
my $created = dt_from_string->subtract( hours => 1 ); |
86 |
my $created = dt_from_string->subtract( hours => 1 ); |
| 80 |
$shelf->created_on($created); |
87 |
$shelf->created_on($created); |
|
Lines 93-99
subtest 'CRUD' => sub {
Link Here
|
| 93 |
$shelf = Koha::Virtualshelf->new( |
100 |
$shelf = Koha::Virtualshelf->new( |
| 94 |
{ |
101 |
{ |
| 95 |
shelfname => "my first shelf", |
102 |
shelfname => "my first shelf", |
| 96 |
owner => $patron->{borrowernumber}, |
103 |
owner_id => $patron->{borrowernumber}, |
| 97 |
public => 0, |
104 |
public => 0, |
| 98 |
} |
105 |
} |
| 99 |
)->store; |
106 |
)->store; |
|
Lines 114-120
subtest 'CRUD' => sub {
Link Here
|
| 114 |
$shelf = Koha::Virtualshelf->new( |
121 |
$shelf = Koha::Virtualshelf->new( |
| 115 |
{ |
122 |
{ |
| 116 |
shelfname => "my first shelf", |
123 |
shelfname => "my first shelf", |
| 117 |
owner => $another_patron->{borrowernumber}, |
124 |
owner_id => $another_patron->{borrowernumber}, |
| 118 |
public => 0, |
125 |
public => 0, |
| 119 |
} |
126 |
} |
| 120 |
)->store; |
127 |
)->store; |
|
Lines 218-224
subtest 'Sharing' => sub {
Link Here
|
| 218 |
my $shelf_to_share = Koha::Virtualshelf->new( |
225 |
my $shelf_to_share = Koha::Virtualshelf->new( |
| 219 |
{ |
226 |
{ |
| 220 |
shelfname => "my first shelf", |
227 |
shelfname => "my first shelf", |
| 221 |
owner => $patron_wants_to_share->{borrowernumber}, |
228 |
owner_id => $patron_wants_to_share->{borrowernumber}, |
| 222 |
public => 0, |
229 |
public => 0, |
| 223 |
} |
230 |
} |
| 224 |
)->store; |
231 |
)->store; |
|
Lines 226-232
subtest 'Sharing' => sub {
Link Here
|
| 226 |
my $shelf_not_to_share = Koha::Virtualshelf->new( |
233 |
my $shelf_not_to_share = Koha::Virtualshelf->new( |
| 227 |
{ |
234 |
{ |
| 228 |
shelfname => "my second shelf", |
235 |
shelfname => "my second shelf", |
| 229 |
owner => $patron_wants_to_share->{borrowernumber}, |
236 |
owner_id => $patron_wants_to_share->{borrowernumber}, |
| 230 |
public => 0, |
237 |
public => 0, |
| 231 |
} |
238 |
} |
| 232 |
)->store; |
239 |
)->store; |
|
Lines 331-337
subtest 'Shelf content' => sub {
Link Here
|
| 331 |
my $shelf = Koha::Virtualshelf->new( |
338 |
my $shelf = Koha::Virtualshelf->new( |
| 332 |
{ |
339 |
{ |
| 333 |
shelfname => "my first shelf", |
340 |
shelfname => "my first shelf", |
| 334 |
owner => $patron1->{borrowernumber}, |
341 |
owner_id => $patron1->{borrowernumber}, |
| 335 |
public => 0, |
342 |
public => 0, |
| 336 |
lastmodified => $dt_yesterday, |
343 |
lastmodified => $dt_yesterday, |
| 337 |
} |
344 |
} |
|
Lines 473-479
subtest 'Shelf permissions' => sub {
Link Here
|
| 473 |
my $public_shelf = Koha::Virtualshelf->new( |
480 |
my $public_shelf = Koha::Virtualshelf->new( |
| 474 |
{ |
481 |
{ |
| 475 |
shelfname => "my first shelf", |
482 |
shelfname => "my first shelf", |
| 476 |
owner => $patron1->{borrowernumber}, |
483 |
owner_id => $patron1->{borrowernumber}, |
| 477 |
public => 1, |
484 |
public => 1, |
| 478 |
allow_change_from_owner => 0, |
485 |
allow_change_from_owner => 0, |
| 479 |
allow_change_from_others => 0, |
486 |
allow_change_from_others => 0, |
|
Lines 905-911
subtest 'Shelf permissions' => sub {
Link Here
|
| 905 |
my $private_shelf = Koha::Virtualshelf->new( |
912 |
my $private_shelf = Koha::Virtualshelf->new( |
| 906 |
{ |
913 |
{ |
| 907 |
shelfname => "my first shelf", |
914 |
shelfname => "my first shelf", |
| 908 |
owner => $patron1->{borrowernumber}, |
915 |
owner_id => $patron1->{borrowernumber}, |
| 909 |
public => 0, |
916 |
public => 0, |
| 910 |
allow_change_from_owner => 0, |
917 |
allow_change_from_owner => 0, |
| 911 |
allow_change_from_others => 0, |
918 |
allow_change_from_others => 0, |
|
Lines 1248-1289
subtest 'Get shelves' => sub {
Link Here
|
| 1248 |
my $private_shelf1_1 = Koha::Virtualshelf->new( |
1255 |
my $private_shelf1_1 = Koha::Virtualshelf->new( |
| 1249 |
{ |
1256 |
{ |
| 1250 |
shelfname => "private shelf 1 for patron 1", |
1257 |
shelfname => "private shelf 1 for patron 1", |
| 1251 |
owner => $patron1->{borrowernumber}, |
1258 |
owner_id => $patron1->{borrowernumber}, |
| 1252 |
public => 0, |
1259 |
public => 0, |
| 1253 |
} |
1260 |
} |
| 1254 |
)->store; |
1261 |
)->store; |
| 1255 |
my $private_shelf1_2 = Koha::Virtualshelf->new( |
1262 |
my $private_shelf1_2 = Koha::Virtualshelf->new( |
| 1256 |
{ |
1263 |
{ |
| 1257 |
shelfname => "private shelf 2 for patron 1", |
1264 |
shelfname => "private shelf 2 for patron 1", |
| 1258 |
owner => $patron1->{borrowernumber}, |
1265 |
owner_id => $patron1->{borrowernumber}, |
| 1259 |
public => 0, |
1266 |
public => 0, |
| 1260 |
} |
1267 |
} |
| 1261 |
)->store; |
1268 |
)->store; |
| 1262 |
my $private_shelf2_1 = Koha::Virtualshelf->new( |
1269 |
my $private_shelf2_1 = Koha::Virtualshelf->new( |
| 1263 |
{ |
1270 |
{ |
| 1264 |
shelfname => "private shelf 1 for patron 2", |
1271 |
shelfname => "private shelf 1 for patron 2", |
| 1265 |
owner => $patron2->{borrowernumber}, |
1272 |
owner_id => $patron2->{borrowernumber}, |
| 1266 |
public => 0, |
1273 |
public => 0, |
| 1267 |
} |
1274 |
} |
| 1268 |
)->store; |
1275 |
)->store; |
| 1269 |
my $public_shelf1_1 = Koha::Virtualshelf->new( |
1276 |
my $public_shelf1_1 = Koha::Virtualshelf->new( |
| 1270 |
{ |
1277 |
{ |
| 1271 |
shelfname => "public shelf 1 for patron 1", |
1278 |
shelfname => "public shelf 1 for patron 1", |
| 1272 |
owner => $patron1->{borrowernumber}, |
1279 |
owner_id => $patron1->{borrowernumber}, |
| 1273 |
public => 1, |
1280 |
public => 1, |
| 1274 |
} |
1281 |
} |
| 1275 |
)->store; |
1282 |
)->store; |
| 1276 |
my $public_shelf1_2 = Koha::Virtualshelf->new( |
1283 |
my $public_shelf1_2 = Koha::Virtualshelf->new( |
| 1277 |
{ |
1284 |
{ |
| 1278 |
shelfname => "public shelf 2 for patron 1", |
1285 |
shelfname => "public shelf 2 for patron 1", |
| 1279 |
owner => $patron1->{borrowernumber}, |
1286 |
owner_id => $patron1->{borrowernumber}, |
| 1280 |
public => 1, |
1287 |
public => 1, |
| 1281 |
} |
1288 |
} |
| 1282 |
)->store; |
1289 |
)->store; |
| 1283 |
my $shelf_to_share = Koha::Virtualshelf->new( |
1290 |
my $shelf_to_share = Koha::Virtualshelf->new( |
| 1284 |
{ |
1291 |
{ |
| 1285 |
shelfname => "shared shelf", |
1292 |
shelfname => "shared shelf", |
| 1286 |
owner => $patron1->{borrowernumber}, |
1293 |
owner_id => $patron1->{borrowernumber}, |
| 1287 |
public => 0, |
1294 |
public => 0, |
| 1288 |
} |
1295 |
} |
| 1289 |
)->store; |
1296 |
)->store; |
|
Lines 1360-1380
subtest 'Get shelves containing biblios' => sub {
Link Here
|
| 1360 |
my $shelf1 = Koha::Virtualshelf->new( |
1367 |
my $shelf1 = Koha::Virtualshelf->new( |
| 1361 |
{ |
1368 |
{ |
| 1362 |
shelfname => "my first shelf", |
1369 |
shelfname => "my first shelf", |
| 1363 |
owner => $patron1->{borrowernumber}, |
1370 |
owner_id => $patron1->{borrowernumber}, |
| 1364 |
public => 0, |
1371 |
public => 0, |
| 1365 |
} |
1372 |
} |
| 1366 |
)->store; |
1373 |
)->store; |
| 1367 |
my $shelf2 = Koha::Virtualshelf->new( |
1374 |
my $shelf2 = Koha::Virtualshelf->new( |
| 1368 |
{ |
1375 |
{ |
| 1369 |
shelfname => "my x second shelf", # 'x' to make it sorted after 'third' |
1376 |
shelfname => "my x second shelf", # 'x' to make it sorted after 'third' |
| 1370 |
owner => $patron2->{borrowernumber}, |
1377 |
owner_id => $patron2->{borrowernumber}, |
| 1371 |
public => 0, |
1378 |
public => 0, |
| 1372 |
} |
1379 |
} |
| 1373 |
)->store; |
1380 |
)->store; |
| 1374 |
my $shelf3 = Koha::Virtualshelf->new( |
1381 |
my $shelf3 = Koha::Virtualshelf->new( |
| 1375 |
{ |
1382 |
{ |
| 1376 |
shelfname => "my third shelf", |
1383 |
shelfname => "my third shelf", |
| 1377 |
owner => $patron1->{borrowernumber}, |
1384 |
owner_id => $patron1->{borrowernumber}, |
| 1378 |
public => 1, |
1385 |
public => 1, |
| 1379 |
} |
1386 |
} |
| 1380 |
)->store; |
1387 |
)->store; |
|
Lines 1467-1475
subtest 'cannot_be_transferred' => sub {
Link Here
|
| 1467 |
$removed_patron->delete; |
1474 |
$removed_patron->delete; |
| 1468 |
|
1475 |
|
| 1469 |
# Create three lists |
1476 |
# Create three lists |
| 1470 |
my $private_list = Koha::Virtualshelf->new( { shelfname => "A", owner => $listowner->id } )->store; |
1477 |
my $private_list = Koha::Virtualshelf->new( { shelfname => "A", owner_id => $listowner->id } )->store; |
| 1471 |
my $public_list = Koha::Virtualshelf->new( { shelfname => "B", public => 1, owner => $listowner->id } )->store; |
1478 |
my $public_list = Koha::Virtualshelf->new( { shelfname => "B", public => 1, owner_id => $listowner->id } )->store; |
| 1472 |
my $shared_list = Koha::Virtualshelf->new( { shelfname => "C", owner => $listowner->id } )->store; |
1479 |
my $shared_list = Koha::Virtualshelf->new( { shelfname => "C", owner_id => $listowner->id } )->store; |
| 1473 |
$shared_list->share("key")->accept( "key", $receiver->id ); |
1480 |
$shared_list->share("key")->accept( "key", $receiver->id ); |
| 1474 |
|
1481 |
|
| 1475 |
# Test on private list |
1482 |
# Test on private list |
|
Lines 1606-1613
subtest 'filter_by_readable() tests' => sub {
Link Here
|
| 1606 |
{ |
1613 |
{ |
| 1607 |
class => 'Koha::Virtualshelves', |
1614 |
class => 'Koha::Virtualshelves', |
| 1608 |
value => { |
1615 |
value => { |
| 1609 |
public => 0, |
1616 |
public => 0, |
| 1610 |
owner => $patron_1->id, |
1617 |
owner_id => $patron_1->id, |
| 1611 |
} |
1618 |
} |
| 1612 |
} |
1619 |
} |
| 1613 |
); |
1620 |
); |
|
Lines 1615-1622
subtest 'filter_by_readable() tests' => sub {
Link Here
|
| 1615 |
{ |
1622 |
{ |
| 1616 |
class => 'Koha::Virtualshelves', |
1623 |
class => 'Koha::Virtualshelves', |
| 1617 |
value => { |
1624 |
value => { |
| 1618 |
public => 1, |
1625 |
public => 1, |
| 1619 |
owner => $patron_1->id, |
1626 |
owner_id => $patron_1->id, |
| 1620 |
} |
1627 |
} |
| 1621 |
} |
1628 |
} |
| 1622 |
); |
1629 |
); |
|
Lines 1624-1631
subtest 'filter_by_readable() tests' => sub {
Link Here
|
| 1624 |
{ |
1631 |
{ |
| 1625 |
class => 'Koha::Virtualshelves', |
1632 |
class => 'Koha::Virtualshelves', |
| 1626 |
value => { |
1633 |
value => { |
| 1627 |
public => 0, |
1634 |
public => 0, |
| 1628 |
owner => $patron_2->id, |
1635 |
owner_id => $patron_2->id, |
| 1629 |
} |
1636 |
} |
| 1630 |
} |
1637 |
} |
| 1631 |
); |
1638 |
); |
|
Lines 1633-1640
subtest 'filter_by_readable() tests' => sub {
Link Here
|
| 1633 |
{ |
1640 |
{ |
| 1634 |
class => 'Koha::Virtualshelves', |
1641 |
class => 'Koha::Virtualshelves', |
| 1635 |
value => { |
1642 |
value => { |
| 1636 |
public => 1, |
1643 |
public => 1, |
| 1637 |
owner => $patron_2->id, |
1644 |
owner_id => $patron_2->id, |
| 1638 |
} |
1645 |
} |
| 1639 |
} |
1646 |
} |
| 1640 |
); |
1647 |
); |
|
Lines 1653-1659
subtest 'filter_by_readable() tests' => sub {
Link Here
|
| 1653 |
is( $lists->count, 3, 'Three lists are returned' ); |
1660 |
is( $lists->count, 3, 'Three lists are returned' ); |
| 1654 |
|
1661 |
|
| 1655 |
while ( my $list = $lists->next ) { |
1662 |
while ( my $list = $lists->next ) { |
| 1656 |
ok( $list->owner == $patron_1->id || $list->public, 'Only public or self lists in the resultset' ); |
1663 |
ok( $list->owner_id == $patron_1->id || $list->public, 'Only public or self lists in the resultset' ); |
| 1657 |
} |
1664 |
} |
| 1658 |
|
1665 |
|
| 1659 |
$schema->storage->txn_rollback; |
1666 |
$schema->storage->txn_rollback; |