From beb6f6149031c713a73a717c5e72435260f59126 Mon Sep 17 00:00:00 2001 From: Hector Castro Date: Sat, 17 Oct 2015 11:15:29 -0600 Subject: [PATCH] Bug 13642 - Unit Test for Koha::Crosswalk::DublinCore.pm To test -Apply patches -porve t/db_dependent/DublinCore.t Sponsored-by: Universidad de El Salvador --- t/db_dependent/DublinCore.t | 293 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 t/db_dependent/DublinCore.t diff --git a/t/db_dependent/DublinCore.t b/t/db_dependent/DublinCore.t new file mode 100644 index 0000000..af8e557 --- /dev/null +++ b/t/db_dependent/DublinCore.t @@ -0,0 +1,293 @@ +#!/usr/bin/perl + +# +# This file is part of Koha. +# +# Copyright (C) 2015 Universidad de El Salvador, +# Facultad Multidisciplinaria Oriental +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . +# + +use Modern::Perl; + +use Test::More tests => 11; +use MARC::Record; + +BEGIN { + use_ok('Koha::Crosswalk::DublinCore'); +} + +## create a MARC::Record object. +my $record = MARC::Record->new(); +$record->leader('00000cam a2200000 i 4500'); +my $control_number = MARC::Field->new( '001', '55645069' ); +$record->append_fields($control_number); +my $date_time_transection = MARC::Field->new( '005', '20050131000000.0' ); +$record->append_fields($date_time_transection); +my $fixed_length = MARC::Field->new( '008', '040526t20042004nju b 001 0 eng d' ); +$record->append_fields($fixed_length); + +my $LCCN = MARC::Field->new( + '010','','', + a => '2004051516' + ); +$record->append_fields($LCCN); + +my $author = MARC::Field->new( + '100',1,'', + a => 'Logan, Robert K.', + d => '1939-' + ); +$record->append_fields($author); + +my $title = MARC::Field->new( + '245','1','4', + a => 'The alphabet effect /', + c => 'Robert K. Logan.' + ); +$record->append_fields($title); + +my $publisher = MARC::Field->new( + '260','','', + a => 'Cresskill, N.J. :', + b => 'Hampton Press,', + c => '[2004]' + ); +$record->append_fields($publisher); + +my $physical_escription = MARC::Field->new( + '300','','', + a => 'xiv, 265 pages :', + c => '24 cm' + ); +$record->append_fields($physical_escription); + +my $bibliography = MARC::Field->new( + '504','','', + a => 'Includes bibliographical references (pages 247-255) and indexes' + ); +$record->append_fields($bibliography); + +my $subject = MARC::Field->new( + '650','','0', + a => 'Alphabet', + x => 'History.' + ); +$record->append_fields($subject); + + ok( defined $record, 'Returned new()' ); + ok( $record->isa('MARC::Record'), "Right class for creating MARC records" ); + +#Koha::Crosswalk::DublinCore object for XML metadata +my $xml_dc_record = Koha::Crosswalk::DublinCore->new({ + type => 'xml', + qualified => 0, + get_marc_record => $record + }); + +#Koha::Crosswalk::DublinCore object for RDF metadata +my $rdf_dc_record = Koha::Crosswalk::DublinCore->new({ + type => 'rdf', + qualified => 0, + get_marc_record => $record, + }); + +#OAI-DC +my $test4 = qq( + + The alphabet effect / Robert K. Logan. + Logan, Robert K. 1939- + Alphabet History. + Includes bibliographical references (pages 247-255) and indexes + Cresskill, N.J. : Hampton Press, + Text + eng + +); + +#OAI-DC Data + $xml_dc_record->get_xml_data({ + root => 'oai_dc:dc', + xsi_schemaLocation => 'http://www.openarchives.org/OAI/2.0/oai_dc/' . + ' http://www.openarchives.org/OAI/2.0/oai_dc.xsd', + entities => 0, + opt_namespace => 'oai_dc', + opt_namespace_url => 'http://www.openarchives.org/OAI/2.0/oai_dc/' + }); + + is ($xml_dc_record->write_xml(), $test4, "testing OAI-DC"); + +#SRW-DC +my $test5 = qq( + + The alphabet effect / Robert K. Logan. + Logan, Robert K. 1939- + Alphabet History. + Includes bibliographical references (pages 247-255) and indexes + Cresskill, N.J. : Hampton Press, + Text + eng + +); + +# SRW-DC Data + $xml_dc_record->get_xml_data({ + root => 'srw_dc:dc', + xsi_schemaLocation => 'info:srw/schema/1/dc-schema' . + ' http://www.loc.gov/standards/sru/resources/dc-schema.xsd', + entities => 0, + opt_namespace => 'srw_dc', + opt_namespace_url => 'info:srw/schema/1/dc-schema' + }); + + is ($xml_dc_record->write_xml(), $test5, "testing SRW-DC"); + +#Simple RDF-DC + $rdf_dc_record->get_rdf_data({ + rdf_subject => 'http://opac.mydomain.edu/cgi-bin/koha/opac-detail.pl?biblionumber=#', + rdf_format => 'rdfxml', + entities => 0 + }); + +my $test6 = qq( + + +\tLogan, Robert K. 1939- +\tIncludes bibliographical references (pages 247-255) and indexes +\teng +\tCresskill, N.J. : Hampton Press, +\tAlphabet History. +\tThe alphabet effect / Robert K. Logan. +\tText + + +); + + is ($rdf_dc_record->write_rdf(), $test6, "testing Simple RDF-DC"); + +#RDF-DC (Recommendation)-rdfxml + +my $test7 = qq( + + +\t +\tText + + +\t +\tAlphabet History. + + +\t +\teng + + +\t[2004] +\tLogan, Robert K. 1939- +\tIncludes bibliographical references (pages 247-255) and indexes +\txiv, 265 pages : +\t2004 +\t[2004] +\t +\tCresskill, N.J. : Hampton Press, +\t +\tThe alphabet effect / Robert K. Logan. +\t + + +); + +$rdf_dc_record->qualified(1); + + is ($rdf_dc_record->write_rdf(), $test7, "testing RDF-DC (Recommendation)"); + +my $test8 = qq(\@prefix rdf: . +\@prefix dcterms: . +\@prefix dcam: . + +_:DCMIType dcam:memberOf dcterms:DCMIType ; +\trdf:value "Text" . +_:LCSH dcam:memberOf dcterms:LCSH ; +\trdf:value "Alphabet History." . +_:language dcam:memberOf dcterms:ISO639-2 ; +\trdf:value "eng" . + dcterms:created "[2004]" ; +\tdcterms:creator "Logan, Robert K. 1939-" ; +\tdcterms:description "Includes bibliographical references (pages 247-255) and indexes" ; +\tdcterms:extent "xiv, 265 pages :" ; +\tdcterms:issued "2004", "[2004]" ; +\tdcterms:language _:language ; +\tdcterms:publisher "Cresskill, N.J. : Hampton Press," ; +\tdcterms:subject _:LCSH ; +\tdcterms:title "The alphabet effect / Robert K. Logan." ; +\tdcterms:type _:DCMIType . +); + +$rdf_dc_record->rdf_format('turtle'); + + is ($rdf_dc_record->write_rdf(), $test8, "testing RDF-DC (Recommendation) in turtle format"); + +my $test9 = qq(_:DCMIType . +_:DCMIType "Text" . +_:LCSH . +_:LCSH "Alphabet History." . +_:language . +_:language "eng" . + "[2004]" . + "Logan, Robert K. 1939-" . + "Includes bibliographical references (pages 247-255) and indexes" . + "xiv, 265 pages :" . + "2004" . + "[2004]" . + _:language . + "Cresskill, N.J. : Hampton Press," . + _:LCSH . + "The alphabet effect / Robert K. Logan." . + _:DCMIType . +); + +$rdf_dc_record->rdf_format('nquads'); + + is ($rdf_dc_record->write_rdf(), $test9, "testing RDF-DC (Recommendation) in nquads format"); + +my $test10 = qq({"_:LCSH":{"http://www.w3.org/1999/02/22-rdf-syntax-ns#value":[{"value":"Alphabet History.","type":"literal"}],"http://purl.org/dc/dcam/memberOf":[{"value":"http://purl.org/dc/terms/LCSH","type":"uri"}]},"http://opac.mydomain.edu/cgi-bin/koha/opac-detail.pl?biblionumber=#":{"http://purl.org/dc/terms/title":[{"value":"The alphabet effect / Robert K. Logan.","type":"literal"}],"http://purl.org/dc/terms/issued":[{"value":"2004","type":"literal"},{"value":"[2004]","type":"literal"}],"http://purl.org/dc/terms/type":[{"value":"_:DCMIType","type":"bnode"}],"http://purl.org/dc/terms/subject":[{"value":"_:LCSH","type":"bnode"}],"http://purl.org/dc/terms/description":[{"value":"Includes bibliographical references (pages 247-255) and indexes","type":"literal"}],"http://purl.org/dc/terms/publisher":[{"value":"Cresskill, N.J. : Hampton Press,","type":"literal"}],"http://purl.org/dc/terms/creator":[{"value":"Logan, Robert K. 1939-","type":"literal"}],"http://purl.org/dc/terms/language":[{"value":"_:language","type":"bnode"}],"http://purl.org/dc/terms/extent":[{"value":"xiv, 265 pages :","type":"literal"}],"http://purl.org/dc/terms/created":[{"value":"[2004]","type":"literal"}]},"_:language":{"http://www.w3.org/1999/02/22-rdf-syntax-ns#value":[{"value":"eng","type":"literal"}],"http://purl.org/dc/dcam/memberOf":[{"value":"http://purl.org/dc/terms/ISO639-2","type":"uri"}]},"_:DCMIType":{"http://www.w3.org/1999/02/22-rdf-syntax-ns#value":[{"value":"Text","type":"literal"}],"http://purl.org/dc/dcam/memberOf":[{"value":"http://purl.org/dc/terms/DCMIType","type":"uri"}]}}); + +$rdf_dc_record->rdf_format('rdfjson'); + + is ($rdf_dc_record->write_rdf(), $test10, "testing RDF-DC (Recommendation) in rdfjson format"); + +my $test11 = qq(_:DCMIType . +_:DCMIType "Text" . +_:LCSH . +_:LCSH "Alphabet History." . +_:language . +_:language "eng" . + "[2004]" . + "Logan, Robert K. 1939-" . + "Includes bibliographical references (pages 247-255) and indexes" . + "xiv, 265 pages :" . + "2004" . + "[2004]" . + _:language . + "Cresskill, N.J. : Hampton Press," . + _:LCSH . + "The alphabet effect / Robert K. Logan." . + _:DCMIType . +); + +$rdf_dc_record->rdf_format('ntriples'); + + is ($rdf_dc_record->write_rdf(), $test11, "testing RDF-DC (Recommendation) in ntriples format"); + -- 1.7.10.4