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

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

Return to bug 12457