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

(-)a/t/db_dependent/Utils/Datatables_Members.t (-97 / +79 lines)
Lines 28-124 use C4::Members::AttributeTypes; Link Here
28
use Koha::Library;
28
use Koha::Library;
29
29
30
use t::lib::Mocks;
30
use t::lib::Mocks;
31
use t::lib::TestBuilder;
32
33
use Koha::Database;
31
34
32
use_ok( "C4::Utils::DataTables::Members" );
35
use_ok( "C4::Utils::DataTables::Members" );
33
36
34
my $dbh = C4::Context->dbh;
37
my $schema = Koha::Database->new->schema;
35
38
$schema->storage->txn_begin;
36
# Start transaction
37
$dbh->{AutoCommit} = 0;
38
$dbh->{RaiseError} = 1;
39
40
# Pick a categorycode from the DB
41
my @categories   = C4::Category->all;
42
my $categorycode = $categories[0]->categorycode;
43
# Add a new branch so we control what borrowers it has
44
my $branchcode   = "UNC";
45
my $branch_data = {
46
    branchcode     => $branchcode,
47
    branchname     => 'Universidad Nacional de Cordoba',
48
    branchaddress1 => 'Haya de la Torre',
49
    branchaddress2 => 'S/N',
50
    branchzip      => '5000',
51
    branchcity     => 'Cordoba',
52
    branchstate    => 'Cordoba',
53
    branchcountry  => 'Argentina'
54
};
55
Koha::Library->new( $branch_data )->store;
56
57
my %john_doe = (
58
    cardnumber   => '123456',
59
    firstname    => 'John',
60
    surname      => 'Doe',
61
    categorycode => $categorycode,
62
    branchcode   => $branchcode,
63
    dateofbirth  => '1983-03-01',
64
    dateexpiry   => '9999-12-31',
65
    userid       => 'john.doe'
66
);
67
39
68
my %john_smith = (
40
my $builder = t::lib::TestBuilder->new;
69
    cardnumber   => '234567',
70
    firstname    =>  'John',
71
    surname      => 'Smith',
72
    categorycode => $categorycode,
73
    branchcode   => $branchcode,
74
    dateofbirth  => '1982-02-01',
75
    dateexpiry   => '9999-12-31',
76
    userid       => 'john.smith'
77
);
78
41
79
my %jane_doe = (
42
my $library = $builder->build({
80
    cardnumber   => '345678',
43
    source => "Branch",
81
    firstname    =>  'Jane',
44
});
82
    surname      => 'Doe',
83
    categorycode => $categorycode,
84
    branchcode   => $branchcode,
85
    dateofbirth  => '1983-03-01',
86
    dateexpiry   => '9999-12-31',
87
    userid       => 'jane.doe'
88
);
89
45
90
my %jeanpaul_dupont = (
46
my $branchcode=$library->{branchcode};
91
    cardnumber   => '456789',
47
92
    firstname    => 'Jean Paul',
48
my $john_doe = $builder->build({
93
    surname      => 'Dupont',
49
        source => "Borrower",
94
    categorycode => $categorycode,
50
        value => {
95
    branchcode   => $branchcode,
51
            cardnumber   => '123456',
96
    dateofbirth  => '1982-02-01',
52
            firstname    => 'John',
97
    dateexpiry   => '9999-12-31',
53
            surname      => 'Doe',
98
    userid       => 'jeanpaul.dupont'
54
            branchcode   => $branchcode,
99
);
55
            dateofbirth  => '1983-03-01',
56
            userid       => 'john.doe'
57
        },
58
});
100
59
101
my %dupont_brown = (
60
my $john_smith = $builder->build({
102
    cardnumber   => '567890',
61
        source => "Borrower",
103
    firstname    => 'Dupont',
62
        value => {
104
    surname      => 'Brown',
63
            cardnumber   => '234567',
105
    categorycode => $categorycode,
64
            firstname    => 'John',
106
    branchcode   => $branchcode,
65
            surname      => 'Smith',
107
    dateofbirth  => '1979-01-01',
66
            branchcode   => $branchcode,
108
    dateexpiry   => '9999-12-31',
67
            dateofbirth  => '1982-02-01',
109
    userid       => 'dupont.brown'
68
            userid       => 'john.smith'
110
);
69
        },
70
});
111
71
112
$john_doe{borrowernumber} = AddMember( %john_doe );
72
my $jane_doe = $builder->build({
113
warn "Error adding John Doe, check your tests" unless $john_doe{borrowernumber};
73
        source => "Borrower",
114
$john_smith{borrowernumber} = AddMember( %john_smith );
74
        value => {
115
warn "Error adding John Smith, check your tests" unless $john_smith{borrowernumber};
75
            cardnumber   => '345678',
116
$jane_doe{borrowernumber} = AddMember( %jane_doe );
76
            firstname    => 'Jane',
117
warn "Error adding Jane Doe, check your tests" unless $jane_doe{borrowernumber};
77
            surname      => 'Doe',
118
$jeanpaul_dupont{borrowernumber} = AddMember( %jeanpaul_dupont );
78
            branchcode   => $branchcode,
119
warn "Error adding Jean Paul Dupont, check your tests" unless $jeanpaul_dupont{borrowernumber};
79
            dateofbirth  => '1983-03-01',
120
$dupont_brown{borrowernumber} = AddMember( %dupont_brown );
80
            userid       => 'jane.doe'
121
warn "Error adding Dupont Brown, check your tests" unless $dupont_brown{borrowernumber};
81
        },
82
});
83
my $jeanpaul_dupont = $builder->build({
84
        source => "Borrower",
85
        value => {
86
            cardnumber   => '456789',
87
            firstname    => 'Jean Paul',
88
            surname      => 'Dupont',
89
            branchcode   => $branchcode,
90
            dateofbirth  => '1982-02-01',
91
            userid       => 'jeanpaul.dupont'
92
        },
93
});
94
my $dupont_brown = $builder->build({
95
        source => "Borrower",
96
        value => {
97
            cardnumber   => '567890',
98
            firstname    => 'Dupont',
99
            surname      => 'Brown',
100
            branchcode   => $branchcode,
101
            dateofbirth  => '1979-01-01',
102
            userid       => 'dupont.brown'
103
        },
104
});
122
105
123
# Set common datatables params
106
# Set common datatables params
124
my %dt_params = (
107
my %dt_params = (
Lines 138-144 my $search_results = C4::Utils::DataTables::Members::search({ Link Here
138
is( $search_results->{ iTotalDisplayRecords }, 1,
121
is( $search_results->{ iTotalDisplayRecords }, 1,
139
    "John Doe has only one match on $branchcode (Bug 12595)");
122
    "John Doe has only one match on $branchcode (Bug 12595)");
140
123
141
ok( $search_results->{ patrons }[0]->{ cardnumber } eq $john_doe{ cardnumber }
124
ok( $search_results->{ patrons }[0]->{ cardnumber } eq $john_doe->{ cardnumber }
142
    && ! $search_results->{ patrons }[1],
125
    && ! $search_results->{ patrons }[1],
143
    "John Doe is the only match (Bug 12595)");
126
    "John Doe is the only match (Bug 12595)");
144
127
Lines 155-161 is( $search_results->{ iTotalDisplayRecords }, 1, Link Here
155
    "Jane Doe has only one match on $branchcode (Bug 12595)");
138
    "Jane Doe has only one match on $branchcode (Bug 12595)");
156
139
157
is( $search_results->{ patrons }[0]->{ cardnumber },
140
is( $search_results->{ patrons }[0]->{ cardnumber },
158
    $jane_doe{ cardnumber },
141
    $jane_doe->{ cardnumber },
159
    "Jane Doe is the only match (Bug 12595)");
142
    "Jane Doe is the only match (Bug 12595)");
160
143
161
# Search "John"
144
# Search "John"
Lines 171-181 is( $search_results->{ iTotalDisplayRecords }, 2, Link Here
171
    "There are two John at $branchcode");
154
    "There are two John at $branchcode");
172
155
173
is( $search_results->{ patrons }[0]->{ cardnumber },
156
is( $search_results->{ patrons }[0]->{ cardnumber },
174
    $john_doe{ cardnumber },
157
    $john_doe->{ cardnumber },
175
    "John Doe is the first result");
158
    "John Doe is the first result");
176
159
177
is( $search_results->{ patrons }[1]->{ cardnumber },
160
is( $search_results->{ patrons }[1]->{ cardnumber },
178
    $john_smith{ cardnumber },
161
    $john_smith->{ cardnumber },
179
    "John Smith is the second result");
162
    "John Smith is the second result");
180
163
181
# Search "Doe"
164
# Search "Doe"
Lines 191-201 is( $search_results->{ iTotalDisplayRecords }, 2, Link Here
191
    "There are two Doe at $branchcode");
174
    "There are two Doe at $branchcode");
192
175
193
is( $search_results->{ patrons }[0]->{ cardnumber },
176
is( $search_results->{ patrons }[0]->{ cardnumber },
194
    $john_doe{ cardnumber },
177
    $john_doe->{ cardnumber },
195
    "John Doe is the first result");
178
    "John Doe is the first result");
196
179
197
is( $search_results->{ patrons }[1]->{ cardnumber },
180
is( $search_results->{ patrons }[1]->{ cardnumber },
198
    $jane_doe{ cardnumber },
181
    $jane_doe->{ cardnumber },
199
    "Jane Doe is the second result");
182
    "Jane Doe is the second result");
200
183
201
# Search "Smith" as surname - there is only one occurrence of Smith
184
# Search "Smith" as surname - there is only one occurrence of Smith
Lines 211-217 is( $search_results->{ iTotalDisplayRecords }, 1, Link Here
211
    "There is one Smith at $branchcode when searching for surname");
194
    "There is one Smith at $branchcode when searching for surname");
