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

(-)a/t/Koha_MetadataRecord.t (-4 / +52 lines)
Lines 17-26 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use Test::More tests => 4;
22
use Test::More tests => 5;
23
use Test::Warn;
24
24
25
BEGIN {
25
BEGIN {
26
        use_ok('Koha::MetadataRecord');
26
        use_ok('Koha::MetadataRecord');
Lines 96-98 foreach my $field (@$hash) { Link Here
96
is_deeply($hash, $samplehash, 'Generated hash correctly');
96
is_deeply($hash, $samplehash, 'Generated hash correctly');
97
my $dupkeys = grep { $_ > 1 } values %fieldkeys;
97
my $dupkeys = grep { $_ > 1 } values %fieldkeys;
98
is($dupkeys, 0, 'No duplicate keys');
98
is($dupkeys, 0, 'No duplicate keys');
99
- 
99
100
101
subtest "new() tests" => sub {
102
103
    plan tests => 12;
104
105
    # Test default values with a MARC::Record record
106
    my $record = MARC::Record->new();
107
    my $metadata_record = new Koha::MetadataRecord({
108
        record => $record
109
    });
110
111
    is( ref($metadata_record), 'Koha::MetadataRecord', 'Type correct');
112
    is( ref($metadata_record->record), 'MARC::Record', 'Record type preserved');
113
    is( $metadata_record->schema, 'marc21', 'Metadata schema defaults to marc21');
114
    is( $metadata_record->format, 'marc', 'Serializacion format defaults to marc');
115
    is( $metadata_record->id, undef, 'id is optional, undef if unspecifid');
116
117
    # Test passed values, also no constraint on record type
118
    my $weird_record = {};
119
    bless $weird_record, 'Weird::Class';
120
121
    $metadata_record = new Koha::MetadataRecord({
122
        record => $weird_record,
123
        schema => 'something',
124
        format => 'else',
125
        id     => 'an id'
126
    });
127
128
    is( ref($metadata_record), 'Koha::MetadataRecord', 'Type correct');
129
    is( ref($metadata_record->record), 'Weird::Class', 'Record type preserved');
130
    is( $metadata_record->schema, 'something', 'Metadata schema correctly set');
131
    is( $metadata_record->format, 'else', 'Serializacion format correctly set');
132
    is( $metadata_record->id, 'an id', 'The id correctly set');
133
134
    # Having a record object is mandatory
135
    warning_is { $metadata_record = new Koha::MetadataRecord({
136
                                        record => undef,
137
                                        schema => 'something',
138
                                        format => 'else',
139
                                        id     => 'an id'
140
                                    }) }
141
                { carped => 'No record passed' },
142
                'Undefined record raises carped warning';
143
144
    is( $metadata_record, undef, 'record object mandatory')
145
};
146
147
1;

Return to bug 14639