Changeset 361 for trunk/t/21_rdf.t
- Timestamp:
- 06/07/04 21:39:35 (5 years ago)
- Files:
-
- 1 modified
-
trunk/t/21_rdf.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/t/21_rdf.t
r324 r361 1 use CGI::Wiki::TestConfig::Utilities; 2 use CGI::Wiki; 3 use CGI::Wiki::Formatter::UseMod; 1 use CGI::Wiki::Setup::SQLite; 4 2 use Config::Tiny; 3 use OpenGuides::RDF; 4 use OpenGuides::Utils; 5 5 use URI::Escape; 6 use Test::More tests => 22; 6 7 7 use Test::More tests => 8 (1 + 22 * $CGI::Wiki::TestConfig::Utilities::num_stores);8 eval { require DBD::SQLite; }; 9 my $have_sqlite = $@ ? 0 : 1; 9 10 10 use_ok( "OpenGuides::RDF" ); 11 SKIP: { 12 skip "DBD::SQLite not installed - no database to test with", 22 13 unless $have_sqlite; 11 14 12 my %stores = CGI::Wiki::TestConfig::Utilities->stores; 15 CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } ); 16 my $config = Config::Tiny->new; 17 $config->{_} = { 18 dbtype => "sqlite", 19 dbname => "t/node.db", 20 indexing_directory => "t/indexes", 21 script_url => "http://wiki.example.com/", 22 script_name => "mywiki.cgi", 23 site_name => "CGI::Wiki Test Site", 24 default_city => "London", 25 default_country => "United Kingdom", 26 }; 13 27 14 my ($store_name, $store); 15 while ( ($store_name, $store) = each %stores ) { 16 SKIP: { 17 skip "$store_name storage backend not configured for testing", 22 18 unless $store; 28 my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 19 29 20 print "#\n##### TEST CONFIG: Store: $store_name\n#\n"; 30 # Clear out the database from any previous runs. 31 foreach my $del_node ( $wiki->list_all_nodes ) { 32 $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; 33 } 21 34 22 my $wiki = CGI::Wiki->new(23 store => $store,24 formatter => CGI::Wiki::Formatter::UseMod->new( munge_urls => 1 ),25 );26 my $config = Config::Tiny->read( "t/21_wiki.conf" );35 my $rdf_writer = eval { 36 OpenGuides::RDF->new( wiki => $wiki, config => $config ); 37 }; 38 is( $@, "", "'new' doesn't croak if wiki and config objects supplied" ); 39 isa_ok( $rdf_writer, "OpenGuides::RDF" ); 27 40 28 my $rdf_writer = eval { 29 OpenGuides::RDF->new( wiki => $wiki, 30 config => $config 31 ); 32 }; 33 is( $@, "", 34 "'new' doesn't croak if wiki and config objects supplied" 35 ); 36 isa_ok( $rdf_writer, "OpenGuides::RDF" ); 41 # Test the data for a node that exists. 42 $wiki->write_node( "Calthorpe Arms", 43 "CAMRA-approved pub near King's Cross", 44 undef, 45 { 46 comment => "Stub page, please update!", 47 username => "Kake", 48 postcode => "WC1X 8JR", 49 locale => [ "Bloomsbury", "St Pancras" ], 50 phone => "test phone number", 51 website => "test website", 52 opening_hours_text => "test hours", 53 latitude => "51.524193", 54 longitude => "-0.114436" 55 } 56 ); 37 57 38 # Test the data for a node that exists. 39 my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); 58 my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); 40 59 41 like( $rdfxml, qr|<\?xml version="1.0"\?>|, 42 "RDF is encoding-neutral" ); 60 like( $rdfxml, qr|<\?xml version="1.0"\?>|, "RDF is encoding-neutral" ); 43 61 44 like( $rdfxml, qr|<wn:Neighborhood>Bloomsbury</wn:Neighborhood>|,45 "finds the first locale" );46 like( $rdfxml, qr|<wn:Neighborhood>St Pancras</wn:Neighborhood>|,47 "finds the second locale" );62 like( $rdfxml, qr|<wn:Neighborhood>Bloomsbury</wn:Neighborhood>|, 63 "finds the first locale" ); 64 like( $rdfxml, qr|<wn:Neighborhood>St Pancras</wn:Neighborhood>|, 65 "finds the second locale" ); 48 66 49 like( $rdfxml, qr|<phone>test phone number</phone>|,50 "picks up phone number" );67 like( $rdfxml, qr|<phone>test phone number</phone>|, 68 "picks up phone number" ); 51 69 52 like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|,53 "picks up opening hours text" );70 like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|, 71 "picks up opening hours text" ); 54 72 55 like( $rdfxml, qr|<homePage>test website</homePage>|, 56 "picks up website" ); 73 like( $rdfxml, qr|<homePage>test website</homePage>|, "picks up website" ); 57 74 58 like( $rdfxml,59 qr|<dc:title>CGI::Wiki Test Site: Calthorpe Arms</dc:title>|,60 "sets the title correctly" );75 like( $rdfxml, 76 qr|<dc:title>CGI::Wiki Test Site: Calthorpe Arms</dc:title>|, 77 "sets the title correctly" ); 61 78 62 like( $rdfxml, qr|<dc:contributor>Kake</dc:contributor>|,63 "last username to edit used as contributor" );79 like( $rdfxml, qr|<dc:contributor>Kake</dc:contributor>|, 80 "last username to edit used as contributor" ); 64 81 65 like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );82 like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" ); 66 83 67 like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" ); 84 like( $rdfxml, qr|<rdf:Description rdf:about="">|, 85 "sets the 'about' correctly" ); 68 86 69 like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?id=Calthorpe_Arms" />|,70 "set the dc:source with the version-independent uri" );87 like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?id=Calthorpe_Arms" />|, 88 "set the dc:source with the version-independent uri" ); 71 89 72 like( $rdfxml, qr|<country>United Kingdom</country>|, 73 "default country picked up" ). 74 like( $rdfxml, qr|<city>London</city>|, 75 "default city picked up" ). 76 like( $rdfxml, qr|<postalCode>WC1X 8JR</postalCode>|, 77 "postcode picked up" ); 78 like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, 79 "latitude picked up" ); 80 like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, 81 "longitude picked up" ); 90 like( $rdfxml, qr|<country>United Kingdom</country>|, "country" ). 91 like( $rdfxml, qr|<city>London</city>|, "city" ). 92 like( $rdfxml, qr|<postalCode>WC1X 8JR</postalCode>|, "postcode" ); 93 like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, "latitude" ); 94 like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, "longitude" ); 82 95 83 like( $rdfxml, qr|<dc:date>|, "date element included" );84 unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );96 like( $rdfxml, qr|<dc:date>|, "date element included" ); 97 unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" ); 85 98 99 # Now test that there's a nice failsafe where a node doesn't exist. 100 $rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); }; 101 is( $@, "", 102 "->emit_rdfxml doesn't die when called on a nonexistent node" ); 86 103 87 # Now test that there's a nice failsafe where a node doesn't exist. 88 $rdfxml = eval { 89 $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); 90 }; 91 is( $@, "", 92 "->emit_rdfxml doesn't die when called on a nonexistent node" ); 93 94 like( $rdfxml, qr|<wiki:version>0</wiki:version>|, 95 "...and wiki:version is 0" ); 96 97 #print $rdfxml; 98 } 104 like( $rdfxml, qr|<wiki:version>0</wiki:version>|, 105 "...and wiki:version is 0" ); 99 106 }