212
195
213
is( $search_results->{ patrons }[0]->{ cardnumber },
196
is( $search_results->{ patrons }[0]->{ cardnumber },
214
    $john_smith{ cardnumber },
197
    $john_smith->{ cardnumber },
215
    "John Smith is the first result");
198
    "John Smith is the first result");
216
199
217
# Search "Dupont" as surname - Dupont is used both as firstname and surname, we
200
# Search "Dupont" as surname - Dupont is used both as firstname and surname, we
Lines 228-234 is( $search_results->{ iTotalDisplayRecords }, 1, Link Here
228
    "There is one Dupont at $branchcode when searching for surname");
211
    "There is one Dupont at $branchcode when searching for surname");
229
212
230
is( $search_results->{ patrons }[0]->{ cardnumber },
213
is( $search_results->{ patrons }[0]->{ cardnumber },
231
    $jeanpaul_dupont{ cardnumber },
214
    $jeanpaul_dupont->{ cardnumber },
232
    "Jean Paul Dupont is the first result");
215
    "Jean Paul Dupont is the first result");
233
216
234
# Search "Doe" as surname - Doe is used twice as surname
217
# Search "Doe" as surname - Doe is used twice as surname
Lines 244-254 is( $search_results->{ iTotalDisplayRecords }, 2, Link Here
244
    "There are two Doe at $branchcode when searching for surname");
