|
Lines 1606-1612
subtest 'BorrowersLog tests' => sub {
Link Here
|
| 1606 |
$schema->storage->txn_rollback; |
1606 |
$schema->storage->txn_rollback; |
| 1607 |
|
1607 |
|
| 1608 |
subtest 'Test Koha::Patrons::merge' => sub { |
1608 |
subtest 'Test Koha::Patrons::merge' => sub { |
| 1609 |
plan tests => 113; |
1609 |
plan tests => 110; |
| 1610 |
|
1610 |
|
| 1611 |
my $schema = Koha::Database->new()->schema(); |
1611 |
my $schema = Koha::Database->new()->schema(); |
| 1612 |
|
1612 |
|
|
Lines 1657-1662
subtest 'Test Koha::Patrons::merge' => sub {
Link Here
|
| 1657 |
is( $results, undef, "Anonymous patron cannot have other patrons merged into it" ); |
1657 |
is( $results, undef, "Anonymous patron cannot have other patrons merged into it" ); |
| 1658 |
is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" ); |
1658 |
is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" ); |
| 1659 |
|
1659 |
|
|
|
1660 |
subtest 'extended attributes' => sub { |
| 1661 |
plan tests => 5; |
| 1662 |
|
| 1663 |
my $keep_patron = |
| 1664 |
$builder->build_object( { class => 'Koha::Patrons' } ); |
| 1665 |
my $merge_patron = |
| 1666 |
$builder->build_object( { class => 'Koha::Patrons' } ); |
| 1667 |
|
| 1668 |
my $attribute_type_normal_1 = $builder->build_object( |
| 1669 |
{ |
| 1670 |
class => 'Koha::Patron::Attribute::Types', |
| 1671 |
value => { repeatable => 0, unique_id => 0 } |
| 1672 |
} |
| 1673 |
); |
| 1674 |
my $attribute_type_normal_2 = $builder->build_object( |
| 1675 |
{ |
| 1676 |
class => 'Koha::Patron::Attribute::Types', |
| 1677 |
value => { repeatable => 0, unique_id => 0 } |
| 1678 |
} |
| 1679 |
); |
| 1680 |
|
| 1681 |
my $attribute_type_repeatable = $builder->build_object( |
| 1682 |
{ |
| 1683 |
class => 'Koha::Patron::Attribute::Types', |
| 1684 |
value => { repeatable => 1, unique_id => 0 } |
| 1685 |
} |
| 1686 |
); |
| 1687 |
|
| 1688 |
my $attr_keep = [ |
| 1689 |
{ |
| 1690 |
code => $attribute_type_normal_1->code, |
| 1691 |
attribute => 'from attr 1' |
| 1692 |
}, |
| 1693 |
{ |
| 1694 |
code => $attribute_type_repeatable->code, |
| 1695 |
attribute => 'from attr repeatable' |
| 1696 |
} |
| 1697 |
]; |
| 1698 |
|
| 1699 |
my $attr_merge = [ |
| 1700 |
{ |
| 1701 |
code => $attribute_type_normal_2->code, |
| 1702 |
attribute => 'to attr 2' |
| 1703 |
}, |
| 1704 |
{ |
| 1705 |
code => $attribute_type_repeatable->code, |
| 1706 |
attribute => 'to attr repeatable' |
| 1707 |
}, |
| 1708 |
]; |
| 1709 |
|
| 1710 |
$keep_patron->extended_attributes($attr_keep); |
| 1711 |
$merge_patron->extended_attributes($attr_merge); |
| 1712 |
|
| 1713 |
$keep_patron->merge_with( [ $merge_patron->borrowernumber ] ); |
| 1714 |
my $merged_attributes = $keep_patron->extended_attributes; |
| 1715 |
is( $merged_attributes->count, 4 ); |
| 1716 |
|
| 1717 |
sub compare_attributes { |
| 1718 |
my ( $got, $expected, $code ) = @_; |
| 1719 |
|
| 1720 |
is_deeply( |
| 1721 |
[ |
| 1722 |
sort $got->search( { code => $code } ) |
| 1723 |
->get_column('attribute') |
| 1724 |
], |
| 1725 |
$expected |
| 1726 |
); |
| 1727 |
} |
| 1728 |
compare_attributes( |
| 1729 |
$merged_attributes, |
| 1730 |
['from attr 1'], |
| 1731 |
$attribute_type_normal_1->code |
| 1732 |
); |
| 1733 |
compare_attributes( |
| 1734 |
$merged_attributes, |
| 1735 |
['to attr 2'], |
| 1736 |
$attribute_type_normal_2->code |
| 1737 |
); |
| 1738 |
compare_attributes( |
| 1739 |
$merged_attributes, |
| 1740 |
[ 'from attr repeatable', 'to attr repeatable' ], |
| 1741 |
$attribute_type_repeatable->code |
| 1742 |
); |
| 1743 |
|
| 1744 |
# Cleanup |
| 1745 |
$keep_patron->delete; |
| 1746 |
$merge_patron->delete; |
| 1747 |
|
| 1748 |
# Recreate but expect an exception because 2 "normal" attributes will be in the resulting patron |
| 1749 |
$keep_patron = |
| 1750 |
$builder->build_object( { class => 'Koha::Patrons' } ); |
| 1751 |
$merge_patron = |
| 1752 |
$builder->build_object( { class => 'Koha::Patrons' } ); |
| 1753 |
|
| 1754 |
$keep_patron->extended_attributes($attr_keep); |
| 1755 |
$merge_patron->extended_attributes( |
| 1756 |
[ |
| 1757 |
@$attr_merge, |
| 1758 |
{ |
| 1759 |
code => $attribute_type_normal_1->code, |
| 1760 |
attribute => 'yet another attribute for non-repeatable' |
| 1761 |
} |
| 1762 |
] |
| 1763 |
); |
| 1764 |
|
| 1765 |
throws_ok { |
| 1766 |
$keep_patron->merge_with( [ $merge_patron->borrowernumber ] ); |
| 1767 |
} |
| 1768 |
'Koha::Exceptions::Patron::Attribute::NonRepeatable', |
| 1769 |
'Exception thrown trying to merge several non-repeatable attributes'; |
| 1770 |
}; |
| 1771 |
|
| 1660 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', '' ); |
1772 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', '' ); |
| 1661 |
$schema->storage->txn_rollback; |
1773 |
$schema->storage->txn_rollback; |
| 1662 |
}; |
1774 |
}; |
| 1663 |
- |
|
|