root/tags/rel0_48/t/21_rdf.t

Revision 637, 5.4 kB (checked in by earle, 4 years ago)

add owl:sameAs property to RDF versions of redirecting nodes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 => 25;
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                       }
62    );
63
64    my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" );
65
66    like( $rdfxml, qr|<\?xml version="1.0"\?>|, "RDF is encoding-neutral" );
67
68    like( $rdfxml, qr|<foaf:name>Bloomsbury</foaf:name>|,
69          "finds the first locale" );
70    like( $rdfxml, qr|<foaf:name>St Pancras</foaf:name>|,
71         "finds the second locale" );
72
73    like( $rdfxml, qr|<phone>test phone number</phone>|,
74          "picks up phone number" );
75
76    like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|,
77          "picks up opening hours text" );
78
79    like( $rdfxml, qr|<foaf:homepage rdf:resource="test website" />|, "picks up website" );
80
81    like( $rdfxml,
82          qr|<dc:title>CGI::Wiki Test Site: Calthorpe Arms</dc:title>|,
83          "sets the title correctly" );
84
85    like( $rdfxml, qr|<dc:contributor>Kake</dc:contributor>|,
86          "last username to edit used as contributor" );
87
88    like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );
89
90    like( $rdfxml, qr|<rdf:Description rdf:about="">|,
91          "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
102    like( $rdfxml, qr|<dc:date>|, "date element included" );
103    unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
104
105    # Check that default city and country can be set to blank.
106    $config = OpenGuides::Test->make_basic_config;
107    $config->default_city( "" );
108    $config->default_country( "" );
109    my $guide = OpenGuides->new( config => $config );
110    OpenGuides::Test->write_data(
111                                  guide => $guide,
112                                  node  => "Star Tavern",
113                                  latitude => 51.498,
114                                  longitude => -0.154,
115                                );
116    $rdf_writer = OpenGuides::RDF->new( wiki => $guide->wiki, config => $config );
117    $rdfxml = $rdf_writer->emit_rdfxml( node => "Star Tavern" );
118    unlike( $rdfxml, qr|<city>|, "no city in RDF when no default city" );
119    unlike( $rdfxml, qr|<country>|, "...same for country" );
120
121    # Now test that there's a nice failsafe where a node doesn't exist.
122    $rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); };
123    is( $@, "",
124        "->emit_rdfxml doesn't die when called on a nonexistent node" );
125
126    like( $rdfxml, qr|<wiki:version>0</wiki:version>|,
127          "...and wiki:version is 0" );
128
129    # Test the data for a node that redirects.
130    $wiki->write_node( "Calthorpe Arms Pub",
131                       "#REDIRECT [[Calthorpe Arms]]",
132                       undef,
133                       {
134                         comment            => "Created as redirect to Calthorpe Arms page.",
135                         username           => "Earle",
136                       }
137    );
138
139    my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" );
140
141    like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/\?id=Calthorpe_Arms;format=rdf#obj" />|,
142          "redirecting node gets owl:sameAs to target" );
143
144}
Note: See TracBrowser for help on using the browser.