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