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

(-)a/t/db_dependent/VirtualShelves.t (-17 / +16 lines)
Lines 50-56 use_ok('C4::VirtualShelves'); Link Here
50
50
51
# creating shelves (could be <10 when names are not unique)
51
# creating shelves (could be <10 when names are not unique)
52
my @shelves;
52
my @shelves;
53
for my $i(0..9){
53
for my $i (0..9){
54
    my $name= randomname();
54
    my $name= randomname();
55
    my $catg= int(rand(2))+1;
55
    my $catg= int(rand(2))+1;
56
    my $ShelfNumber= AddShelf(
56
    my $ShelfNumber= AddShelf(
Lines 66-72 for my $i(0..9){ Link Here
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, $borrowers[$i], 0);
69
        ok($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,
Lines 77-83 for my $i(0..9){ Link Here
77
}
77
}
78
78
79
# try to create shelves with duplicate names
79
# try to create shelves with duplicate names
80
for my $i(0..9){
80
for my $i (0..9){
81
    if($shelves[$i]->{number}<0) {
81
    if($shelves[$i]->{number}<0) {
82
        ok(1, 'skip duplicate test for earlier name clash');
82
        ok(1, 'skip duplicate test for earlier name clash');
83
        next;
83
        next;
Lines 90-96 for my $i(0..9){ Link Here
90
            shelfname=> $shelves[$i]->{name},
90
            shelfname=> $shelves[$i]->{name},
91
            category => 2
91
            category => 2
92
        }, $borrowers[$i]);
92
        }, $borrowers[$i]);
93
        ok(-1==$badNumShelf, '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..
96
    }
96
    }
Lines 101-107 for my $i(0..9){ Link Here
101
                category => 1,
101
                category => 1,
102
            },
102
            },
103
            $shlf[2]): -1;
103
            $shlf[2]): -1;
104
        ok(-1==$badNumShelf, 'do not create private lists with duplicate name for same user');
104
        is($badNumShelf, -1, 'do not create private lists with duplicate name for same user');
105
        DelShelf($badNumShelf) if $badNumShelf>-1; #delete if went wrong..
105
        DelShelf($badNumShelf) if $badNumShelf>-1; #delete if went wrong..
106
    }
106
    }
