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

Last change on this file since 535 was 535, checked in by Dominic Hargreaves, 17 years ago

Fixed up test broken by earle with lib/OpenGuides/RDF.pm change.

  • 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 Config::Tiny;
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 = Config::Tiny->new;
17    $config->{_} = {
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    my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
29
30    # Clear out the database from any previous runs.
31    foreach my $del_node ( $wiki->list_all_nodes ) {
32        $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
33    }
34
35    my $rdf_writer = eval {
36        OpenGuides::RDF->new( wiki => $wiki, config => $config );
37    };
38    is( $@, "", "'new' doesn't croak if wiki and config objects supplied" );
39    isa_ok( $rdf_writer, "OpenGuides::RDF" );
40
41    # Test the data for a node that exists.
42    $wiki->write_node( "Calthorpe Arms",
43                       "CAMRA-approved pub near King's Cross",
44                       undef,
45                       {
46                         comment            => "Stub page, please update!",
47                         username           => "Kake",
48                         postcode           => "WC1X 8JR",
49                         locale             => [ "Bloomsbury", "St Pancras" ],
50                         phone              => "test phone number",
51                         website            => "test website",
52                         opening_hours_text => "test hours",
53                         latitude           => "51.524193",
54                         longitude          => "-0.114436"
55                       }
56    );
57
58    my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" );
59
60    like( $rdfxml, qr|<\?xml version="1.0"\?>|, "RDF is encoding-neutral" );
61
62    like( $rdfxml, qr|<foaf:based_near><wn:Neighborhood><foaf:name>Bloomsbury</foaf:name></wn:Neighborhood></foaf:based_near>|,
63          "finds the first locale" );
64    like( $rdfxml, qr|<foaf:based_near><wn:Neighborhood><foaf:name>St Pancras</foaf:name></wn:Neighborhood></foaf:based_near>|,
65         "finds the second locale" );
66
67    like( $rdfxml, qr|<phone>test phone number</phone>|,
68          "picks up phone number" );
69
70    like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|,
71          "picks up opening hours text" );
72
73    like( $rdfxml, qr|<homePage>test website</homePage>|, "picks up website" );
74
75    like( $rdfxml,
76          qr|<dc:title>CGI::Wiki Test Site: Calthorpe Arms</dc:title>|,
77          "sets the title correctly" );
78
79    like( $rdfxml, qr|<dc:contributor>Kake</dc:contributor>|,
80          "last username to edit used as contributor" );
81
82    like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );
83
84    like( $rdfxml, qr|<rdf:Description rdf:about="">|,
85          "sets the 'about' correctly" );
86
87    like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?id=Calthorpe_Arms" />|,
88          "set the dc:source with the version-independent uri" );
89
90    like( $rdfxml, qr|<country>United Kingdom</country>|, "country" ).
91    like( $rdfxml, qr|<city>London</city>|, "city" ).
92    like( $rdfxml, qr|<postalCode>WC1X 8JR</postalCode>|, "postcode" );
93    like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, "latitude" );
94    like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, "longitude" );
95
96    like( $rdfxml, qr|<dc:date>|, "date element included" );
97    unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
98
99    # Now test that there's a nice failsafe where a node doesn't exist.
100    $rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); };
101    is( $@, "",
102        "->emit_rdfxml doesn't die when called on a nonexistent node" );
103
104    like( $rdfxml, qr|<wiki:version>0</wiki:version>|,
105          "...and wiki:version is 0" );
106}
Note: See TracBrowser for help on using the repository browser.