source: trunk/t/21_rdf.t @ 812

Last change on this file since 812 was 785, checked in by Dominic Hargreaves, 16 years ago

Use Wiki::Toolkit. Note that CGI::Wiki::Plugin::Diff hasn't been converted yet,
so tests will be broken for now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
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 tests => 27;
9
10eval { require DBD::SQLite; };
11my $have_sqlite = $@ ? 0 : 1;
12
13SKIP: {
14    skip "DBD::SQLite not installed - no database to test with", 24
15        unless $have_sqlite;
16
17    Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
18    my $config = OpenGuides::Config->new(
19        vars => {
20                    dbtype             => "sqlite",
21                    dbname             => "t/node.db",
22                    indexing_directory => "t/indexes",
23                    script_url         => "http://wiki.example.com/",
24                    script_name        => "mywiki.cgi",
25                    site_name          => "Wiki::Toolkit Test Site",
26                    default_city       => "London",
27                    default_country    => "United Kingdom",
28                }
29    );
30    eval { require Wiki::Toolkit::Search::Plucene; };
31    if ( $@ ) { $config->use_plucene ( 0 ) };
32
33
34    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
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    $wiki->write_node( "Calthorpe Arms",
49        "CAMRA-approved pub near King's Cross",
50        undef,
51        {
52            comment            => "Stub page, please update!",
53            username           => "Kake",
54            postcode           => "WC1X 8JR",
55            locale             => [ "Bloomsbury", "St Pancras" ],
56            phone              => "test phone number",
57            website            => "test website",
58            opening_hours_text => "test hours",
59            latitude           => "51.524193",
60            longitude          => "-0.114436",
61            summary            => "a nice pub",
62        }
63    );
64
65    my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" );
66
67    like( $rdfxml, qr|<\?xml version="1.0"\?>|, "RDF is encoding-neutral" );
68
69    like( $rdfxml, qr|<dc:title>Bloomsbury</dc:title>|,
70        "finds the first locale" );
71    like( $rdfxml, qr|<dc:title>St Pancras</dc:title>|,
72        "finds the second locale" );
73
74    like( $rdfxml, qr|<phone>test phone number</phone>|,
75        "picks up phone number" );
76
77    like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|,
78        "picks up opening hours text" );
79
80    like( $rdfxml, qr|<foaf:homepage rdf:resource="test website" />|, "picks up website" );
81
82    like( $rdfxml,
83        qr|<dc:title>Wiki::Toolkit Test Site: Calthorpe Arms</dc:title>|,
84        "sets the title correctly" );
85
86    like( $rdfxml, qr|<foaf:Person rdf:ID="Kake">|,
87        "last username to edit used as contributor" );
88
89    like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );
90
91    like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" );
92
93    like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?Calthorpe_Arms" />|,
94        "set the dc:source with the version-independent uri" );
95
96    like( $rdfxml, qr|<country>United Kingdom</country>|, "country" ).
97    like( $rdfxml, qr|<city>London</city>|, "city" ).
98    like( $rdfxml, qr|<postalCode>WC1X 8JR</postalCode>|, "postcode" );
99    like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, "latitude" );
100    like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, "longitude" );
101    like( $rdfxml, qr|<dc:description>a nice pub</dc:description>|, "summary (description)" );
102
103    like( $rdfxml, qr|<dc:date>|, "date element included" );
104    unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
105
106    # Check that default city and country can be set to blank.
107    $config = OpenGuides::Test->make_basic_config;
108    $config->default_city( "" );
109    $config->default_country( "" );
110    my $guide = OpenGuides->new( config => $config );
111    OpenGuides::Test->write_data(
112                                    guide => $guide,
113                                    node  => "Star Tavern",
114                                    latitude => 51.498,
115                                    longitude => -0.154,
116                                );
117    $rdf_writer = OpenGuides::RDF->new( wiki => $guide->wiki, config => $config );
118    $rdfxml = $rdf_writer->emit_rdfxml( node => "Star Tavern" );
119    unlike( $rdfxml, qr|<city>|, "no city in RDF when no default city" );
120    unlike( $rdfxml, qr|<country>|, "...same for country" );
121
122    # Now test that there's a nice failsafe where a node doesn't exist.
123    $rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); };
124    is( $@, "", "->emit_rdfxml doesn't die when called on a nonexistent node" );
125
126    like( $rdfxml, qr|<wiki:version>0</wiki:version>|, "...and wiki:version is 0" );
127
128    # Test the data for a node that redirects.
129    $wiki->write_node( "Calthorpe Arms Pub",
130        "#REDIRECT [[Calthorpe Arms]]",
131        undef,
132        {
133            comment  => "Created as redirect to Calthorpe Arms page.",
134            username => "Earle",
135        }
136    );
137
138    my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" );
139
140    like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/\?id=Calthorpe_Arms;format=rdf#obj" />|,
141        "redirecting node gets owl:sameAs to target" );
142
143    $wiki->write_node( "Nonesuch Stores",
144        "A metaphysical wonderland",
145        undef,
146        {
147            comment            => "Yup.",
148            username           => "Nobody",
149            opening_hours_text => "Open All Hours",
150        }
151    );
152
153    $rdfxml = $rdf_writer->emit_rdfxml( node => "Nonesuch Stores" );
154
155    like( $rdfxml, qr|<geo:SpatialThing rdf:ID="obj" dc:title="Nonesuch Stores">|,
156        "having opening hours marks node as geospatial" );
157
158}
Note: See TracBrowser for help on using the repository browser.