Lines 10-32
use MARC::Record;
Link Here
|
10 |
|
10 |
|
11 |
use C4::Biblio qw( AddBiblio DelBiblio ); |
11 |
use C4::Biblio qw( AddBiblio DelBiblio ); |
12 |
use C4::Context; |
12 |
use C4::Context; |
|
|
13 |
use C4::Members qw( AddMember ); |
13 |
|
14 |
|
14 |
|
15 |
|
15 |
my $dbh = C4::Context->dbh; |
16 |
my $dbh = C4::Context->dbh; |
16 |
$dbh->{RaiseError} = 1; |
17 |
$dbh->{RaiseError} = 1; |
17 |
$dbh->{AutoCommit} = 0; |
18 |
$dbh->{AutoCommit} = 0; |
18 |
|
19 |
|
19 |
# Getting some borrowers from database. |
20 |
# Create some borrowers |
20 |
my $query = q{SELECT borrowernumber FROM borrowers LIMIT 10}; |
21 |
my @borrowernumbers; |
21 |
my $borr_ref=$dbh->selectall_arrayref($query); |
22 |
for my $i ( 1 .. 10 ) { |
22 |
if(@$borr_ref==0) { #no borrowers? should not occur of course |
23 |
my $borrowernumber = AddMember( |
23 |
$borr_ref->[0][0]=undef; |
24 |
firstname => 'my firstname', |
24 |
#but even then, we can run this robust test :) |
25 |
surname => 'my surname ' . $i, |
25 |
} |
26 |
categorycode => 'S', |
26 |
my @borrowers; |
27 |
branchcode => 'CPL', |
27 |
foreach(1..10) { |
28 |
); |
28 |
my $t= $_> @$borr_ref ? int(rand()*@$borr_ref): $_-1; #repeat if not enough |
29 |
push @borrowernumbers, $borrowernumber; |
29 |
push @borrowers, $borr_ref->[$t][0]; |
|
|
30 |
} |
30 |
} |
31 |
|
31 |
|
32 |
# Creating some biblios |
32 |
# Creating some biblios |
Lines 58-78
for my $i (0..9){
Link Here
|
58 |
shelfname => $name, |
58 |
shelfname => $name, |
59 |
category => $catg, |
59 |
category => $catg, |
60 |
}, |
60 |
}, |
61 |
$borrowers[$i]); |
61 |
$borrowernumbers[$i]); |
62 |
|
62 |
|
63 |
if($ShelfNumber>-1) { |
63 |
if($ShelfNumber>-1) { |
64 |
ok($ShelfNumber > -1, "created shelf"); # Shelf creation successful; |
64 |
ok($ShelfNumber > -1, "created shelf"); # Shelf creation successful; |
65 |
} |
65 |
} |
66 |
else { |
66 |
else { |
67 |
my $t= C4::VirtualShelves::_CheckShelfName( |
67 |
my $t= C4::VirtualShelves::_CheckShelfName( |
68 |
$name, $catg, $borrowers[$i], 0); |
68 |
$name, $catg, $borrowernumbers[$i], 0); |
69 |
is($t, 0, "Name clash expected on shelf creation"); |
69 |
is($t, 0, "Name clash expected on shelf creation"); |
70 |
} |
70 |
} |
71 |
push @shelves, { |
71 |
push @shelves, { |
72 |
number => $ShelfNumber, |
72 |
number => $ShelfNumber, |
73 |
name => $name, |
73 |
name => $name, |
74 |
catg => $catg, |
74 |
catg => $catg, |
75 |
owner => $borrowers[$i], |
75 |
owner => $borrowernumbers[$i], |
76 |
}; #also push the errors |
76 |
}; #also push the errors |
77 |
} |
77 |
} |
78 |
|
78 |
|
Lines 89-95
for my $i (0..9){
Link Here
|
89 |
my $badNumShelf= AddShelf( { |
89 |
my $badNumShelf= AddShelf( { |
90 |
shelfname=> $shelves[$i]->{name}, |
90 |
shelfname=> $shelves[$i]->{name}, |
91 |
category => 2 |
91 |
category => 2 |
92 |
}, $borrowers[$i]); |
92 |
}, $borrowernumbers[$i]); |
93 |
is($badNumShelf, -1, 'do not create public lists with duplicate names'); |
93 |
is($badNumShelf, -1, 'do not create public lists with duplicate names'); |
94 |
#AddShelf returns -1 if name already exist. |
94 |
#AddShelf returns -1 if name already exist. |
95 |
DelShelf($badNumShelf) if $badNumShelf>-1; #delete if went wrong.. |
95 |
DelShelf($badNumShelf) if $badNumShelf>-1; #delete if went wrong.. |
Lines 127-133
for my $i (0..9){
Link Here
|
127 |
#The different permissions could be tested too. |
127 |
#The different permissions could be tested too. |
128 |
|
128 |
|
129 |
my ($biblistBefore,$countbefore) = GetShelfContents($shelfnumber); |
129 |
my ($biblistBefore,$countbefore) = GetShelfContents($shelfnumber); |
130 |
my $status = AddToShelf($bib,$shelfnumber,$borrowers[$i]); |
130 |
my $status = AddToShelf($bib,$shelfnumber,$borrowernumbers[$i]); |
131 |
my ($biblistAfter,$countafter) = GetShelfContents($shelfnumber); |
131 |
my ($biblistAfter,$countafter) = GetShelfContents($shelfnumber); |
132 |
|
132 |
|
133 |
if ($should_fail) { |
133 |
if ($should_fail) { |
134 |
- |
|
|