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

Last change on this file since 587 was 587, checked in by kake, 17 years ago

Encapsulate config data in OpenGuides::Config.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1use CGI::Wiki::Setup::SQLite;
2use OpenGuides::Config;
3use OpenGuides::RDF;
4use OpenGuides::Utils;
5use URI::Escape;
6use Test::More tests => 22;
7
8eval { require DBD::SQLite; };
9my $have_sqlite = $@ ? 0 : 1;
10
11SKIP: {
12    skip "DBD::SQLite not installed - no database to test with", 22
13      unless $have_sqlite;
14
15    CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
16    my $config = OpenGuides::Config->new(
17           vars => {
18                     dbtype             => "sqlite",
19                     dbname             => "t/node.db",
20                     indexing_directory => "t/indexes",
21                     script_url         => "http://wiki.example.com/",
22                     script_name        => "mywiki.cgi",
23                     site_name          => "CGI::Wiki Test Site",
24                     default_city       => "London",
25                     default_country    => "United Kingdom",
26                   }
27    );
28
29    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
30
31    # Clear out the database from any previous runs.
32    foreach my $del_node ( $wiki->list_all_nodes ) {
33        $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
34    }
35
36    my $rdf_writer = eval {
37        OpenGuides::RDF->new( wiki => $wiki, config => $config );
38    };
39    is( $@, "", "'new' doesn't croak if wiki and config objects supplied" );
40    isa_ok( $rdf_writer, "OpenGuides::RDF" );
41
42    # Test the data for a node that exists.
43    $wiki->write_node( "Calthorpe Arms",
44                       "CAMRA-approved pub near King's Cross",
45                       undef,
46                       {
47                         comment            => "Stub page, please update!",
48                         username           => "Kake",
49                         postcode           => "WC1X 8JR",
50                         locale             => [ "Bloomsbury", "St Pancras" ],
51                         phone              => "test phone number",
52                         website            => "test website",
53                         opening_hours_text => "test hours",
54                         latitude           => "51.524193",
55                         longitude          => "-0.114436"
56                       }
57    );
58
59    my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" );
60
61    like( $rdfxml, qr|<\?xml version="1.0"\?>|, "RDF is encoding-neutral" );
62
63    like( $rdfxml, qr|<foaf:based_near><wn:Neighborhood><foaf:name>Bloomsbury</foaf:name></wn:Neighborhood></foaf:based_near>|,
64          "finds the first locale" );
65    like( $rdfxml, qr|<foaf:based_near><wn:Neighborhood><foaf:name>St Pancras</foaf:name></wn:Neighborhood></foaf:based_near>|,
66         "finds the second locale" );
67
68    like( $rdfxml, qr|<phone>test phone number</phone>|,
69          "picks up phone number" );
70
71    like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|,
72          "picks up opening hours text" );
73
74    like( $rdfxml, qr|<homePage>test website</homePage>|, "picks up website" );
75
76    like( $rdfxml,
77          qr|<dc:title>CGI::Wiki Test Site: Calthorpe Arms</dc:title>|,
78          "sets the title correctly" );
79
80    like( $rdfxml, qr|<dc:contributor>Kake</dc:contributor>|,
81          "last username to edit used as contributor" );
82
83    like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );
84
85    like( $rdfxml, qr|<rdf:Description rdf:about="">|,
86          "sets the 'about' correctly" );
87
88    like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?id=Calthorpe_Arms" />|,
89          "set the dc:source with the version-independent uri" );
90
91    like( $rdfxml, qr|<country>United Kingdom</country>|, "country" ).
92    like( $rdfxml, qr|<city>London</city>|, "city" ).
93    like( $rdfxml, qr|<postalCode>WC1X 8JR</postalCode>|, "postcode" );
94    like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, "latitude" );
95    like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, "longitude" );
96
97    like( $rdfxml, qr|<dc:date>|, "date element included" );
98    unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
99
100    # Now test that there's a nice failsafe where a node doesn't exist.
101    $rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); };
102    is( $@, "",
103        "->emit_rdfxml doesn't die when called on a nonexistent node" );
104
105    like( $rdfxml, qr|<wiki:version>0</wiki:version>|,
106          "...and wiki:version is 0" );
107}
Note: See TracBrowser for help on using the repository browser.