2 use Test::More tests => 4;
5 use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
7 use C4::Charset qw( SanitizeRecord );
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
13 my $dbh = C4::Context->dbh;
15 my $frameworkcode = q||;
18 DELETE FROM marc_subfield_structure WHERE kohafield='biblioitems.url'
21 INSERT INTO marc_subfield_structure(frameworkcode,kohafield,tagfield,tagsubfield)
22 VALUES ('$frameworkcode', 'biblioitems.url', '856', 'u')
24 my ( $url_field, $url_subfield ) = C4::Biblio::GetMarcFromKohaField('biblioitems.url', $frameworkcode);
26 my $title = q|My title & a word & another word|;
27 my $url = q|http://www.example.org/index.pl?arg1=val1&arg2=val2|;
28 my $record = MARC::Record->new();
29 $record->append_fields(
30 MARC::Field->new('100', ' ', ' ', a => 'my author'),
31 MARC::Field->new('245', ' ', ' ', a => $title),
32 MARC::Field->new($url_field, ' ', ' ', $url_subfield => $url ),
35 my ($biblionumber, $biblioitemnumber) = AddBiblio($record, $frameworkcode);
36 my ( $sanitized_record, $has_been_modified ) = C4::Charset::SanitizeRecord( $record, $biblionumber );
37 is( $has_been_modified, 0, 'SanitizeRecord: the record has not been modified' );
38 is( $url, $sanitized_record->subfield($url_field, $url_subfield), 'SanitizeRecord: the url has not been modified');
40 $title = q|My title & a word & another word|;
41 $record = MARC::Record->new();
42 $record->append_fields(
43 MARC::Field->new('100', ' ', ' ', a => 'my author'),
44 MARC::Field->new('245', ' ', ' ', a => $title),
45 MARC::Field->new($url_field, ' ', ' ', $url_subfield => $url ),
48 ($biblionumber, $biblioitemnumber) = AddBiblio($record, $frameworkcode);
49 ( $sanitized_record, $has_been_modified ) = C4::Charset::SanitizeRecord( $record, $biblionumber );
50 is( $has_been_modified, 1, 'SanitizeRecord: the record has been modified' );
51 is( $url, $sanitized_record->subfield($url_field, $url_subfield), 'SanitizeRecord: the url has not been modified');