Bug 22721: Remove frameworkcode parameter in GetMarcFromKohaField calls
[koha-equinox.git] / t / db_dependent / Charset.t
1 use Modern::Perl;
2 use Test::More tests => 4;
3 use MARC::Record;
4
5 use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
6 use C4::Context;
7 use C4::Charset qw( SanitizeRecord );
8
9 use Koha::Database;
10
11 my $schema = Koha::Database->new->schema;
12 $schema->storage->txn_begin;
13 my $dbh = C4::Context->dbh;
14
15 my $frameworkcode = q||;
16
17 $dbh->do(q|
18     DELETE FROM marc_subfield_structure WHERE kohafield='biblioitems.url'
19 |);
20 $dbh->do(qq|
21     INSERT INTO marc_subfield_structure(frameworkcode,kohafield,tagfield,tagsubfield)
22     VALUES ('$frameworkcode', 'biblioitems.url', '856', 'u')
23 |);
24 my ( $url_field, $url_subfield ) = C4::Biblio::GetMarcFromKohaField( 'biblioitems.url' );
25
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 ),
33 );
34
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');
39
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 ),
46 );
47
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');