Lines 1024-1035
subtest 'extended_attributes' => sub {
Link Here
|
1024 |
|
1024 |
|
1025 |
subtest 'globally mandatory attributes tests' => sub { |
1025 |
subtest 'globally mandatory attributes tests' => sub { |
1026 |
|
1026 |
|
1027 |
plan tests => 5; |
1027 |
plan tests => 8; |
1028 |
|
1028 |
|
1029 |
$schema->storage->txn_begin; |
1029 |
$schema->storage->txn_begin; |
1030 |
Koha::Patron::Attribute::Types->search->delete; |
1030 |
Koha::Patron::Attribute::Types->search->delete; |
1031 |
|
1031 |
|
1032 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1032 |
my $context = Test::MockModule->new('C4::Context'); |
|
|
1033 |
|
1034 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1033 |
|
1035 |
|
1034 |
my $attribute_type_1 = $builder->build_object( |
1036 |
my $attribute_type_1 = $builder->build_object( |
1035 |
{ |
1037 |
{ |
Lines 1045-1061
subtest 'extended_attributes' => sub {
Link Here
|
1045 |
} |
1047 |
} |
1046 |
); |
1048 |
); |
1047 |
|
1049 |
|
1048 |
is( $patron->extended_attributes->count, 0, 'Patron has no extended attributes' ); |
1050 |
my $attribute_type_3 = $builder->build_object( |
|
|
1051 |
{ |
1052 |
class => 'Koha::Patron::Attribute::Types', |
1053 |
value => { mandatory => 1, class => 'a', category_code => undef, opac_editable => 1 } |
1054 |
} |
1055 |
); |
1049 |
|
1056 |
|
1050 |
throws_ok |
1057 |
my $attribute_type_4 = $builder->build_object( |
1051 |
{ |
1058 |
{ |
1052 |
$patron->extended_attributes( |
1059 |
class => 'Koha::Patron::Attribute::Types', |
1053 |
[ |
1060 |
value => { mandatory => 0, class => 'a', category_code => undef, opac_editable => 1 } |
1054 |
{ code => $attribute_type_2->code, attribute => 'b' } |
|
|
1055 |
] |
1056 |
); |
1057 |
} |
1061 |
} |
1058 |
'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute', |
1062 |
); |
|
|
1063 |
|
1064 |
#Staff interface tests |
1065 |
$context->mock( 'interface', sub { return "intranet" } ); |
1066 |
is( $patron->extended_attributes->count, 0, 'Patron has no extended attributes' ); |
1067 |
|
1068 |
throws_ok { |
1069 |
$patron->extended_attributes( |
1070 |
[ |
1071 |
{ code => $attribute_type_2->code, attribute => 'b' }, |
1072 |
{ code => $attribute_type_3->code, attribute => 'b' }, |
1073 |
] |
1074 |
); |
1075 |
} |
1076 |
'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute', |
1059 |
'Exception thrown on missing mandatory attribute type'; |
1077 |
'Exception thrown on missing mandatory attribute type'; |
1060 |
|
1078 |
|
1061 |
is( $@->type, $attribute_type_1->code, 'Exception parameters are correct' ); |
1079 |
is( $@->type, $attribute_type_1->code, 'Exception parameters are correct' ); |
Lines 1064-1074
subtest 'extended_attributes' => sub {
Link Here
|
1064 |
|
1082 |
|
1065 |
$patron->extended_attributes( |
1083 |
$patron->extended_attributes( |
1066 |
[ |
1084 |
[ |
1067 |
{ code => $attribute_type_1->code, attribute => 'b' } |
1085 |
{ code => $attribute_type_1->code, attribute => 'b' }, |
|
|
1086 |
{ code => $attribute_type_3->code, attribute => 'b' }, |
1068 |
] |
1087 |
] |
1069 |
); |
1088 |
); |
1070 |
|
1089 |
|
1071 |
is( $patron->extended_attributes->count, 1, 'Extended attributes succeeded' ); |
1090 |
is( $patron->extended_attributes->count, 2, 'Extended attributes succeeded' ); |
|
|
1091 |
|
1092 |
# OPAC interface tests |
1093 |
$context->mock( 'interface', sub { return "opac" } ); |
1094 |
|
1095 |
is( $patron->extended_attributes->count, 2, 'Patron still has 2 extended attributes in OPAC' ); |
1096 |
|
1097 |
throws_ok { |
1098 |
$patron->extended_attributes( |
1099 |
[ |
1100 |
{ code => $attribute_type_1->code, attribute => 'b' }, |
1101 |
{ code => $attribute_type_2->code, attribute => 'b' }, |
1102 |
] |
1103 |
); |
1104 |
} |
1105 |
'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute', |
1106 |
'Exception thrown on missing mandatory OPAC-editable attribute'; |
1107 |
|
1108 |
is( $@->type, $attribute_type_3->code, 'Exception parameters are correct for OPAC-editable attribute' ); |
1072 |
|
1109 |
|
1073 |
$schema->storage->txn_rollback; |
1110 |
$schema->storage->txn_rollback; |
1074 |
|
1111 |
|
1075 |
- |
|
|