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

(-)a/Koha/CirculationRules.pm (-1 / +1 lines)
Lines 25-31 use Koha::CirculationRule; Link Here
25
25
26
use base qw(Koha::Objects);
26
use base qw(Koha::Objects);
27
27
28
use constant GUESSED_ITEMTYPES_KEY => 'Koha_IssuingRules_last_guess';
28
use constant GUESSED_ITEMTYPES_KEY => 'Koha_CirculationRules_last_guess';
29
29
30
=head1 NAME
30
=head1 NAME
31
31
(-)a/t/db_dependent/Koha/CirculationRules.t (-4 / +371 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Benchmark;
23
use Test::More tests => 7;
24
use Test::Deep qw( cmp_methods );
23
use Test::Exception;
25
use Test::Exception;
24
26
25
use Koha::CirculationRules;
27
use Koha::CirculationRules;
Lines 27-37 use Koha::Database; Link Here
27
29
28
use t::lib::Mocks;
30
use t::lib::Mocks;
29
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
30
use t::lib::Mocks;
31
32
32
my $schema = Koha::Database->new->schema;
33
my $schema = Koha::Database->new->schema;
33
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
34
35
36
subtest 'get_effective_issuing_rule' => sub {
37
    plan tests => 2;
38
39
    $schema->storage->txn_begin;
40
41
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
42
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
44
45
    subtest 'Call with undefined values' => sub {
46
        plan tests => 5;
47
48
        my $rule;
49
        Koha::CirculationRules->delete;
50
51
        is(Koha::CirculationRules->search->count, 0, 'There are no issuing rules.');
52
        # undef, undef, undef => 1
53
        $rule = Koha::CirculationRules->get_effective_rule({
54
            branchcode   => undef,
55
            categorycode => undef,
56
            itemtype     => undef,
57
            rule_name    => 'fine',
58
            rule_value   => 1,
59
        });
60
        is($rule, undef, 'When I attempt to get effective issuing rule by'
61
           .' providing undefined values, then undef is returned.');
62
63
       # undef, undef, undef => 2
64
        ok(
65
            Koha::CirculationRule->new(
66
                {
67
                    branchcode   => undef,
68
                    categorycode => undef,
69
                    itemtype     => undef,
70
                    rule_name    => 'fine',
71
                    rule_value   => 2,
72
                }
73
              )->store,
74
            'Given I added an issuing rule branchcode => undef,'
75
           .' categorycode => undef, itemtype => undef,');
76
        $rule = Koha::CirculationRules->get_effective_rule({
77
            branchcode   => undef,
78
            categorycode => undef,
79
            itemtype     => undef,
80
            rule_name    => 'fine',
81
        });
82
        _is_row_match(
83
            $rule,
84
            {
85
                branchcode   => undef,
86
                categorycode => undef,
87
                itemtype     => undef,
88
                rule_name    => 'fine',
89
                rule_value   => 2,
90
            },
91
            'When I attempt to get effective'
92
           .' issuing rule by providing undefined values, then the above one is'
93
           .' returned.'
94
        );
95
    };
96
97
    subtest 'Performance' => sub {
98
        plan tests => 4;
99
100
        my $worst_case = timethis(500,
101
                    sub { Koha::CirculationRules->get_effective_rule({
102
                            branchcode   => 'nonexistent',
103
                            categorycode => 'nonexistent',
104
                            itemtype     => 'nonexistent',
105
                            rule_name    => 'nonexistent',
106
                        });
107
                    }
108
                );
109
        my $mid_case = timethis(500,
110
                    sub { Koha::CirculationRules->get_effective_rule({
111
                            branchcode   => $branchcode,
112
                            categorycode => 'nonexistent',
113
                            itemtype     => 'nonexistent',
114
                            rule_name    => 'nonexistent',
115
                        });
116
                    }
117
                );
118
        my $sec_best_case = timethis(500,
119
                    sub { Koha::CirculationRules->get_effective_rule({
120
                            branchcode   => $branchcode,
121
                            categorycode => $categorycode,
122
                            itemtype     => 'nonexistent',
123
                            rule_name    => 'nonexistent',
124
                        });
125
                    }
126
                );
127
        my $best_case = timethis(500,
128
                    sub { Koha::CirculationRules->get_effective_rule({
129
                            branchcode   => $branchcode,
130
                            categorycode => $categorycode,
131
                            itemtype     => $itemtype,
132
                            rule_name    => 'nonexistent',
133
                        });
134
                    }
135
                );
136
        ok($worst_case, 'In worst case, get_effective_issuing_rule finds matching'
137
           .' rule '.sprintf('%.2f', $worst_case->iters/$worst_case->cpu_a)
138
           .' times per second.');
139
        ok($mid_case, 'In mid case, get_effective_issuing_rule finds matching'
140
           .' rule '.sprintf('%.2f', $mid_case->iters/$mid_case->cpu_a)
141
           .' times per second.');
142
        ok($sec_best_case, 'In second best case, get_effective_issuing_rule finds matching'
143
           .' rule '.sprintf('%.2f', $sec_best_case->iters/$sec_best_case->cpu_a)
144
           .' times per second.');
145
        ok($best_case, 'In best case, get_effective_issuing_rule finds matching'
146
           .' rule '.sprintf('%.2f', $best_case->iters/$best_case->cpu_a)
147
           .' times per second.');
148
    };
149
150
    $schema->storage->txn_rollback;
151
152
};
153
154
subtest 'set_rule' => sub {
155
    plan tests => 3;
156
157
    $schema->storage->txn_begin;
158
159
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
160
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
161
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
162
163
    subtest 'Correct call' => sub {
164
        plan tests => 4;
165
166
        Koha::CirculationRules->delete;
167
168
        lives_ok( sub {
169
            Koha::CirculationRules->set_rule( {
170
                branchcode => $branchcode,
171
                rule_name => 'lostreturn',
172
                rule_value => '',
173
            } );
174
        }, 'setting lostreturn with branch' );
175
176
        lives_ok( sub {
177
            Koha::CirculationRules->set_rule( {
178
                branchcode => $branchcode,
179
                categorycode => $categorycode,
180
                rule_name => 'patron_maxissueqty',
181
                rule_value => '',
182
            } );
183
        }, 'setting patron_maxissueqty with branch/category succeeds' );
184
185
        lives_ok( sub {
186
            Koha::CirculationRules->set_rule( {
187
                branchcode => $branchcode,
188
                itemtype => $itemtype,
189
                rule_name => 'holdallowed',
190
                rule_value => '',
191
            } );
192
        }, 'setting holdallowed with branch/itemtype succeeds' );
193
194
        lives_ok( sub {
195
            Koha::CirculationRules->set_rule( {
196
                branchcode => $branchcode,
197
                categorycode => $categorycode,
198
                itemtype => $itemtype,
199
                rule_name => 'fine',
200
                rule_value => '',
201
            } );
202
        }, 'setting fine with branch/category/itemtype succeeds' );
203
    };
204
205
    subtest 'Call with missing params' => sub {
206
        plan tests => 4;
207
208
        Koha::CirculationRules->delete;
209
210
        throws_ok( sub {
211
            Koha::CirculationRules->set_rule( {
212
                rule_name => 'lostreturn',
213
                rule_value => '',
214
            } );
215
        }, qr/branchcode/, 'setting lostreturn without branch fails' );
216
217
        throws_ok( sub {
218
            Koha::CirculationRules->set_rule( {
219
                branchcode => $branchcode,
220
                rule_name => 'patron_maxissueqty',
221
                rule_value => '',
222
            } );
223
        }, qr/categorycode/, 'setting patron_maxissueqty without categorycode fails' );
224
225
        throws_ok( sub {
226
            Koha::CirculationRules->set_rule( {
227
                branchcode => $branchcode,
228
                rule_name => 'holdallowed',
229
                rule_value => '',
230
            } );
231
        }, qr/itemtype/, 'setting holdallowed without itemtype fails' );
232
233
        throws_ok( sub {
234
            Koha::CirculationRules->set_rule( {
235
                branchcode => $branchcode,
236
                categorycode => $categorycode,
237
                rule_name => 'fine',
238
                rule_value => '',
239
            } );
240
        }, qr/itemtype/, 'setting fine without itemtype fails' );
241
    };
242
243
    subtest 'Call with extra params' => sub {
244
        plan tests => 3;
245
246
        Koha::CirculationRules->delete;
247
248
        throws_ok( sub {
249
            Koha::CirculationRules->set_rule( {
250
                branchcode => $branchcode,
251
                categorycode => $categorycode,
252
                rule_name => 'lostreturn',
253
                rule_value => '',
254
            } );
255
        }, qr/categorycode/, 'setting lostreturn with categorycode fails' );
256
257
        throws_ok( sub {
258
            Koha::CirculationRules->set_rule( {
259
                branchcode => $branchcode,
260
                categorycode => $categorycode,
261
                itemtype => $itemtype,
262
                rule_name => 'patron_maxissueqty',
263
                rule_value => '',
264
            } );
265
        }, qr/itemtype/, 'setting patron_maxissueqty with itemtype fails' );
266
267
        throws_ok( sub {
268
            Koha::CirculationRules->set_rule( {
269
                branchcode => $branchcode,
270
                rule_name => 'holdallowed',
271
                categorycode => $categorycode,
272
                itemtype => $itemtype,
273
                rule_value => '',
274
            } );
275
        }, qr/categorycode/, 'setting holdallowed with categorycode fails' );
276
    };
277
278
    $schema->storage->txn_rollback;
279
};
280
281
subtest 'clone' => sub {
282
    plan tests => 2;
283
284
    $schema->storage->txn_begin;
285
286
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
287
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
288
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
289
290
    subtest 'Clone multiple rules' => sub {
291
        plan tests => 4;
292
293
        Koha::CirculationRules->delete;
294
295
        Koha::CirculationRule->new({
296
            branchcode   => undef,
297
            categorycode => $categorycode,
298
            itemtype     => $itemtype,
299
            rule_name    => 'fine',
300
            rule_value   => 5,
301
        })->store;
302
303
        Koha::CirculationRule->new({
304
            branchcode   => undef,
305
            categorycode => $categorycode,
306
            itemtype     => $itemtype,
307
            rule_name    => 'lengthunit',
308
            rule_value   => 'days',
309
        })->store;
310
311
        Koha::CirculationRules->search({ branchcode => undef })->clone($branchcode);
312
313
        my $rule_fine = Koha::CirculationRules->get_effective_rule({
314
            branchcode   => $branchcode,
315
            categorycode => $categorycode,
316
            itemtype     => $itemtype,
317
            rule_name    => 'fine',
318
        });
319
        my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({
320
            branchcode   => $branchcode,
321
            categorycode => $categorycode,
322
            itemtype     => $itemtype,
323
            rule_name    => 'lengthunit',
324
        });
325
326
        _is_row_match(
327
            $rule_fine,
328
            {
329
                branchcode   => $branchcode,
330
                categorycode => $categorycode,
331
                itemtype     => $itemtype,
332
                rule_name    => 'fine',
333
                rule_value   => 5,
334
            },
335
            'When I attempt to get cloned fine rule,'
336
           .' then the above one is returned.'
337
        );
338
        _is_row_match(
339
            $rule_lengthunit,
340
            {
341
                branchcode   => $branchcode,
342
                categorycode => $categorycode,
343
                itemtype     => $itemtype,
344
                rule_name    => 'lengthunit',
345
                rule_value   => 'days',
346
            },
347
            'When I attempt to get cloned lengthunit rule,'
348
           .' then the above one is returned.'
349
        );
350
351
    };
352
353
    subtest 'Clone one rule' => sub {
354
        plan tests => 2;
355
356
        Koha::CirculationRules->delete;
357
358
        Koha::CirculationRule->new({
359
            branchcode   => undef,
360
            categorycode => $categorycode,
361
            itemtype     => $itemtype,
362
            rule_name    => 'fine',
363
            rule_value   => 5,
364
        })->store;
365
366
        my $rule = Koha::CirculationRules->search({ branchcode => undef })->next;
367
        $rule->clone($branchcode);
368
369
        my $cloned_rule = Koha::CirculationRules->get_effective_rule({
370
            branchcode   => $branchcode,
371
            categorycode => $categorycode,
372
            itemtype     => $itemtype,
373
            rule_name    => 'fine',
374
        });
375
376
        _is_row_match(
377
            $cloned_rule,
378
            {
379
                branchcode   => $branchcode,
380
                categorycode => $categorycode,
381
                itemtype     => $itemtype,
382
                rule_name    => 'fine',
383
                rule_value   => '5',
384
            },
385
            'When I attempt to get cloned fine rule,'
386
           .' then the above one is returned.'
387
        );
388
389
    };
390
391
    $schema->storage->txn_rollback;
392
};
393
35
subtest 'set_rule + get_effective_rule' => sub {
394
subtest 'set_rule + get_effective_rule' => sub {
36
    plan tests => 9;
395
    plan tests => 9;
37
396
Lines 128-134 subtest 'set_rule + get_effective_rule' => sub { Link Here
128
487
129
488
130
    subtest 'test rule matching with different combinations of rule scopes' => sub {
489
    subtest 'test rule matching with different combinations of rule scopes' => sub {
131
        my ( $tests, $order ) = prepare_tests_for_rule_scope_combinations(
490
        my ( $tests, $order ) = _prepare_tests_for_rule_scope_combinations(
132
            {
491
            {
133
                branchcode   => $branchcode,
492
                branchcode   => $branchcode,
134
                categorycode => $categorycode,
493
                categorycode => $categorycode,
Lines 442-448 subtest 'get_lostreturn_policy() tests' => sub { Link Here
442
    $schema->storage->txn_rollback;
801
    $schema->storage->txn_rollback;
443
};
802
};
444
803
445
sub prepare_tests_for_rule_scope_combinations {
804
sub _is_row_match {
805
    my ( $rule, $expected, $message ) = @_;
806
807
    ok( $rule, $message ) ?
808
        cmp_methods( $rule, [ %$expected ], $message ) :
809
        fail( $message );
810
}
811
812
sub _prepare_tests_for_rule_scope_combinations {
446
    my ( $scope, $rule_name ) = @_;
813
    my ( $scope, $rule_name ) = @_;
447
814
448
    # Here we create a combinations of 1s and 0s the following way
815
    # Here we create a combinations of 1s and 0s the following way
(-)a/t/db_dependent/Koha/IssuingRules.t (-344 lines)
Lines 35-384 $schema->storage->txn_begin; Link Here
35
35
36
my $builder      = t::lib::TestBuilder->new;
36
my $builder      = t::lib::TestBuilder->new;
37
37
38
subtest 'get_effective_issuing_rule' => sub {
39
    plan tests => 2;
40
38
41
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
42
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
44
45
    subtest 'Call with undefined values' => sub {
46
        plan tests => 5;
47
48
        my $rule;
49
        Koha::CirculationRules->delete;
50
51
        is(Koha::CirculationRules->search->count, 0, 'There are no issuing rules.');
52
        # undef, undef, undef => 1
53
        $rule = Koha::CirculationRules->get_effective_rule({
54
            branchcode   => undef,
55
            categorycode => undef,
56
            itemtype     => undef,
57
            rule_name    => 'fine',
58
            rule_value   => 1,
59
        });
60
        is($rule, undef, 'When I attempt to get effective issuing rule by'
61
           .' providing undefined values, then undef is returned.');
62
63
       # undef, undef, undef => 2
64
        ok(
65
            Koha::CirculationRule->new(
66
                {
67
                    branchcode   => undef,
68
                    categorycode => undef,
69
                    itemtype     => undef,
70
                    rule_name    => 'fine',
71
                    rule_value   => 2,
72
                }
73
              )->store,
74
            'Given I added an issuing rule branchcode => undef,'
75
           .' categorycode => undef, itemtype => undef,');
76
        $rule = Koha::CirculationRules->get_effective_rule({
77
            branchcode   => undef,
78
            categorycode => undef,
79
            itemtype     => undef,
80
            rule_name    => 'fine',
81
        });
82
        _is_row_match(
83
            $rule,
84
            {
85
                branchcode   => undef,
86
                categorycode => undef,
87
                itemtype     => undef,
88
                rule_name    => 'fine',
89
                rule_value   => 2,
90
            },
91
            'When I attempt to get effective'
92
           .' issuing rule by providing undefined values, then the above one is'
93
           .' returned.'
94
        );
95
    };
96
97
    subtest 'Performance' => sub {
98
        plan tests => 4;
99
100
        my $worst_case = timethis(500,
101
                    sub { Koha::CirculationRules->get_effective_rule({
102
                            branchcode   => 'nonexistent',
103
                            categorycode => 'nonexistent',
104
                            itemtype     => 'nonexistent',
105
                            rule_name    => 'nonexistent',
106
                        });
107
                    }
108
                );
109
        my $mid_case = timethis(500,
110
                    sub { Koha::CirculationRules->get_effective_rule({
111
                            branchcode   => $branchcode,
112
                            categorycode => 'nonexistent',
113
                            itemtype     => 'nonexistent',
114
                            rule_name    => 'nonexistent',
115
                        });
116
                    }
117
                );
118
        my $sec_best_case = timethis(500,
119
                    sub { Koha::CirculationRules->get_effective_rule({
120
                            branchcode   => $branchcode,
121
                            categorycode => $categorycode,
122
                            itemtype     => 'nonexistent',
123
                            rule_name    => 'nonexistent',
124
                        });
125
                    }
126
                );
127
        my $best_case = timethis(500,
128
                    sub { Koha::CirculationRules->get_effective_rule({
129
                            branchcode   => $branchcode,
130
                            categorycode => $categorycode,
131
                            itemtype     => $itemtype,
132
                            rule_name    => 'nonexistent',
133
                        });
134
                    }
135
                );
136
        ok($worst_case, 'In worst case, get_effective_issuing_rule finds matching'
137
           .' rule '.sprintf('%.2f', $worst_case->iters/$worst_case->cpu_a)
138
           .' times per second.');
139
        ok($mid_case, 'In mid case, get_effective_issuing_rule finds matching'
140
           .' rule '.sprintf('%.2f', $mid_case->iters/$mid_case->cpu_a)
141
           .' times per second.');
142
        ok($sec_best_case, 'In second best case, get_effective_issuing_rule finds matching'
143
           .' rule '.sprintf('%.2f', $sec_best_case->iters/$sec_best_case->cpu_a)
144
           .' times per second.');
145
        ok($best_case, 'In best case, get_effective_issuing_rule finds matching'
146
           .' rule '.sprintf('%.2f', $best_case->iters/$best_case->cpu_a)
147
           .' times per second.');
148
    };
149
};
150
151
subtest 'set_rule' => sub {
152
    plan tests => 3;
153
154
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
155
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
156
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
157
158
    subtest 'Correct call' => sub {
159
        plan tests => 4;
160
161
        Koha::CirculationRules->delete;
162
163
        lives_ok( sub {
164
            Koha::CirculationRules->set_rule( {
165
                branchcode => $branchcode,
166
                rule_name => 'lostreturn',
167
                rule_value => '',
168
            } );
169
        }, 'setting lostreturn with branch' );
170
171
        lives_ok( sub {
172
            Koha::CirculationRules->set_rule( {
173
                branchcode => $branchcode,
174
                categorycode => $categorycode,
175
                rule_name => 'patron_maxissueqty',
176
                rule_value => '',
177
            } );
178
        }, 'setting patron_maxissueqty with branch/category succeeds' );
179
180
        lives_ok( sub {
181
            Koha::CirculationRules->set_rule( {
182
                branchcode => $branchcode,
183
                itemtype => $itemtype,
184
                rule_name => 'holdallowed',
185
                rule_value => '',
186
            } );
187
        }, 'setting holdallowed with branch/itemtype succeeds' );
188
189
        lives_ok( sub {
190
            Koha::CirculationRules->set_rule( {
191
                branchcode => $branchcode,
192
                categorycode => $categorycode,
193
                itemtype => $itemtype,
194
                rule_name => 'fine',
195
                rule_value => '',
196
            } );
197
        }, 'setting fine with branch/category/itemtype succeeds' );
198
    };
199
200
    subtest 'Call with missing params' => sub {
201
        plan tests => 4;
202
203
        Koha::CirculationRules->delete;
204
205
        throws_ok( sub {
206
            Koha::CirculationRules->set_rule( {
207
                rule_name => 'lostreturn',
208
                rule_value => '',
209
            } );
210
        }, qr/branchcode/, 'setting lostreturn without branch fails' );
211
212
        throws_ok( sub {
213
            Koha::CirculationRules->set_rule( {
214
                branchcode => $branchcode,
215
                rule_name => 'patron_maxissueqty',
216
                rule_value => '',
217
            } );
218
        }, qr/categorycode/, 'setting patron_maxissueqty without categorycode fails' );
219
220
        throws_ok( sub {
221
            Koha::CirculationRules->set_rule( {
222
                branchcode => $branchcode,
223
                rule_name => 'holdallowed',
224
                rule_value => '',
225
            } );
226
        }, qr/itemtype/, 'setting holdallowed without itemtype fails' );
227
228
        throws_ok( sub {
229
            Koha::CirculationRules->set_rule( {
230
                branchcode => $branchcode,
231
                categorycode => $categorycode,
232
                rule_name => 'fine',
233
                rule_value => '',
234
            } );
235
        }, qr/itemtype/, 'setting fine without itemtype fails' );
236
    };
237
238
    subtest 'Call with extra params' => sub {
239
        plan tests => 3;
240
241
        Koha::CirculationRules->delete;
242
243
        throws_ok( sub {
244
            Koha::CirculationRules->set_rule( {
245
                branchcode => $branchcode,
246
                categorycode => $categorycode,
247
                rule_name => 'lostreturn',
248
                rule_value => '',
249
            } );
250
        }, qr/categorycode/, 'setting lostreturn with categorycode fails' );
251
252
        throws_ok( sub {
253
            Koha::CirculationRules->set_rule( {
254
                branchcode => $branchcode,
255
                categorycode => $categorycode,
256
                itemtype => $itemtype,
257
                rule_name => 'patron_maxissueqty',
258
                rule_value => '',
259
            } );
260
        }, qr/itemtype/, 'setting patron_maxissueqty with itemtype fails' );
261
262
        throws_ok( sub {
263
            Koha::CirculationRules->set_rule( {
264
                branchcode => $branchcode,
265
                rule_name => 'holdallowed',
266
                categorycode => $categorycode,
267
                itemtype => $itemtype,
268
                rule_value => '',
269
            } );
270
        }, qr/categorycode/, 'setting holdallowed with categorycode fails' );
271
    };
272
};
273
274
subtest 'clone' => sub {
275
    plan tests => 2;
276
277
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
278
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
279
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
280
281
    subtest 'Clone multiple rules' => sub {
282
        plan tests => 4;
283
284
        Koha::CirculationRules->delete;
285
286
        Koha::CirculationRule->new({
287
            branchcode   => undef,
288
            categorycode => $categorycode,
289
            itemtype     => $itemtype,
290
            rule_name    => 'fine',
291
            rule_value   => 5,
292
        })->store;
293
294
        Koha::CirculationRule->new({
295
            branchcode   => undef,
296
            categorycode => $categorycode,
297
            itemtype     => $itemtype,
298
            rule_name    => 'lengthunit',
299
            rule_value   => 'days',
300
        })->store;
301
302
        Koha::CirculationRules->search({ branchcode => undef })->clone($branchcode);
303
304
        my $rule_fine = Koha::CirculationRules->get_effective_rule({
305
            branchcode   => $branchcode,
306
            categorycode => $categorycode,
307
            itemtype     => $itemtype,
308
            rule_name    => 'fine',
309
        });
310
        my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({
311
            branchcode   => $branchcode,
312
            categorycode => $categorycode,
313
            itemtype     => $itemtype,
314
            rule_name    => 'lengthunit',
315
        });
316
317
        _is_row_match(
318
            $rule_fine,
319
            {
320
                branchcode   => $branchcode,
321
                categorycode => $categorycode,
322
                itemtype     => $itemtype,
323
                rule_name    => 'fine',
324
                rule_value   => 5,
325
            },
326
            'When I attempt to get cloned fine rule,'
327
           .' then the above one is returned.'
328
        );
329
        _is_row_match(
330
            $rule_lengthunit,
331
            {
332
                branchcode   => $branchcode,
333
                categorycode => $categorycode,
334
                itemtype     => $itemtype,
335
                rule_name    => 'lengthunit',
336
                rule_value   => 'days',
337
            },
338
            'When I attempt to get cloned lengthunit rule,'
339
           .' then the above one is returned.'
340
        );
341
342
    };
343
344
    subtest 'Clone one rule' => sub {
345
        plan tests => 2;
346
347
        Koha::CirculationRules->delete;
348
349
        Koha::CirculationRule->new({
350
            branchcode   => undef,
351
            categorycode => $categorycode,
352
            itemtype     => $itemtype,
353
            rule_name    => 'fine',
354
            rule_value   => 5,
355
        })->store;
356
357
        my $rule = Koha::CirculationRules->search({ branchcode => undef })->next;
358
        $rule->clone($branchcode);
359
360
        my $cloned_rule = Koha::CirculationRules->get_effective_rule({
361
            branchcode   => $branchcode,
362
            categorycode => $categorycode,
363
            itemtype     => $itemtype,
364
            rule_name    => 'fine',
365
        });
366
367
        _is_row_match(
368
            $cloned_rule,
369
            {
370
                branchcode   => $branchcode,
371
                categorycode => $categorycode,
372
                itemtype     => $itemtype,
373
                rule_name    => 'fine',
374
                rule_value   => '5',
375
            },
376
            'When I attempt to get cloned fine rule,'
377
           .' then the above one is returned.'
378
        );
379
380
    };
381
};
382
39
383
sub _is_row_match {
40
sub _is_row_match {
384
    my ( $rule, $expected, $message ) = @_;
41
    my ( $rule, $expected, $message ) = @_;
385
- 

Return to bug 29705