|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
| 23 |
use Test::Deep qw( cmp_methods ); |
23 |
use Test::Deep qw( cmp_methods ); |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
|
25 |
|
|
Lines 566-571
subtest 'set_rule' => sub {
Link Here
|
| 566 |
}; |
566 |
}; |
| 567 |
}; |
567 |
}; |
| 568 |
|
568 |
|
|
|
569 |
subtest 'clone' => sub { |
| 570 |
plan tests => 2; |
| 571 |
|
| 572 |
my $branchcode = $builder->build({ source => 'Branch' })->{'branchcode'}; |
| 573 |
my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'}; |
| 574 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{'itemtype'}; |
| 575 |
|
| 576 |
subtest 'Clone multiple rules' => sub { |
| 577 |
plan tests => 4; |
| 578 |
|
| 579 |
Koha::CirculationRules->delete; |
| 580 |
|
| 581 |
Koha::CirculationRule->new({ |
| 582 |
branchcode => undef, |
| 583 |
categorycode => $categorycode, |
| 584 |
itemtype => $itemtype, |
| 585 |
rule_name => 'fine', |
| 586 |
rule_value => 5, |
| 587 |
})->store; |
| 588 |
|
| 589 |
Koha::CirculationRule->new({ |
| 590 |
branchcode => undef, |
| 591 |
categorycode => $categorycode, |
| 592 |
itemtype => $itemtype, |
| 593 |
rule_name => 'lengthunit', |
| 594 |
rule_value => 'days', |
| 595 |
})->store; |
| 596 |
|
| 597 |
Koha::CirculationRules->search({ branchcode => undef })->clone($branchcode); |
| 598 |
|
| 599 |
my $rule_fine = Koha::CirculationRules->get_effective_rule({ |
| 600 |
branchcode => $branchcode, |
| 601 |
categorycode => $categorycode, |
| 602 |
itemtype => $itemtype, |
| 603 |
rule_name => 'fine', |
| 604 |
}); |
| 605 |
my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({ |
| 606 |
branchcode => $branchcode, |
| 607 |
categorycode => $categorycode, |
| 608 |
itemtype => $itemtype, |
| 609 |
rule_name => 'lengthunit', |
| 610 |
}); |
| 611 |
|
| 612 |
_is_row_match( |
| 613 |
$rule_fine, |
| 614 |
{ |
| 615 |
branchcode => $branchcode, |
| 616 |
categorycode => $categorycode, |
| 617 |
itemtype => $itemtype, |
| 618 |
rule_name => 'fine', |
| 619 |
rule_value => 5, |
| 620 |
}, |
| 621 |
'When I attempt to get cloned fine rule,' |
| 622 |
.' then the above one is returned.' |
| 623 |
); |
| 624 |
_is_row_match( |
| 625 |
$rule_lengthunit, |
| 626 |
{ |
| 627 |
branchcode => $branchcode, |
| 628 |
categorycode => $categorycode, |
| 629 |
itemtype => $itemtype, |
| 630 |
rule_name => 'lengthunit', |
| 631 |
rule_value => 'days', |
| 632 |
}, |
| 633 |
'When I attempt to get cloned lengthunit rule,' |
| 634 |
.' then the above one is returned.' |
| 635 |
); |
| 636 |
|
| 637 |
}; |
| 638 |
|
| 639 |
subtest 'Clone one rule' => sub { |
| 640 |
plan tests => 2; |
| 641 |
|
| 642 |
Koha::CirculationRules->delete; |
| 643 |
|
| 644 |
Koha::CirculationRule->new({ |
| 645 |
branchcode => undef, |
| 646 |
categorycode => $categorycode, |
| 647 |
itemtype => $itemtype, |
| 648 |
rule_name => 'fine', |
| 649 |
rule_value => 5, |
| 650 |
})->store; |
| 651 |
|
| 652 |
my $rule = Koha::CirculationRules->search({ branchcode => undef })->next; |
| 653 |
$rule->clone($branchcode); |
| 654 |
|
| 655 |
my $cloned_rule = Koha::CirculationRules->get_effective_rule({ |
| 656 |
branchcode => $branchcode, |
| 657 |
categorycode => $categorycode, |
| 658 |
itemtype => $itemtype, |
| 659 |
rule_name => 'fine', |
| 660 |
}); |
| 661 |
|
| 662 |
_is_row_match( |
| 663 |
$cloned_rule, |
| 664 |
{ |
| 665 |
branchcode => $branchcode, |
| 666 |
categorycode => $categorycode, |
| 667 |
itemtype => $itemtype, |
| 668 |
rule_name => 'fine', |
| 669 |
rule_value => '5', |
| 670 |
}, |
| 671 |
'When I attempt to get cloned fine rule,' |
| 672 |
.' then the above one is returned.' |
| 673 |
); |
| 674 |
|
| 675 |
}; |
| 676 |
}; |
| 677 |
|
| 569 |
sub _is_row_match { |
678 |
sub _is_row_match { |
| 570 |
my ( $rule, $expected, $message ) = @_; |
679 |
my ( $rule, $expected, $message ) = @_; |
| 571 |
|
680 |
|
| 572 |
- |
|
|