"Fossies" - the Fresh Open Source Software Archive

Member "eprints3.4-3.4.4/tests/70_xml_import.pl" (7 Aug 2022, 9625 Bytes) of package /linux/www/eprints3.4-3.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "70_xml_import.pl": 3.4-3.4.3_vs_3.4-3.4.4.

    1 =head1 NAME
    2 
    3 MyHander
    4 
    5 =cut
    6 
    7 use strict;
    8 use Test::More tests => 9;
    9 
   10 BEGIN { use_ok( "EPrints" ); }
   11 BEGIN { use_ok( "EPrints::Test" ); }
   12 
   13 my $session = EPrints::Test::get_test_session( 0 );
   14 ok(defined $session, 'opened an EPrints::Session object (noisy, no_check_db)');
   15 
   16 {
   17 package MyHander;
   18 
   19 sub new { bless {}, shift; }
   20 
   21 sub message
   22 {
   23     my( $self, $type, $xml ) = @_;
   24 
   25     my $mess = EPrints::XML::to_string( $xml );
   26     EPrints::XML::dispose( $xml );
   27 
   28     push @{$self->{$type}||=[]}, $mess;
   29 }
   30 }
   31 
   32 my $doc = EPrints::XML::parse_xml_string( join "", <DATA> );
   33 my( $eprint_xml ) = $doc->documentElement->getElementsByTagName( "eprint" );
   34 
   35 my $handler = MyHander->new;
   36 my $epdata = EPrints::DataObj::EPrint->xml_to_epdata( $session, $eprint_xml, Handler => $handler );
   37 
   38 is( $epdata->{title}, "Fulvous Whistling Ducks and Man", "Parsed title" );
   39 is( $epdata->{creators}->[0]->{name}->{family}, "Toda", "Parsed 1st creator" );
   40 
   41 my %warnings = (
   42     bad_field => 0,
   43     bad_document => 0,
   44     bad_item => 0,
   45     bad_name_part => 0
   46     );
   47 foreach my $warning (@{$handler->{warning}})
   48 {
   49     while(my( $key, $value ) = each %warnings)
   50     {
   51         $warnings{$key} = 1 if $warning =~ /$key/;
   52     }
   53 }
   54 
   55 foreach my $test (sort keys %warnings)
   56 {
   57     ok( $warnings{$test}, "Invalid XML element: $test" );
   58 }
   59 
   60 EPrints::XML::dispose( $doc );
   61 
   62 $session->terminate;
   63 
   64 
   65 =head1 COPYRIGHT
   66 
   67 =for COPYRIGHT BEGIN
   68 
   69 Copyright 2022 University of Southampton.
   70 EPrints 3.4 is supplied by EPrints Services.
   71 
   72 http://www.eprints.org/eprints-3.4/
   73 
   74 =for COPYRIGHT END
   75 
   76 =for LICENSE BEGIN
   77 
   78 This file is part of EPrints 3.4 L<http://www.eprints.org/>.
   79 
   80 EPrints 3.4 and this file are released under the terms of the
   81 GNU Lesser General Public License version 3 as published by
   82 the Free Software Foundation unless otherwise stated.
   83 
   84 EPrints 3.4 is distributed in the hope that it will be useful,
   85 but WITHOUT ANY WARRANTY; without even the implied warranty of
   86 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   87 See the GNU Lesser General Public License for more details.
   88 
   89 You should have received a copy of the GNU Lesser General Public
   90 License along with EPrints 3.4.
   91 If not, see L<http://www.gnu.org/licenses/>.
   92 
   93 =for LICENSE END
   94 
   95 =cut
   96 
   97 __DATA__
   98 <?xml version="1.0" encoding="utf-8" ?>
   99 <eprints xmlns="http://eprints.org/ep2/data/2.0">
  100   <eprint id="http://yomiko.ecs.soton.ac.uk:8080/id/eprint/100" xmlns="http://eprints.org/ep2/data/2.0">
  101     <eprintid>100</eprintid>
  102     <rev_number>2</rev_number>
  103     <bad_field>asdasdasd</bad_field>
  104     <documents>
  105       <bad_document></bad_document>
  106       <document id="http://yomiko.ecs.soton.ac.uk:8080/id/document/671">
  107         <docid>671</docid>
  108         <rev_number>3</rev_number>
  109         <files>
  110           <file id="http://yomiko.ecs.soton.ac.uk:8080/id/file/980">
  111             <fileid>980</fileid>
  112             <datasetid>document</datasetid>
  113             <objectid>671</objectid>
  114             <filename>indexcodes.txt</filename>
  115             <mime_type>text/plain</mime_type>
  116             <hash>a39762b923e9d4b815eabda0e344f53a</hash>
  117             <hash_type>MD5</hash_type>
  118             <filesize>103</filesize>
  119             <mtime>2009-06-09 08:15:24</mtime>
  120             <url>http://yomiko.ecs.soton.ac.uk:8080/100/3/indexcodes.txt</url>
  121             <copies>
  122               <item>
  123                 <pluginid>Storage::Local</pluginid>
  124                 <sourceid>indexcodes.txt</sourceid>
  125               </item>
  126             </copies>
  127           </file>
  128         </files>
  129         <eprintid>100</eprintid>
  130         <pos>3</pos>
  131         <placement>3</placement>
  132         <format>indexcodes</format>
  133         <formatdesc>Generate index codes conversion from application/pdf to indexcodes</formatdesc>
  134         <language>en</language>
  135         <security>public</security>
  136         <main>indexcodes.txt</main>
  137         <relation>
  138           <item>
  139             <type>http://eprints.org/relation/isVersionOf</type>
  140             <uri>_internal:document.230</uri>
  141           </item>
  142           <item>
  143             <type>http://eprints.org/relation/isVolatileVersionOf</type>
  144             <uri>_internal:document.230</uri>
  145           </item>
  146           <item>
  147             <type>http://eprints.org/relation/isIndexCodesVersionOf</type>
  148             <uri>_internal:document.230</uri>
  149           </item>
  150         </relation>
  151       </document>
  152       <document id="http://yomiko.ecs.soton.ac.uk:8080/id/document/231">
  153         <docid>231</docid>
  154         <rev_number>3</rev_number>
  155         <files>
  156           <file id="http://yomiko.ecs.soton.ac.uk:8080/id/file/361">
  157             <fileid>361</fileid>
  158             <datasetid>document</datasetid>
  159             <objectid>231</objectid>
  160             <filename>preview.jpg</filename>
  161             <mime_type>image/jpeg</mime_type>
  162             <hash>0f66da4ed2a17be8c3e9fea227bf8137</hash>
  163             <hash_type>MD5</hash_type>
  164             <filesize>9227</filesize>
  165             <mtime>2009-06-05 11:46:56</mtime>
  166             <url>http://yomiko.ecs.soton.ac.uk:8080/100/2/preview.jpg</url>
  167             <copies>
  168               <item>
  169                 <pluginid>Storage::Local</pluginid>
  170                 <sourceid>preview.jpg</sourceid>
  171               </item>
  172             </copies>
  173           </file>
  174         </files>
  175         <eprintid>100</eprintid>
  176         <pos>2</pos>
  177         <placement>2</placement>
  178         <format>image/jpeg</format>
  179         <formatdesc>Thumbnail Documents conversion from application/pdf to thumbnail_preview</formatdesc>
  180         <language>en</language>
  181         <security>public</security>
  182         <main>preview.jpg</main>
  183         <relation>
  184           <item>
  185             <type>http://eprints.org/relation/isVersionOf</type>
  186             <uri>_internal:document.230</uri>
  187           </item>
  188           <item>
  189             <type>http://eprints.org/relation/isVolatileVersionOf</type>
  190             <uri>_internal:document.230</uri>
  191           </item>
  192           <item>
  193             <type>http://eprints.org/relation/ispreviewThumbnailVersionOf</type>
  194             <uri>_internal:document.230</uri>
  195           </item>
  196         </relation>
  197       </document>
  198       <document id="http://yomiko.ecs.soton.ac.uk:8080/id/document/230">
  199         <docid>230</docid>
  200         <rev_number>3</rev_number>
  201         <files>
  202           <file id="http://yomiko.ecs.soton.ac.uk:8080/id/file/360">
  203             <fileid>360</fileid>
  204             <datasetid>document</datasetid>
  205             <objectid>230</objectid>
  206             <filename>paper.pdf</filename>
  207             <mime_type>application/pdf</mime_type>
  208             <hash>8628e41b6818f896a8e011d9ac31aae1</hash>
  209             <hash_type>MD5</hash_type>
  210             <filesize>12174</filesize>
  211             <mtime>2009-06-05 11:46:55</mtime>
  212             <url>http://yomiko.ecs.soton.ac.uk:8080/100/1/paper.pdf</url>
  213             <copies>
  214               <item>
  215                 <pluginid>Storage::Local</pluginid>
  216                 <sourceid>paper.pdf</sourceid>
  217               </item>
  218             </copies>
  219           </file>
  220         </files>
  221         <eprintid>100</eprintid>
  222         <pos>1</pos>
  223         <placement>1</placement>
  224         <format>application/pdf</format>
  225         <language>en</language>
  226         <security>public</security>
  227         <main>paper.pdf</main>
  228         <relation>
  229           <item>
  230             <type>http://eprints.org/relation/hasVolatileVersion</type>
  231             <uri>_internal:document.231</uri>
  232           </item>
  233           <item>
  234             <type>http://eprints.org/relation/hasVersion</type>
  235             <uri>_internal:document.231</uri>
  236           </item>
  237           <item>
  238             <type>http://eprints.org/relation/haspreviewThumbnailVersion</type>
  239             <uri>_internal:document.231</uri>
  240           </item>
  241           <item>
  242             <type>http://eprints.org/relation/hasVolatileVersion</type>
  243             <uri>_internal:document.671</uri>
  244           </item>
  245           <item>
  246             <type>http://eprints.org/relation/hasVersion</type>
  247             <uri>_internal:document.671</uri>
  248           </item>
  249           <item>
  250             <type>http://eprints.org/relation/hasIndexCodesVersion</type>
  251             <uri>_internal:document.671</uri>
  252           </item>
  253         </relation>
  254       </document>
  255     </documents>
  256     <eprint_status>archive</eprint_status>
  257     <userid>1</userid>
  258     <dir>disk0/00/00/01/00</dir>
  259     <datestamp>2009-06-05 11:46:55</datestamp>
  260     <lastmod>2009-06-05 11:46:55</lastmod>
  261     <status_changed>2009-06-05 11:46:55</status_changed>
  262     <type>conference_item</type>
  263     <metadata_visibility>show</metadata_visibility>
  264     <item_issues_count>0</item_issues_count>
  265     <creators>
  266       <bad_item>asdasd</bad_item>
  267       <item>
  268         <name>
  269           <family>Toda</family>
  270           <given>Y.</given>
  271           <bad_name_part>XXX</bad_name_part>
  272         </name>
  273         <id></id>
  274       </item>
  275       <item>
  276         <name>
  277           <family>Aφροδίτη</family>
  278           <given>O.</given>
  279         </name>
  280         <id></id>
  281       </item>
  282       <item>
  283         <name>
  284           <family>Ερμής</family>
  285           <given>C.</given>
  286         </name>
  287         <id></id>
  288       </item>
  289     </creators>
  290     <title>Fulvous Whistling Ducks and Man</title>
  291     <ispublished>pub</ispublished>
  292     <subjects>
  293       <item>CS</item>
  294       <item>GA</item>
  295       <item>ZA4050</item>
  296       <item>QH</item>
  297     </subjects>
  298     <full_text_status>public</full_text_status>
  299     <pres_type>paper</pres_type>
  300     <abstract>This is where the abstract of this record would appear. This is only demonstration data.</abstract>
  301     <date>2005</date>
  302     <event_title>Animal Data Conference</event_title>
  303     <event_location>London</event_location>
  304     <event_dates>23-25 November</event_dates>
  305   </eprint>
  306 </eprints>