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

(-)a/C4/Members.pm (+3 lines)
Lines 1180-1185 C<items> tables of the Koha database. Link Here
1180
sub GetAllIssues {
1180
sub GetAllIssues {
1181
    my ( $borrowernumber, $order, $limit ) = @_;
1181
    my ( $borrowernumber, $order, $limit ) = @_;
1182
1182
1183
    return unless $borrowernumber;
1184
    $order = 'date_due desc' unless $order;
1185
1183
    my $dbh = C4::Context->dbh;
1186
    my $dbh = C4::Context->dbh;
1184
    my $query =
1187
    my $query =
1185
'SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
1188
'SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
(-)a/t/db_dependent/Members.t (-1 / +45 lines)
Lines 6-12 Link Here
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
9
use Test::More tests => 26;
9
use Test::More tests => 47;
10
use Data::Dumper;
10
use Data::Dumper;
11
use C4::Context;
11
use C4::Context;
12
12
Lines 192-197 ModMember(borrowernumber => $member->{'borrowernumber'}, dateexpiry => '2001-01- Link Here
192
$member = GetMemberDetails($member->{'borrowernumber'});
192
$member = GetMemberDetails($member->{'borrowernumber'});
193
ok($member->{is_expired}, "GetMemberDetails() indicates that patron is expired");
193
ok($member->{is_expired}, "GetMemberDetails() indicates that patron is expired");
194
194
195
196
my $message_type = 'B';
197
my $message = 'my message';
198
my $messages_count = GetMessagesCount($member->{borrowernumber}, $message_type, $BRANCHCODE);
199
is( $messages_count, 0, 'GetMessagesCount returns the number of messages correclty' );
200
201
is( AddMessage(), undef, 'AddMessage without argument returns undef' );
202
is( AddMessage(undef, $message_type, $message, $BRANCHCODE), undef,  'AddMessage without the borrower number returns undef' );
203
is( AddMessage($member->{borrowernumber}, undef, $message, $BRANCHCODE), undef,  'AddMessage without the message type returns undef' );
204
is( AddMessage($member->{borrowernumber}, $message_type, undef, $BRANCHCODE), undef,  'AddMessage without the message returns undef' );
205
is( AddMessage($member->{borrowernumber}, $message_type, $message, undef), undef,  'AddMessage without the branch code returns undef' );
206
is( AddMessage($member->{borrowernumber}, $message_type, $message, $BRANCHCODE), 1,  'AddMessage functions correctly' );
207
208
$messages_count = GetMessagesCount();
209
is( $messages_count, 0, 'GetMessagesCount without argument returns 0' );
210
$messages_count = GetMessagesCount(undef, $message_type, $BRANCHCODE);
211
is( $messages_count, '0', 'GetMessagesCount without the borrower number returns the number of messages' );
212
$messages_count = GetMessagesCount($member->{borrowernumber}, undef, $BRANCHCODE);
213
is( $messages_count, '1', 'GetMessagesCount without the message type returns the total number of messages' );
214
$messages_count = GetMessagesCount($member->{borrowernumber}, $message_type, undef);
215
is( $messages_count, '1', 'GetMessagesCount without the branchcode returns the total number of messages' );
216
$messages_count = GetMessagesCount($member->{borrowernumber}, $message_type, $BRANCHCODE);
217
is( $messages_count, '1', 'GetMessagesCount returns the number of messages correctly' );
218
219
my $messages = GetMessages();
220
is( @$messages, 0, 'GetMessages without argument returns 0' );
221
$messages = GetMessages($member->{borrowernumber}, $message_type, $BRANCHCODE);
222
is( @$messages, 1, 'GetMessages returns the correct number of messages' );
223
is( $messages->[0]->{borrowernumber}, $member->{borrowernumber}, 'GetMessages returns the borrower number correctly' );
224
is( $messages->[0]->{message_type}, $message_type, 'GetMessages returns the message type correclty' );
225
is( $messages->[0]->{message}, $message, 'GetMessages returns the message correctly' );
226
is( $messages->[0]->{branchcode}, $BRANCHCODE, 'GetMessages returns the branch code correctly' );
227
228
$messages_count = GetMessagesCount($member->{borrowernumber}, $message_type, $BRANCHCODE);
229
is( $messages_count, 1, 'GetMessagesCount returns the number of messages correclty' );
230
231
DeleteMessage();
232
$messages = GetMessages($member->{borrowernumber}, $message_type, $BRANCHCODE);
233
is( @$messages, 1, 'DeleteMessage without message id does not delete messages' );
234
DeleteMessage($messages->[0]->{message_id});
235
$messages = GetMessages($member->{borrowernumber}, $message_type, $BRANCHCODE);
236
is( @$messages, 0, 'DeleteMessage deletes a message correctly' );
237
238
195
# clean up 
239
# clean up 
196
DelMember($member->{borrowernumber});
240
DelMember($member->{borrowernumber});
197
$results = Search($CARDNUMBER,undef,undef,undef,["cardnumber"]);
241
$results = Search($CARDNUMBER,undef,undef,undef,["cardnumber"]);
(-)a/t/db_dependent/Members/GetAllIssues.t (+89 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 16;
6
use Test::MockModule;
7
8
use C4::Biblio;
9
use C4::Items;
10
use C4::Members;
11
use C4::Branch;
12
use C4::Category;
13
use C4::Circulation;
14
use MARC::Record;
15
16
17
my $dbh = C4::Context->dbh;
18
$dbh->{AutoCommit} = 0;
19
$dbh->{RaiseError} = 1;
20
21
$dbh->do(q|DELETE FROM borrowers|);
22
$dbh->do(q|DELETE FROM branches|);
23
$dbh->do(q|DELETE FROM biblio|);
24
$dbh->do(q|DELETE FROM items|);
25
$dbh->do(q|DELETE FROM categories|);
26
27
28
my $branchcode = 'B';
29
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
30
31
my $categorycode = 'C';
32
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
33
34
my %item_branch_infos = (
35
    homebranch => $branchcode,
36
    holdingbranch => $branchcode,
37
);
38
39
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
40
my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1);
41
my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1);
42
43
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
44
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
45
46
my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode);
47
my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode);
48
my $borrower1 = GetMember(borrowernumber => $borrowernumber1);
49
my $borrower2 = GetMember(borrowernumber => $borrowernumber2);
50
51
my $module = new Test::MockModule('C4::Context');
52
$module->mock('userenv', sub { { branch => $branchcode } });
53
54
55
my $issues = C4::Members::GetAllIssues();
56
is( $issues, undef, 'GetAllIssues without borrower number returns undef' );
57
58
$issues = C4::Members::GetAllIssues($borrowernumber1);
59
is( @$issues, 0, 'GetAllIssues returns the correct number of elements' );
60
$issues = C4::Members::GetAllIssues($borrowernumber2);
61
is( @$issues, 0, 'GetAllIssues returns the correct number of elements' );
62
63
AddIssue($borrower1, '0101');
64
$issues = C4::Members::GetAllIssues($borrowernumber1);
65
my $issues_with_order = C4::Members::GetAllIssues($borrowernumber1, 'date_due desc');
66
is_deeply( $issues, $issues_with_order, 'The value by default for the argument order in GellAllIssues is date_due_desc' );
67
is( @$issues, 1, 'GetAllIssues returns the correct number of elements' );
68
is( $issues->[0]->{itemnumber}, $itemnumber1, '' );
69
$issues = C4::Members::GetAllIssues($borrowernumber2);
70
is( @$issues, 0, 'GetAllIssues returns the correct number of elements' );
71
72
AddIssue($borrower1, '0102');
73
$issues = C4::Members::GetAllIssues($borrowernumber1);
74
is( @$issues, 2, 'GetAllIssues returns the correct number of elements' );
75
is( $issues->[0]->{itemnumber}, $itemnumber1, '' );
76
is( $issues->[1]->{itemnumber}, $itemnumber2, '' );
77
$issues = C4::Members::GetAllIssues($borrowernumber2);
78
is( @$issues, 0, 'GetAllIssues returns the correct number of elements' );
79
80
AddIssue($borrower2, '0203');
81
$issues = C4::Members::GetAllIssues($borrowernumber1);
82
is( @$issues, 2, 'GetAllIssues returns the correct number of elements' );
83
is( $issues->[0]->{itemnumber}, $itemnumber1, '' );
84
is( $issues->[1]->{itemnumber}, $itemnumber2, '' );
85
$issues = C4::Members::GetAllIssues($borrowernumber2);
86
is( @$issues, 1, 'GetAllIssues returns the correct number of elements' );
87
is( $issues->[0]->{itemnumber}, $itemnumber3, '' );
88
89
$dbh->rollback();
(-)a/t/db_dependent/Members/GetPendingIssues.t (-1 / +94 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 20;
6
use Test::MockModule;
7
8
use C4::Biblio;
9
use C4::Items;
10
use C4::Members;
11
use C4::Branch;
12
use C4::Category;
13
use C4::Circulation;
14
use MARC::Record;
15
16
17
my $dbh = C4::Context->dbh;
18
$dbh->{AutoCommit} = 0;
19
$dbh->{RaiseError} = 1;
20
21
$dbh->do(q|DELETE FROM borrowers|);
22
$dbh->do(q|DELETE FROM branches|);
23
$dbh->do(q|DELETE FROM biblio|);
24
$dbh->do(q|DELETE FROM items|);
25
$dbh->do(q|DELETE FROM categories|);
26
27
28
my $branchcode = 'B';
29
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
30
31
my $categorycode = 'C';
32
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
33
34
my %item_branch_infos = (
35
    homebranch => $branchcode,
36
    holdingbranch => $branchcode,
37
);
38
39
my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
40
my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1);
41
my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1);
42
43
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
44
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
45
46
my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode);
47
my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode);
48
my $borrower1 = GetMember(borrowernumber => $borrowernumber1);
49
my $borrower2 = GetMember(borrowernumber => $borrowernumber2);
50
51
my $module = new Test::MockModule('C4::Context');
52
$module->mock('userenv', sub { { branch => $branchcode } });
53
54
55
my $issues = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2);
56
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' );
57
58
AddIssue($borrower1, '0101');
59
$issues = C4::Members::GetPendingIssues($borrowernumber1);
60
is( @$issues, 1, 'GetPendingIssues returns the correct number of elements' );
61
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
62
my $issues_bis = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2);
63
is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' );
64
$issues = C4::Members::GetPendingIssues($borrowernumber2);
65
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' );
66
67
AddIssue($borrower1, '0102');
68
$issues = C4::Members::GetPendingIssues($borrowernumber1);
69
is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' );
70
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
71
is( $issues->[1]->{itemnumber}, $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' );
72
$issues_bis = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2);
73
is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' );
74
$issues = C4::Members::GetPendingIssues($borrowernumber2);
75
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' );
76
77
AddIssue($borrower2, '0203');
78
$issues = C4::Members::GetPendingIssues($borrowernumber2);
79
is( @$issues, 1, 'GetAllIssues returns the correct number of elements' );
80
is( $issues->[0]->{itemnumber}, $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' );
81
$issues = C4::Members::GetPendingIssues($borrowernumber1);
82
is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' );
83
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
84
is( $issues->[1]->{itemnumber}, $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' );
85
$issues = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2);
86
is( @$issues, 3, 'GetPendingIssues returns the correct number of elements' );
87
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
88
is( $issues->[1]->{itemnumber}, $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' );
89
is( $issues->[2]->{itemnumber}, $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' );
90
91
$issues = C4::Members::GetPendingIssues();
92
is( @$issues, 0, 'GetPendingIssues without borrower numbers returns an empty array' );
93
94
$dbh->rollback();

Return to bug 12457