| 1 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 2 | use OpenGuides; |
|---|
| 3 | use OpenGuides::Config; |
|---|
| 4 | use OpenGuides::RDF; |
|---|
| 5 | use OpenGuides::Utils; |
|---|
| 6 | use OpenGuides::Test; |
|---|
| 7 | use URI::Escape; |
|---|
| 8 | use Test::More; |
|---|
| 9 | |
|---|
| 10 | eval { require DBD::SQLite; }; |
|---|
| 11 | my $have_sqlite = $@ ? 0 : 1; |
|---|
| 12 | |
|---|
| 13 | if ( $@ ) { |
|---|
| 14 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 15 | plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | plan tests => 30; |
|---|
| 19 | |
|---|
| 20 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 21 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 22 | $config->script_url( "http://wiki.example.com/" ); |
|---|
| 23 | $config->script_name( "mywiki.cgi" ); |
|---|
| 24 | $config->site_name( "Wiki::Toolkit Test Site" ); |
|---|
| 25 | $config->default_city( "London" ); |
|---|
| 26 | $config->default_country( "United Kingdom" ); |
|---|
| 27 | $config->geo_handler( 3 ); |
|---|
| 28 | |
|---|
| 29 | eval { require Wiki::Toolkit::Search::Plucene; }; |
|---|
| 30 | if ( $@ ) { $config->use_plucene ( 0 ) }; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 34 | my $wiki = $guide->wiki; |
|---|
| 35 | |
|---|
| 36 | # Clear out the database from any previous runs. |
|---|
| 37 | foreach my $del_node ( $wiki->list_all_nodes ) { |
|---|
| 38 | $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | my $rdf_writer = eval { |
|---|
| 42 | OpenGuides::RDF->new( wiki => $wiki, config => $config ); |
|---|
| 43 | }; |
|---|
| 44 | is( $@, "", "'new' doesn't croak if wiki and config objects supplied" ); |
|---|
| 45 | isa_ok( $rdf_writer, "OpenGuides::RDF" ); |
|---|
| 46 | |
|---|
| 47 | # Test the data for a node that exists. |
|---|
| 48 | OpenGuides::Test->write_data( |
|---|
| 49 | guide => $guide, |
|---|
| 50 | node => "Calthorpe Arms", |
|---|
| 51 | content => "CAMRA-approved pub near King's Cross", |
|---|
| 52 | comment => "Stub page, please update!", |
|---|
| 53 | username => "Anonymous", |
|---|
| 54 | postcode => "WC1X 8JR", |
|---|
| 55 | locales => "Bloomsbury\r\nSt Pancras", |
|---|
| 56 | phone => "test phone number", |
|---|
| 57 | website => "http://example.com", |
|---|
| 58 | hours_text => "test hours", |
|---|
| 59 | latitude => "51.524193", |
|---|
| 60 | longitude => "-0.114436", |
|---|
| 61 | summary => "a really nice pub", |
|---|
| 62 | ); |
|---|
| 63 | |
|---|
| 64 | OpenGuides::Test->write_data( |
|---|
| 65 | guide => $guide, |
|---|
| 66 | node => "Calthorpe Arms", |
|---|
| 67 | content => "CAMRA-approved pub near King's Cross", |
|---|
| 68 | comment => "Stub page, please update!", |
|---|
| 69 | username => "Kake", |
|---|
| 70 | postcode => "WC1X 8JR", |
|---|
| 71 | locales => "Bloomsbury\r\nSt Pancras", |
|---|
| 72 | phone => "test phone number", |
|---|
| 73 | website => "http://example.com", |
|---|
| 74 | hours_text => "test hours", |
|---|
| 75 | latitude => "51.524193", |
|---|
| 76 | longitude => "-0.114436", |
|---|
| 77 | summary => "a nice pub", |
|---|
| 78 | node_image => "http://example.com/calthorpe.jpg", |
|---|
| 79 | ); |
|---|
| 80 | |
|---|
| 81 | my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); |
|---|
| 82 | |
|---|
| 83 | like( $rdfxml, qr|<\?xml version="1.0" \?>|, "RDF uses no encoding when none set" ); |
|---|
| 84 | $config->http_charset( "UTF-8" ); |
|---|
| 85 | $guide = OpenGuides->new( config => $config ); |
|---|
| 86 | $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); |
|---|
| 87 | like( $rdfxml, qr|<\?xml version="1.0" encoding="UTF-8"\?>|, "RDF uses declared encoding" ); |
|---|
| 88 | |
|---|
| 89 | like( $rdfxml, qr|<foaf:depiction rdf:resource="http://example.com/calthorpe.jpg" />|, "Node image"); |
|---|
| 90 | |
|---|
| 91 | like( $rdfxml, qr|<wail:Neighborhood rdf:nodeID="Bloomsbury">|, |
|---|
| 92 | "finds the first locale" ); |
|---|
| 93 | like( $rdfxml, qr|<wail:Neighborhood rdf:nodeID="St_Pancras">|, |
|---|
| 94 | "finds the second locale" ); |
|---|
| 95 | |
|---|
| 96 | like( $rdfxml, qr|<contact:phone>test phone number</contact:phone>|, |
|---|
| 97 | "picks up phone number" ); |
|---|
| 98 | |
|---|
| 99 | like( $rdfxml, qr|<dc:available>test hours</dc:available>|, |
|---|
| 100 | "picks up opening hours text" ); |
|---|
| 101 | |
|---|
| 102 | like( $rdfxml, qr|<foaf:homepage rdf:resource="http://example.com" />|, "picks up website" ); |
|---|
| 103 | |
|---|
| 104 | like( $rdfxml, |
|---|
| 105 | qr|<dc:title>Wiki::Toolkit Test Site: Calthorpe Arms</dc:title>|, |
|---|
| 106 | "sets the title correctly" ); |
|---|
| 107 | |
|---|
| 108 | like( $rdfxml, qr|id=Kake;format=rdf#obj"|, |
|---|
| 109 | "last username to edit used as contributor" ); |
|---|
| 110 | like( $rdfxml, qr|id=Anonymous;format=rdf#obj"|, |
|---|
| 111 | "... as well as previous usernames" ); |
|---|
| 112 | |
|---|
| 113 | like( $rdfxml, qr|<wiki:version>2</wiki:version>|, "version picked up" ); |
|---|
| 114 | |
|---|
| 115 | like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" ); |
|---|
| 116 | |
|---|
| 117 | like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?Calthorpe_Arms" />|, |
|---|
| 118 | "set the dc:source with the version-independent uri" ); |
|---|
| 119 | |
|---|
| 120 | like( $rdfxml, qr|<wail:City rdf:nodeID="city">\n\s+<wail:name>London</wail:name>|, "city" ). |
|---|
| 121 | like( $rdfxml, qr|<wail:locatedIn>\n\s+<wail:Country rdf:nodeID="country">\n\s+<wail:name>United Kingdom</wail:name>|, "country" ). |
|---|
| 122 | like( $rdfxml, qr|<wail:postalCode>WC1X 8JR</wail:postalCode>|, "postcode" ); |
|---|
| 123 | like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, "latitude" ); |
|---|
| 124 | like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, "longitude" ); |
|---|
| 125 | like( $rdfxml, qr|<dc:description>a nice pub</dc:description>|, "summary (description)" ); |
|---|
| 126 | |
|---|
| 127 | like( $rdfxml, qr|<dc:date>|, "date element included" ); |
|---|
| 128 | unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" ); |
|---|
| 129 | |
|---|
| 130 | # Check that default city and country can be set to blank. |
|---|
| 131 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 132 | $config->default_city( "" ); |
|---|
| 133 | $config->default_country( "" ); |
|---|
| 134 | $guide = OpenGuides->new( config => $config ); |
|---|
| 135 | OpenGuides::Test->write_data( |
|---|
| 136 | guide => $guide, |
|---|
| 137 | node => "Star Tavern", |
|---|
| 138 | latitude => 51.498, |
|---|
| 139 | longitude => -0.154, |
|---|
| 140 | ); |
|---|
| 141 | $rdf_writer = OpenGuides::RDF->new( wiki => $guide->wiki, config => $config ); |
|---|
| 142 | $rdfxml = $rdf_writer->emit_rdfxml( node => "Star Tavern" ); |
|---|
| 143 | unlike( $rdfxml, qr|<city>|, "no city in RDF when no default city" ); |
|---|
| 144 | unlike( $rdfxml, qr|<country>|, "...same for country" ); |
|---|
| 145 | |
|---|
| 146 | # Now test that there's a nice failsafe where a node doesn't exist. |
|---|
| 147 | $rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); }; |
|---|
| 148 | is( $@, "", "->emit_rdfxml doesn't die when called on a nonexistent node" ); |
|---|
| 149 | |
|---|
| 150 | like( $rdfxml, qr|<wiki:version>0</wiki:version>|, "...and wiki:version is 0" ); |
|---|
| 151 | |
|---|
| 152 | # Test the data for a node that redirects. |
|---|
| 153 | $wiki->write_node( "Calthorpe Arms Pub", |
|---|
| 154 | "#REDIRECT [[Calthorpe Arms]]", |
|---|
| 155 | undef, |
|---|
| 156 | { |
|---|
| 157 | comment => "Created as redirect to Calthorpe Arms page.", |
|---|
| 158 | username => "Earle", |
|---|
| 159 | } |
|---|
| 160 | ); |
|---|
| 161 | |
|---|
| 162 | my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" ); |
|---|
| 163 | |
|---|
| 164 | like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/\?id=Calthorpe_Arms;format=rdf#obj" />|, |
|---|
| 165 | "redirecting node gets owl:sameAs to target" ); |
|---|
| 166 | |
|---|
| 167 | $wiki->write_node( "Nonesuch Stores", |
|---|
| 168 | "A metaphysical wonderland", |
|---|
| 169 | undef, |
|---|
| 170 | { |
|---|
| 171 | comment => "Yup.", |
|---|
| 172 | username => "Nobody", |
|---|
| 173 | opening_hours_text => "Open All Hours", |
|---|
| 174 | } |
|---|
| 175 | ); |
|---|
| 176 | |
|---|
| 177 | $rdfxml = $rdf_writer->emit_rdfxml( node => "Nonesuch Stores" ); |
|---|
| 178 | |
|---|
| 179 | like( $rdfxml, qr|<geo:SpatialThing rdf:ID="obj">|, |
|---|
| 180 | "having opening hours marks node as geospatial" ); |
|---|