227
    "There are two Doe at $branchcode when searching for surname");
245
228
246
is( $search_results->{ patrons }[0]->{ cardnumber },
229
is( $search_results->{ patrons }[0]->{ cardnumber },
247
    $john_doe{ cardnumber },
230
    $john_doe->{ cardnumber },
248
    "John Doe is the first result");
231
    "John Doe is the first result");
249
232
250
is( $search_results->{ patrons }[1]->{ cardnumber },
233
is( $search_results->{ patrons }[1]->{ cardnumber },
251
    $jane_doe{ cardnumber },
234
    $jane_doe->{ cardnumber },
252
    "Jane Doe is the second result");
235
    "Jane Doe is the second result");
253
236
254
# Search by userid
237
# Search by userid
Lines 291-300 $attribute_type->store; Link Here
291
274
292
275
293
C4::Members::Attributes::SetBorrowerAttributes(
276
C4::Members::Attributes::SetBorrowerAttributes(
294
    $john_doe{borrowernumber}, [ { code => $attribute_type->{code}, value => 'the default value for a common user' } ]
277
    $john_doe->{borrowernumber}, [ { code => $attribute_type->{code}, value => 'the default value for a common user' } ]
295
);
278
);
296
C4::Members::Attributes::SetBorrowerAttributes(
279
C4::Members::Attributes::SetBorrowerAttributes(
297
    $jane_doe{borrowernumber}, [ { code => $attribute_type->{code}, value => 'the default value for another common user' } ]
280
    $jane_doe->{borrowernumber}, [ { code => $attribute_type->{code}, value => 'the default value for another common user' } ]
298
);
281
);
299
282
300
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1);
283
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1);
Lines 428-433 foreach my $dateformloo (@datetimeprefs){ Link Here
428
}
411
}
429
412
430
# End
413
# End
431
$dbh->rollback;
414
$schema->storage->txn_rollback;
432
415
433
1;
416
1;
434
- 

Return to bug 14874