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

Last change on this file since 719 was 719, checked in by Earle Martin, 16 years ago

fix whitespace

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1use CGI::Wiki::Setup::SQLite;
2use OpenGuides;
3use OpenGuides::Config;
4use OpenGuides::RDF;
5use OpenGuides::Utils;
6use OpenGuides::Test;
7use URI::Escape;
8use Test::More tests => 26;
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    CGI::Wiki::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          => "CGI::Wiki Test Site",
26                    default_city       => "London",
27                    default_country    => "United Kingdom",
28                }
29    );
30    eval { require CGI::Wiki::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|<foaf:name>Bloomsbury</foaf:name>|,
70      "finds the first locale" );
71    like( $rdfxml, qr|<foaf:name>St Pancras</foaf:name>|,
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>CGI::Wiki Test Site: Calthorpe Arms</dc:title>|,
84      "sets the title correctly" );
85
86    like( $rdfxml, qr|<dc:contributor>Kake</dc:contributor>|,
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="">|,
92          "sets the 'about' correctly" );
93
94    like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?Calthorpe_Arms" />|,
95      "set the dc:source with the version-independent uri" );
96
97    like( $rdfxml, qr|<country>United Kingdom</country>|, "country" ).
98    like( $rdfxml, qr|<city>London</city>|, "city" ).
99    like( $rdfxml, qr|<postalCode>WC1X 8JR</postalCode>|, "postcode" );
100    like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, "latitude" );
101    like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, "longitude" );
102    like( $rdfxml, qr|<dc:description>a nice pub</dc:description>|, "summary (description)" );
103
104    like( $rdfxml, qr|<dc:date>|, "date element included" );
105    unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
106
107    # Check that default city and country can be set to blank.
108    $config = OpenGuides::Test->make_basic_config;
109    $config->default_city( "" );
110    $config->default_country( "" );
111    my $guide = OpenGuides->new( config => $config );
112    OpenGuides::Test->write_data(
113                                  guide => $guide,
114                                  node  => "Star Tavern",
115                                  latitude => 51.498,
116                                  longitude => -0.154,
117                                );
118    $rdf_writer = OpenGuides::RDF->new( wiki => $guide->wiki, config => $config );
119    $rdfxml = $rdf_writer->emit_rdfxml( node => "Star Tavern" );
120    unlike( $rdfxml, qr|<city>|, "no city in RDF when no default city" );
121    unlike( $rdfxml, qr|<country>|, "...same for country" );
122
123    # Now test that there's a nice failsafe where a node doesn't exist.
124    $rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); };
125    is( $@, "",
126        "->emit_rdfxml doesn't die when called on a nonexistent node" );
127
128    like( $rdfxml, qr|<wiki:version>0</wiki:version>|,
129          "...and wiki:version is 0" );
130
131    # Test the data for a node that redirects.
132    $wiki->write_node( "Calthorpe Arms Pub",
133        "#REDIRECT [[Calthorpe Arms]]",
134        undef,
135        {
136            comment  => "Created as redirect to Calthorpe Arms page.",
137            username => "Earle",
138        }
139    );
140
141    my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" );
142
143    like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/\?id=Calthorpe_Arms;format=rdf#obj" />|,
144      "redirecting node gets owl:sameAs to target" );
145
146}
Note: See TracBrowser for help on using the repository browser.