root/branches/new-install-process/t/21_rdf.t

Revision 1081, 6.2 kB (checked in by ilmari, 19 months ago)

List all contributors in RDF version of nodes (fixes #106)

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