107
}
107
}
Lines 112-118 for my $i(0..9){ Link Here
112
# usage : $biblist = GetShelfContents($shelfnumber);
112
# usage : $biblist = GetShelfContents($shelfnumber);
113
113
114
my %used = ();
114
my %used = ();
115
for my $i(0..9){
115
for my $i (0..9){
116
    my $bib = $biblionumbers[int(rand(9))];
116
    my $bib = $biblionumbers[int(rand(9))];
117
    my $shelfnumber = $shelves[int(rand(9))]->{number};
117
    my $shelfnumber = $shelves[int(rand(9))]->{number};
118
    if($shelfnumber<0) {
118
    if($shelfnumber<0) {
Lines 137-145 for my $i(0..9){ Link Here
137
    }
137
    }
138
138
139
    if (defined $status) {
139
    if (defined $status) {
140
        ok($countbefore == $countafter - 1, 'added bib to list');  # the bib has been successfuly added.
140
        is($countbefore, $countafter - 1, 'added bib to list');  # the bib has been successfuly added.
141
    } else {
141
    } else {
142
        ok($countbefore == $countafter, 'did not add duplicate bib to list');
142
        is($countbefore, $countafter, 'did not add duplicate bib to list');
143
    }
143
    }
144
144
145
    $used{$key}++;
145
    $used{$key}++;
Lines 149-155 for my $i(0..9){ Link Here
149
# usage : ModShelf($shelfnumber, $shelfname, $owner, $category )
149
# usage : ModShelf($shelfnumber, $shelfname, $owner, $category )
150
# usage : (shelfnumber,shelfname,owner,category) = GetShelf($shelfnumber);
150
# usage : (shelfnumber,shelfname,owner,category) = GetShelf($shelfnumber);
151
151
152
for my $i(0..9){
152
for my $i (0..9){
153
    my $rand = int(rand(9));
153
    my $rand = int(rand(9));
154
    my $numA = $shelves[$rand]->{number};
154
    my $numA = $shelves[$rand]->{number};
155
    if($numA<0) {
155
    if($numA<0) {
Lines 168-176 for my $i(0..9){ Link Here
168
            $shelves[$rand]->{owner}, $numA)) {
168
            $shelves[$rand]->{owner}, $numA)) {
169
        ModShelf($numA,$shelf);
169
        ModShelf($numA,$shelf);
170
        my ($numB,$nameB,$ownerB,$categoryB) = GetShelf($numA);
170
        my ($numB,$nameB,$ownerB,$categoryB) = GetShelf($numA);
171
        ok($numA == $numB, 'modified shelf');
171
        is($numA, $numB, 'modified shelf');
172
        ok($shelf->{shelfname} eq $nameB,     '... and name change took');
172
        is($shelf->{shelfname}, $nameB,     '... and name change took');
173
        ok($shelf->{category}  eq $categoryB, '... and category change took');
173
        is($shelf->{category}, $categoryB, '... and category change took');
174
    }
174
    }
175
    else {
175
    else {
176
        ok(1, "No ModShelf for $newname") for 1..3;
176
        ok(1, "No ModShelf for $newname") for 1..3;
Lines 187-193 my $cnt1=$dbh->selectrow_array($sql_sharecount); Link Here
187
#try to add a share without shelfnumber: should fail
187
#try to add a share without shelfnumber: should fail
188
AddShare(0, 'abcdefghij');
188
AddShare(0, 'abcdefghij');
189
my $cnt2=$dbh->selectrow_array($sql_sharecount);
189
my $cnt2=$dbh->selectrow_array($sql_sharecount);
190
ok($cnt1 == $cnt2, "Did not add an invalid share record");
190
is($cnt1,$cnt2, "Did not add an invalid share record");
191
191
192
#add another share: should be okay
192
#add another share: should be okay
193
#AddShare assumes that you tested if category==private (so we could actually
193
#AddShare assumes that you tested if category==private (so we could actually
Lines 199-217 if($n<0) { Link Here
199
else {
199
else {
200
    AddShare($n, 'abcdefghij');
200
    AddShare($n, 'abcdefghij');
201
    my $cnt3=$dbh->selectrow_array($sql_sharecount);
201
    my $cnt3=$dbh->selectrow_array($sql_sharecount);
202
    ok(1+$cnt2 == $cnt3, "Added one new share record with invitekey");
202
    is(1+$cnt2, $cnt3, "Added one new share record with invitekey");
203
}
203
}
204
204
205
#----------------TEST DelShelf & DelFromShelf functions------------------------#
205
#----------------TEST DelShelf & DelFromShelf functions------------------------#
206
206
207
for(my $i=0; $i<10;$i++){
207
for my $i (0..9){
208
    my $shelfnumber = $shelves[$i]->{number};
208
    my $shelfnumber = $shelves[$i]->{number};
209
    if($shelfnumber<0) {
209
    if($shelfnumber<0) {
210
        ok(1, 'Skip DelShelf for shelf -1');
210
        ok(1, 'Skip DelShelf for shelf -1');
211
        next;
211
        next;
212
    }
212
    }
213
    my $status = DelShelf($shelfnumber);
213
    my $status = DelShelf($shelfnumber);
214
    ok(1 == $status, "deleted shelf $shelfnumber and its contents");
214
    is($status, 1, "deleted shelf $shelfnumber and its contents");
215
}
215
}
216
216
217
#----------------------- SOME SUBS --------------------------------------------#
217
#----------------------- SOME SUBS --------------------------------------------#
218
- 

Return to bug 10441