Changeset 956


Ignore:
Timestamp:
Mar 20, 2007, 4:47:05 PM (15 years ago)
Author:
Earle Martin
Message:

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

Location:
trunk/t
Files:
46 edited

Legend:

Unmodified
Added
Removed
  • trunk/t/12_macros.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 10;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1312}
     13
     14plan tests => 10;
    1415
    1516SKIP: {
  • trunk/t/16_test_tester.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1011}
    1112
  • trunk/t/17_commit_node.t

    r841 r956  
    99eval { require DBD::SQLite; };
    1010if ( $@ ) {
    11     plan skip_all => "DBD::SQLite not installed";
    12     exit 0;
     11    my ($error) = $@ =~ /^(.*?)\n/;
     12    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1313}
    1414
     
    1616if ( $@ ) {
    1717    plan skip_all => "Plucene not installed";
    18     exit 0;
    1918}
    2019
  • trunk/t/19_autocreate.t

    r930 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10 } else {
    11     plan tests => 4;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1211}
     12
     13plan tests => 4;
    1314
    1415my $config = OpenGuides::Test->make_basic_config;
  • trunk/t/21_rdf.t

    r954 r956  
    1111my $have_sqlite = $@ ? 0 : 1;
    1212
    13 SKIP: {
    14     skip "DBD::SQLite not installed - no database to test with", 24
    15         unless $have_sqlite;
     13if ( $@ ) {
     14    my ($error) = $@ =~ /^(.*?)\n/;
     15    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
     16}
    1617
    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 ) };
     18plan tests => 27;
     19
     20Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     21my $config = OpenGuides::Config->new(
     22    vars => {
     23                dbtype             => "sqlite",
     24                dbname             => "t/node.db",
     25                indexing_directory => "t/indexes",
     26                script_url         => "http://wiki.example.com/",
     27                script_name        => "mywiki.cgi",
     28                site_name          => "Wiki::Toolkit Test Site",
     29                default_city       => "London",
     30                default_country    => "United Kingdom",
     31            }
     32);
     33eval { require Wiki::Toolkit::Search::Plucene; };
     34if ( $@ ) { $config->use_plucene ( 0 ) };
    3235
    3336
    34     my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
     37my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    3538
    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# Clear out the database from any previous runs.
     40foreach my $del_node ( $wiki->list_all_nodes ) {
     41    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     42}
     43
     44my $rdf_writer = eval {
     45    OpenGuides::RDF->new( wiki => $wiki, config => $config );
     46};
     47is( $@, "", "'new' doesn't croak if wiki and config objects supplied" );
     48isa_ok( $rdf_writer, "OpenGuides::RDF" );
     49
     50# Test the data for a node that exists.
     51$wiki->write_node( "Calthorpe Arms",
     52    "CAMRA-approved pub near King's Cross",
     53    undef,
     54    {
     55        comment            => "Stub page, please update!",
     56        username           => "Kake",
     57        postcode           => "WC1X 8JR",
     58        locale             => [ "Bloomsbury", "St Pancras" ],
     59        phone              => "test phone number",
     60        website            => "test website",
     61        opening_hours_text => "test hours",
     62        latitude           => "51.524193",
     63        longitude          => "-0.114436",
     64        summary            => "a nice pub",
    3965    }
     66);
    4067
    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" );
     68my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" );
    4669
    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     );
     70like( $rdfxml, qr|<\?xml version="1.0"\?>|, "RDF is encoding-neutral" );
    6471
    65     my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" );
     72like( $rdfxml, qr|<dc:title>Bloomsbury</dc:title>|,
     73    "finds the first locale" );
     74like( $rdfxml, qr|<dc:title>St Pancras</dc:title>|,
     75    "finds the second locale" );
    6676
    67     like( $rdfxml, qr|<\?xml version="1.0"\?>|, "RDF is encoding-neutral" );
     77like( $rdfxml, qr|<phone>test phone number</phone>|,
     78    "picks up phone number" );
    6879
    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" );
     80like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|,
     81    "picks up opening hours text" );
    7382
    74     like( $rdfxml, qr|<phone>test phone number</phone>|,
    75         "picks up phone number" );
     83like( $rdfxml, qr|<foaf:homepage rdf:resource="test website" />|, "picks up website" );
    7684
    77     like( $rdfxml, qr|<chefmoz:Hours>test hours</chefmoz:Hours>|,
    78         "picks up opening hours text" );
     85like( $rdfxml,
     86    qr|<dc:title>Wiki::Toolkit Test Site: Calthorpe Arms</dc:title>|,
     87    "sets the title correctly" );
    7988
    80     like( $rdfxml, qr|<foaf:homepage rdf:resource="test website" />|, "picks up website" );
     89like( $rdfxml, qr|<foaf:Person rdf:ID="Kake">|,
     90    "last username to edit used as contributor" );
    8191
    82     like( $rdfxml,
    83         qr|<dc:title>Wiki::Toolkit Test Site: Calthorpe Arms</dc:title>|,
    84         "sets the title correctly" );
     92like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );
    8593
    86     like( $rdfxml, qr|<foaf:Person rdf:ID="Kake">|,
    87         "last username to edit used as contributor" );
     94like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" );
    8895
    89     like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );
     96like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi\?Calthorpe_Arms" />|,
     97    "set the dc:source with the version-independent uri" );
    9098
    91     like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" );
     99like( $rdfxml, qr|<country>United Kingdom</country>|, "country" ).
     100like( $rdfxml, qr|<city>London</city>|, "city" ).
     101like( $rdfxml, qr|<postalCode>WC1X 8JR</postalCode>|, "postcode" );
     102like( $rdfxml, qr|<geo:lat>51.524193</geo:lat>|, "latitude" );
     103like( $rdfxml, qr|<geo:long>-0.114436</geo:long>|, "longitude" );
     104like( $rdfxml, qr|<dc:description>a nice pub</dc:description>|, "summary (description)" );
    92105
    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" );
     106like( $rdfxml, qr|<dc:date>|, "date element included" );
     107unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
    95108
    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)" );
     109# Check that default city and country can be set to blank.
     110$config = OpenGuides::Test->make_basic_config;
     111$config->default_city( "" );
     112$config->default_country( "" );
     113my $guide = OpenGuides->new( config => $config );
     114OpenGuides::Test->write_data(
     115                                guide => $guide,
     116                                node  => "Star Tavern",
     117                                latitude => 51.498,
     118                                longitude => -0.154,
     119                            );
     120$rdf_writer = OpenGuides::RDF->new( wiki => $guide->wiki, config => $config );
     121$rdfxml = $rdf_writer->emit_rdfxml( node => "Star Tavern" );
     122unlike( $rdfxml, qr|<city>|, "no city in RDF when no default city" );
     123unlike( $rdfxml, qr|<country>|, "...same for country" );
    102124
    103     like( $rdfxml, qr|<dc:date>|, "date element included" );
    104     unlike( $rdfxml, qr|<dc:date>1970|, "hasn't defaulted to the epoch" );
     125# Now test that there's a nice failsafe where a node doesn't exist.
     126$rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); };
     127is( $@, "", "->emit_rdfxml doesn't die when called on a nonexistent node" );
    105128
    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" );
     129like( $rdfxml, qr|<wiki:version>0</wiki:version>|, "...and wiki:version is 0" );
    121130
    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" );
     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);
    125140
    126     like( $rdfxml, qr|<wiki:version>0</wiki:version>|, "...and wiki:version is 0" );
     141my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" );
    127142
    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     );
     143like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/\?id=Calthorpe_Arms;format=rdf#obj" />|,
     144    "redirecting node gets owl:sameAs to target" );
    137145
    138     my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" );
     146$wiki->write_node( "Nonesuch Stores",
     147    "A metaphysical wonderland",
     148    undef,
     149    {
     150        comment            => "Yup.",
     151        username           => "Nobody",
     152        opening_hours_text => "Open All Hours",
     153    }
     154);
    139155
    140     like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/\?id=Calthorpe_Arms;format=rdf#obj" />|,
    141         "redirecting node gets owl:sameAs to target" );
     156$rdfxml = $rdf_writer->emit_rdfxml( node => "Nonesuch Stores" );
    142157
    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     );
     158like( $rdfxml, qr|<geo:SpatialThing rdf:ID="obj" dc:title="Nonesuch Stores">|,
     159    "having opening hours marks node as geospatial" );
    152160
    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 }
  • trunk/t/22_feed_recent_changes.t

    r903 r956  
    99eval { require DBD::SQLite; };
    1010if ( $@ ) {
    11     plan skip_all => "DBD::SQLite not installed";
    12     exit 0;
     11    my ($error) = $@ =~ /^(.*?)\n/;
     12    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1313}
    1414
     
    1616if ( $@ ) {
    1717    plan skip_all => "Plucene not installed";
    18     exit 0;
    1918}
    2019
  • trunk/t/23_feed_node_all_versions.t

    r898 r956  
    99eval { require DBD::SQLite; };
    1010if ( $@ ) {
    11     plan skip_all => "DBD::SQLite not installed";
    12     exit 0;
     11    my ($error) = $@ =~ /^(.*?)\n/;
     12    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1313}
    1414
     
    1616if ( $@ ) {
    1717    plan skip_all => "Plucene not installed";
    18     exit 0;
    1918}
    2019
  • trunk/t/24_feed_node_listings.t

    r898 r956  
    99eval { require DBD::SQLite; };
    1010if ( $@ ) {
    11     plan skip_all => "DBD::SQLite not installed";
    12     exit 0;
     11    my ($error) = $@ =~ /^(.*?)\n/;
     12    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1313}
    1414
     
    1616if ( $@ ) {
    1717    plan skip_all => "Plucene not installed";
    18     exit 0;
    1918}
    2019
  • trunk/t/25_write_geo_data.t

    r785 r956  
    88eval { require DBD::SQLite; };
    99if ( $@ ) {
    10     plan skip_all => "DBD::SQLite not installed";
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1112}
    1213
  • trunk/t/26_geo_data_search_form.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1011}
    1112
     
    1819if ( $@ ) {
    1920    plan skip_all => "Test::HTML::Content not installed";
    20     exit 0;
    2121}
    2222
  • trunk/t/27_geo_data_edit_form.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1011}
    1112
     
    1314if ( $@ ) {
    1415    plan skip_all => "Plucene not installed";
    15     exit 0;
    1616}
    1717
     
    1919if ( $@ ) {
    2020    plan skip_all => "Test::HTML::Content not installed";
    21     exit 0;
    2221}
    2322
  • trunk/t/28_wgs84_coords.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 6;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1312}
    1413
    15 SKIP: {
    16     # Clear out the database from any previous runs.
    17     unlink "t/node.db";
    18     # And give us a new one
    19     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     14plan tests => 6;
    2015
    21     # Now we can start testing
    22     my $config = OpenGuides::Test->make_basic_config;
    23     $config->force_wgs84 (1);
     16# Clear out the database from any previous runs.
     17unlink "t/node.db";
     18# And give us a new one
     19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    2420
    25     my $guide = OpenGuides->new( config => $config );
     21# Now we can start testing
     22my $config = OpenGuides::Test->make_basic_config;
     23$config->force_wgs84 (1);
    2624
    27     my ($longitude, $latitude) = (10, 12);
     25my $guide = OpenGuides->new( config => $config );
    2826
    29     my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
    30                                                         longitude => $longitude,
    31                                                         latitude => $latitude,
    32                                                         config => $config);
     27my ($longitude, $latitude) = (10, 12);
    3328
    34     is( $wgs_long, $longitude,
    35         "get_wgs84_coords returns the original longitude when force_wgs84 is on");
    36     is( $wgs_lat, $latitude,
    37         "get_wgs84_coords returns the original latitude when force_wgs84 is on");
     29my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
     30                                                    longitude => $longitude,
     31                                                    latitude => $latitude,
     32                                                    config => $config);
     33
     34is( $wgs_long, $longitude,
     35    "get_wgs84_coords returns the original longitude when force_wgs84 is on");
     36is( $wgs_lat, $latitude,
     37    "get_wgs84_coords returns the original latitude when force_wgs84 is on");
    3838
    3939
    40     # Now claim to be in the UK
    41     eval{ require Geo::HelmertTransform; };
    42     my $have_helmert = $@ ? 0 : 1;
    43     SKIP : {
    44         skip "Geo::HelmertTransform not installed - can't do transforms", 4
    45             unless $have_helmert;
     40# Now claim to be in the UK
     41eval{ require Geo::HelmertTransform; };
     42my $have_helmert = $@ ? 0 : 1;
     43SKIP : {
     44    skip "Geo::HelmertTransform not installed - can't do transforms", 4
     45        unless $have_helmert;
    4646
    47         $config->force_wgs84(0);
    48         $config->geo_handler(1);
     47    $config->force_wgs84(0);
     48    $config->geo_handler(1);
    4949
    50         # Set our location to be somewhere known
    51            ($longitude,$latitude)  = (-1.258200,51.754349);
    52         my ($wgs84_lon,$wgs84_lat) = (-1.259687,51.754813);
     50    # Set our location to be somewhere known
     51       ($longitude,$latitude)  = (-1.258200,51.754349);
     52    my ($wgs84_lon,$wgs84_lat) = (-1.259687,51.754813);
    5353
    54         ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
    55                                                          longitude => $longitude,
    56                                                          latitude => $latitude,
    57                                                          config => $config);
     54    ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
     55                                                     longitude => $longitude,
     56                                                     latitude => $latitude,
     57                                                     config => $config);
    5858
    59         # Round to 5 dp
    60         my $fivedp = 1 * 1000 * 100;
    61         $wgs_long = int($wgs_long * $fivedp)/$fivedp;
    62         $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
    63         $wgs84_lon = int($wgs84_lon * $fivedp)/$fivedp;
    64         $wgs84_lat = int($wgs84_lat * $fivedp)/$fivedp;
     59    # Round to 5 dp
     60    my $fivedp = 1 * 1000 * 100;
     61    $wgs_long = int($wgs_long * $fivedp)/$fivedp;
     62    $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
     63    $wgs84_lon = int($wgs84_lon * $fivedp)/$fivedp;
     64    $wgs84_lat = int($wgs84_lat * $fivedp)/$fivedp;
    6565
    66         is( $wgs_long, $wgs84_lon,
    67             "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
    68         is( $wgs_lat, $wgs84_lat,
    69             "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
     66    is( $wgs_long, $wgs84_lon,
     67        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
     68    is( $wgs_lat, $wgs84_lat,
     69        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
    7070
    71         # Call it again, check we get the same result
    72         ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
    73                                                          longitude => $longitude,
    74                                                          latitude => $latitude,
    75                                                          config => $config);
    76         $wgs_long = int($wgs_long * $fivedp)/$fivedp;
    77         $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
    78         is( $wgs_long, $wgs84_lon,
    79             "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
    80         is( $wgs_lat, $wgs84_lat,
    81             "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
    82     }
     71    # Call it again, check we get the same result
     72    ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
     73                                                     longitude => $longitude,
     74                                                     latitude => $latitude,
     75                                                     config => $config);
     76    $wgs_long = int($wgs_long * $fivedp)/$fivedp;
     77    $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
     78    is( $wgs_long, $wgs84_lon,
     79        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
     80    is( $wgs_lat, $wgs84_lat,
     81        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
    8382}
  • trunk/t/31_search.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
    10 } else {
    11     plan tests => 18;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
     11}
    1212
    13     # Clear out the database from any previous runs.
    14     unlink "t/node.db";
    15     unlink <t/indexes/*>;
     13plan tests => 18;
    1614
    17     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    18     my $config = OpenGuides::Test->make_basic_config;
    19     $config->script_name( "wiki.cgi" );
    20     $config->script_url( "http://example.com/" );
     15# Clear out the database from any previous runs.
     16unlink "t/node.db";
     17unlink <t/indexes/*>;
    2118
    22     # Plucene is the recommended searcher now.
    23     eval { require Wiki::Toolkit::Search::Plucene; };
    24     if ( $@ ) { $config->use_plucene( 0 ) };
     19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     20my $config = OpenGuides::Test->make_basic_config;
     21$config->script_name( "wiki.cgi" );
     22$config->script_url( "http://example.com/" );
    2523
    26     my $search = OpenGuides::Search->new( config => $config );
    27     isa_ok( $search, "OpenGuides::Search" );
     24# Plucene is the recommended searcher now.
     25eval { require Wiki::Toolkit::Search::Plucene; };
     26if ( $@ ) { $config->use_plucene( 0 ) };
    2827
    29     my $output = $search->run( return_output => 1 );
    30     unlike( $output, qr/no items matched/i,
    31             "doesn't output 'no items matched' if no terms supplied" );
    32     unlike( $output, qr/action=edit/,
    33             "doesn't offer edit link" );
     28my $search = OpenGuides::Search->new( config => $config );
     29isa_ok( $search, "OpenGuides::Search" );
    3430
    35     my %tt_vars = $search->run(
    36                                 return_tt_vars => 1,
    37                                 vars           => { search => "banana" },
    38                               );
    39     is( $tt_vars{first_num}, 0, "first_num set to 0 when no hits" );
    40     is( scalar @{ $tt_vars{results} }, 0, "...and results array empty" );
     31my $output = $search->run( return_output => 1 );
     32unlike( $output, qr/no items matched/i,
     33        "doesn't output 'no items matched' if no terms supplied" );
     34unlike( $output, qr/action=edit/,
     35        "doesn't offer edit link" );
    4136
    42     $output = $search->run(
    43                             return_output => 1,
    44                             vars          => { search => "banana" }
    45                            );
    46     like( $output, qr/no items matched/i,
    47           "outputs 'no items matched' if term not found" );
    48     unlike( $output, qr/matches found, showing/i,
    49             "doesn't output 'matches found, showing' if term not found" );
     37my %tt_vars = $search->run(
     38                            return_tt_vars => 1,
     39                            vars           => { search => "banana" },
     40                          );
     41is( $tt_vars{first_num}, 0, "first_num set to 0 when no hits" );
     42is( scalar @{ $tt_vars{results} }, 0, "...and results array empty" );
    5043
    51     # Pop some data in and search again.
    52     my $wiki = $search->{wiki}; # white boxiness
    53     $wiki->write_node( "Banana", "banana" );
    54     $wiki->write_node( "Monkey", "banana brains" );
    55     $wiki->write_node( "Monkey Brains", "BRANES" );
    56     $wiki->write_node( "Want Pie Now", "weebl" );
    57     $wiki->write_node( "Punctuation", "*" );
    58     $wiki->write_node( "Choice", "Eenie meenie minie mo");
     44$output = $search->run(
     45                        return_output => 1,
     46                        vars          => { search => "banana" }
     47                      );
     48like( $output, qr/no items matched/i,
     49      "outputs 'no items matched' if term not found" );
     50unlike( $output, qr/matches found, showing/i,
     51        "doesn't output 'matches found, showing' if term not found" );
    5952
    60     # Test with two hits first - simpler.
    61     %tt_vars = $search->run(
    62                              return_tt_vars => 1,
    63                              vars           => { search => "banana" },
    64                            );
    65     my @found = map { $_->{name} } @{ $tt_vars{results} || [] };
    66     is( scalar @found, 2, "search finds single word twice" );
    67     is_deeply( [ sort @found ], [ "Banana", "Monkey" ],
    68                "...in the right places" );
    69     print "# Found in $_\n" foreach @found;
     53# Pop some data in and search again.
     54my $wiki = $search->{wiki}; # white boxiness
     55$wiki->write_node( "Banana", "banana" );
     56$wiki->write_node( "Monkey", "banana brains" );
     57$wiki->write_node( "Monkey Brains", "BRANES" );
     58$wiki->write_node( "Want Pie Now", "weebl" );
     59$wiki->write_node( "Punctuation", "*" );
     60$wiki->write_node( "Choice", "Eenie meenie minie mo");
    7061
    71     # Make sure that $output matches too - we're testing the template here.
    72     $output =  $search->run(
    73                              return_output => 1,
    74                              vars           => { search => "banana" },
    75                            );
    76     like( $output, qr/<a href="http:\/\/example.com\/wiki.cgi\?Banana">/,
    77           "...and link is included in template output" );
     62# Test with two hits first - simpler.
     63%tt_vars = $search->run(
     64                         return_tt_vars => 1,
     65                         vars           => { search => "banana" },
     66                       );
     67my @found = map { $_->{name} } @{ $tt_vars{results} || [] };
     68is( scalar @found, 2, "search finds single word twice" );
     69is_deeply( [ sort @found ], [ "Banana", "Monkey" ],
     70           "...in the right places" );
     71print "# Found in $_\n" foreach @found;
    7872
    79     # One hit in body only should show result list.
    80     $output = $search->run(
    81                             return_output => 1,
    82                             vars          => { search => "weebl" },
    83                           );
    84     unlike( $output, qr/Status: 302/,
    85             "no redirect if match only in body");
     73# Make sure that $output matches too - we're testing the template here.
     74$output = $search->run(
     75                         return_output => 1,
     76                         vars           => { search => "banana" },
     77                       );
     78like( $output, qr/<a href="http:\/\/example.com\/wiki.cgi\?Banana">/,
     79      "...and link is included in template output" );
    8680
    87     # One hit in title should redirect to that page.
    88     $output = $search->run(
    89                             return_output => 1,
    90                             vars          => { search => "want pie now" },
    91                           );
    92     like( $output, qr/Status: 302/,
    93           "prints redirect on single hit and match in title" );
    94     # Old versions of CGI.pm mistakenly print location: instead of Location:
    95     like( $output,
    96           qr/[lL]ocation: http:\/\/example.com\/wiki.cgi\?Want_Pie_Now/,
    97           "...and node name munged correctly in URL" );
     81# One hit in body only should show result list.
     82$output = $search->run(
     83                        return_output => 1,
     84                        vars          => { search => "weebl" },
     85                      );
     86unlike( $output, qr/Status: 302/,
     87        "no redirect if match only in body");
    9888
    99     # Test the AND search
    100     %tt_vars = $search->run(
    101                             return_tt_vars => 1,
    102                             vars           => { search => "monkey banana" },
    103                            );
    104     @found = map { $_->{name} } @{ $tt_vars{results} || [] };
    105     is_deeply( \@found, [ "Monkey" ], "AND search returns right results" );
     89# One hit in title should redirect to that page.
     90$output = $search->run(
     91                        return_output => 1,
     92                        vars          => { search => "want pie now" },
     93                      );
     94like( $output, qr/Status: 302/,
     95      "prints redirect on single hit and match in title" );
     96# Old versions of CGI.pm mistakenly print location: instead of Location:
     97like( $output,
     98      qr/[lL]ocation: http:\/\/example.com\/wiki.cgi\?Want_Pie_Now/,
     99      "...and node name munged correctly in URL" );
    106100
    107     # Test the OR search
    108     %tt_vars = $search->run(
    109                              return_tt_vars => 1,
    110                              vars           => { search => "brains, pie" },
    111                            );
    112     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    113     is_deeply( \@found, [ "Monkey", "Monkey Brains", "Want Pie Now" ],
    114                "OR search returns right results" );
    115     print "# Found in $_\n" foreach @found;
     101# Test the AND search
     102%tt_vars = $search->run(
     103                        return_tt_vars => 1,
     104                        vars           => { search => "monkey banana" },
     105                       );
     106@found = map { $_->{name} } @{ $tt_vars{results} || [] };
     107is_deeply( \@found, [ "Monkey" ], "AND search returns right results" );
    116108
    117     SKIP: {
    118         skip "NOT search not done yet", 1;
    119     # Test the NOT search
    120     %tt_vars = $search->run(
    121                              return_tt_vars => 1,
    122                              vars           => { search => "banana -monkey" },
    123                            );
    124     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    125     is_deeply( \@found, [ "Banana" ], "NOT search returns right results" );
    126     } # end of SKIP
     109# Test the OR search
     110%tt_vars = $search->run(
     111                         return_tt_vars => 1,
     112                         vars           => { search => "brains, pie" },
     113                       );
     114@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     115is_deeply( \@found, [ "Monkey", "Monkey Brains", "Want Pie Now" ],
     116           "OR search returns right results" );
     117print "# Found in $_\n" foreach @found;
    127118
    128     # Test the phrase search
    129     $output = $search->run(
    130                             return_output => 1,
    131                             vars          => { search => '"monkey brains"' },
    132                            );
    133     like( $output,
    134           qr/[lL]ocation: http:\/\/example.com\/wiki.cgi\?Monkey_Brains/,   
    135           "phrase search returns right results and redirects to page"
    136         );
     119SKIP: {
     120    skip "NOT search not done yet", 1;
     121# Test the NOT search
     122%tt_vars = $search->run(
     123                         return_tt_vars => 1,
     124                         vars           => { search => "banana -monkey" },
     125                       );
     126@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     127is_deeply( \@found, [ "Banana" ], "NOT search returns right results" );
     128} # end of SKIP
    137129
    138     #####
    139     ##### Test numbering when we have more than a page of results.
    140     #####
     130# Test the phrase search
     131$output = $search->run(
     132                        return_output => 1,
     133                        vars          => { search => '"monkey brains"' },
     134                       );
     135like( $output,
     136      qr/[lL]ocation: http:\/\/example.com\/wiki.cgi\?Monkey_Brains/,   
     137      "phrase search returns right results and redirects to page"
     138    );
    141139
    142     foreach my $i ( 1 .. 30 ) {
    143         $wiki->write_node( "Node $i", "wombat" ) or die "Can't write Node $i";
    144     }
    145     $output = $search->run(
    146                             return_output => 1,
    147                             vars          => {
    148                                                search => "wombat",
    149                                                next   => 20,
    150                                              },
    151                           );
    152     like( $output, qr/ol start="21"/,
    153           "second page of results starts with right numbering" );
     140#####
     141##### Test numbering when we have more than a page of results.
     142#####
     143
     144foreach my $i ( 1 .. 30 ) {
     145    $wiki->write_node( "Node $i", "wombat" ) or die "Can't write Node $i";
    154146}
     147$output = $search->run(
     148                        return_output => 1,
     149                        vars          => {
     150                                           search => "wombat",
     151                                           next   => 20,
     152                                         },
     153                      );
     154like( $output, qr/ol start="21"/,
     155      "second page of results starts with right numbering" );
  • trunk/t/32_search_simple_metadata.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 10;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1312}
    1413
    15 SKIP: {
    16     # Clear out the database from any previous runs.
    17     unlink "t/node.db";
    18     unlink <t/indexes/*>;
     14plan tests => 10;
    1915
    20     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    21     my $config = OpenGuides::Config->new(
    22            vars => {
    23                      dbtype             => "sqlite",
    24                      dbname             => "t/node.db",
    25                      indexing_directory => "t/indexes",
    26                      script_name        => "wiki.cgi",
    27                      script_url         => "http://example.com/",
    28                      site_name          => "Test Site",
    29                      template_path      => "./templates",
    30                    }
    31     );
     16# Clear out the database from any previous runs.
     17unlink "t/node.db";
     18unlink <t/indexes/*>;
    3219
    33     # Plucene is the recommended searcher now.
    34     eval { require Wiki::Toolkit::Search::Plucene; };
    35     if ( $@ ) { $config->use_plucene( 0 ) };
     20Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     21my $config = OpenGuides::Config->new(
     22       vars => {
     23                 dbtype             => "sqlite",
     24                 dbname             => "t/node.db",
     25                 indexing_directory => "t/indexes",
     26                 script_name        => "wiki.cgi",
     27                 script_url         => "http://example.com/",
     28                 site_name          => "Test Site",
     29                 template_path      => "./templates",
     30               }
     31);
    3632
    37     my $search = OpenGuides::Search->new( config => $config );
     33# Plucene is the recommended searcher now.
     34eval { require Wiki::Toolkit::Search::Plucene; };
     35if ( $@ ) { $config->use_plucene( 0 ) };
    3836
    39     # Add some data.  We write it twice to avoid hitting the redirect.
    40     my $wiki = $search->{wiki}; # white boxiness
    41     $wiki->write_node( "Calthorpe Arms", "Serves beer.", undef,
    42                        { category => "Pubs", locale => "Holborn" } );
    43     $wiki->write_node( "Penderel's Oak", "Serves beer.", undef,
    44                        { category => "Pubs", locale => "Holborn" } );
    45     $wiki->write_node( "British Museum", "Huge museum, lots of artifacts.", undef,
    46                        { category => ["Museums", "Major Attractions"]
    47                        , locale => ["Holborn", "Bloomsbury"] } );
     37my $search = OpenGuides::Search->new( config => $config );
    4838
    49     # Check that a search on its category works.
    50     my %tt_vars = $search->run(
    51                                 return_tt_vars => 1,
    52                                 vars           => { search => "Pubs" },
    53                               );
    54     my @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    55     is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
    56                "simple search looks in category" );
     39# Add some data.  We write it twice to avoid hitting the redirect.
     40my $wiki = $search->{wiki}; # white boxiness
     41$wiki->write_node( "Calthorpe Arms", "Serves beer.", undef,
     42                   { category => "Pubs", locale => "Holborn" } );
     43$wiki->write_node( "Penderel's Oak", "Serves beer.", undef,
     44                   { category => "Pubs", locale => "Holborn" } );
     45$wiki->write_node( "British Museum", "Huge museum, lots of artifacts.", undef,
     46                   { category => ["Museums", "Major Attractions"]
     47                   , locale => ["Holborn", "Bloomsbury"] } );
    5748
    58     %tt_vars = $search->run(
    59                              return_tt_vars => 1,
    60                              vars           => { search => "pubs" },
    61                            );
    62     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    63     is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
    64                "...and is case-insensitive" );
     49# Check that a search on its category works.
     50my %tt_vars = $search->run(
     51                            return_tt_vars => 1,
     52                            vars           => { search => "Pubs" },
     53                          );
     54my @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     55is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
     56           "simple search looks in category" );
    6557
    66     # Check that a search on its locale works.
    67     %tt_vars = $search->run(
    68                              return_tt_vars => 1,
    69                              vars           => { search => "Holborn" },
    70                            );
    71     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    72     is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
    73                "simple search looks in locale" );
     58%tt_vars = $search->run(
     59                         return_tt_vars => 1,
     60                         vars           => { search => "pubs" },
     61                       );
     62@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     63is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
     64           "...and is case-insensitive" );
    7465
    75     %tt_vars = $search->run(
    76                              return_tt_vars => 1,
    77                              vars           => { search => "holborn" },
    78                            );
    79     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    80     is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
    81                "...and is case-insensitive" );
     66# Check that a search on its locale works.
     67%tt_vars = $search->run(
     68                         return_tt_vars => 1,
     69                         vars           => { search => "Holborn" },
     70                       );
     71@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     72is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
     73           "simple search looks in locale" );
    8274
    83     # Test AND search in various combinations.
    84     %tt_vars = $search->run(
    85                              return_tt_vars => 1,
    86                              vars           => { search => "Holborn Pubs" },
    87                            );
    88     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    89     is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
    90                "AND search works between category and locale" );
     75%tt_vars = $search->run(
     76                         return_tt_vars => 1,
     77                         vars           => { search => "holborn" },
     78                       );
     79@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     80is_deeply( \@found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ],
     81           "...and is case-insensitive" );
    9182
    92     %tt_vars = $search->run(
    93                              return_tt_vars => 1,
    94                              vars         => { search => "Holborn Penderel" },
    95                            );
    96     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    97     is_deeply( \@found, [ "Penderel's Oak" ],
    98                "AND search works between title and locale" );
     83# Test AND search in various combinations.
     84%tt_vars = $search->run(
     85                         return_tt_vars => 1,
     86                         vars           => { search => "Holborn Pubs" },
     87                       );
     88@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     89is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
     90           "AND search works between category and locale" );
    9991
    100     %tt_vars = $search->run(
    101                              return_tt_vars => 1,
    102                              vars           => { search => "Pubs Penderel" },
    103                            );
    104     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    105     is_deeply( \@found, [ "Penderel's Oak" ],
    106                "AND search works between title and category" );
     92%tt_vars = $search->run(
     93                         return_tt_vars => 1,
     94                         vars         => { search => "Holborn Penderel" },
     95                       );
     96@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     97is_deeply( \@found, [ "Penderel's Oak" ],
     98           "AND search works between title and locale" );
    10799
    108     %tt_vars = $search->run(
    109                              return_tt_vars => 1,
    110                              vars           => { search => "Holborn beer" },
    111                            );
    112     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    113     is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
    114                "...and between body and locale" );
     100%tt_vars = $search->run(
     101                         return_tt_vars => 1,
     102                         vars           => { search => "Pubs Penderel" },
     103                       );
     104@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     105is_deeply( \@found, [ "Penderel's Oak" ],
     106           "AND search works between title and category" );
    115107
    116     %tt_vars = $search->run(
    117                              return_tt_vars => 1,
    118                              vars           => { search => "Pubs beer" },
    119                            );
    120     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    121     is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
    122                "...and between body and category" );
     108%tt_vars = $search->run(
     109                         return_tt_vars => 1,
     110                         vars           => { search => "Holborn beer" },
     111                       );
     112@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     113is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
     114           "...and between body and locale" );
    123115
    124     %tt_vars = $search->run(
    125                              return_tt_vars => 1,
    126                              vars           => { search => '"major attractions"' },
    127                            );
    128     @found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
    129     is_deeply( \@found, [ "British Museum", ],
    130                "Multi word category name" );
    131 }
     116%tt_vars = $search->run(
     117                         return_tt_vars => 1,
     118                         vars           => { search => "Pubs beer" },
     119                       );
     120@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     121is_deeply( \@found, [ "Calthorpe Arms", "Penderel's Oak" ],
     122           "...and between body and category" );
     123
     124%tt_vars = $search->run(
     125                         return_tt_vars => 1,
     126                         vars           => { search => '"major attractions"' },
     127                       );
     128@found = sort map { $_->{name} } @{ $tt_vars{results} || [] };
     129is_deeply( \@found, [ "British Museum", ],
     130           "Multi word category name" );
  • trunk/t/33_search_advanced_search.t

    r785 r956  
    99eval { require DBD::SQLite; };
    1010if ( $@ ) {
    11     plan skip_all => "DBD::SQLite not installed";
     11    my ($error) = $@ =~ /^(.*?)\n/;
     12    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
    1213}
    1314
  • trunk/t/33_search_advanced_search_utm.t

    r785 r956  
    88eval { require DBD::SQLite; };
    99if ( $@ ) {
    10     plan skip_all => "DBD::SQLite not installed";
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1112}
    1213
  • trunk/t/34_search_paging.t

    r785 r956  
    88eval { require DBD::SQLite; };
    99if ( $@ ) {
    10     plan skip_all => "DBD::SQLite not installed";
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1112}
    1213
  • trunk/t/35_search_two_searches.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1011}
    1112
  • trunk/t/36_search_order.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
    10     exit 0;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1111}
    1212
     
    1414if ( $@ ) {
    1515    plan skip_all => "Plucene not installed";
    16     exit 0;
    1716}
    1817
  • trunk/t/37_search_summaries.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
    10 } else {
    11     plan tests => 2;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
     11}
    1212
    13     # Clear out the database from any previous runs.
    14     unlink "t/node.db";
    15     unlink <t/indexes/*>;
     13plan tests => 2;
    1614
    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_name        => "wiki.cgi",
    24                      script_url         => "http://example.com/",
    25                      site_name          => "Test Site",
    26                      template_path      => "./templates",
    27                    }
    28     );
     15# Clear out the database from any previous runs.
     16unlink "t/node.db";
     17unlink <t/indexes/*>;
    2918
    30     # Plucene is the recommended searcher now.
    31     eval { require Wiki::Toolkit::Search::Plucene; };
    32     if ( $@ ) { $config->use_plucene( 0 ) };
     19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     20my $config = OpenGuides::Config->new(
     21       vars => {
     22                 dbtype             => "sqlite",
     23                 dbname             => "t/node.db",
     24                 indexing_directory => "t/indexes",
     25                 script_name        => "wiki.cgi",
     26                 script_url         => "http://example.com/",
     27                 site_name          => "Test Site",
     28                 template_path      => "./templates",
     29               }
     30);
    3331
    34     my $search = OpenGuides::Search->new( config => $config );
    35     isa_ok( $search, "OpenGuides::Search" );
    36     my $wiki = $search->wiki;
    37     $wiki->write_node( "Pub Crawls", "The basic premise of the pub crawl is to visit a succession of pubs, rather than spending the entire evening or day in a single establishment. London offers an excellent choice of themes for your pub crawl.", undef, { category => "Pubs" } ) or die "Can't write node";
     32# Plucene is the recommended searcher now.
     33eval { require Wiki::Toolkit::Search::Plucene; };
     34if ( $@ ) { $config->use_plucene( 0 ) };
    3835
    39     my $output = $search->run(
    40                                return_output => 1,
    41                                vars          => { search => "pub" }
    42                              );
    43     SKIP: {
    44         skip "TODO: summaries", 1;
    45         like( $output, qr|<b>pub</b>|i,
    46               "outputs at least one bolded occurence of 'pub'" );
    47     } # end of SKIP
    48 }
     36my $search = OpenGuides::Search->new( config => $config );
     37isa_ok( $search, "OpenGuides::Search" );
     38my $wiki = $search->wiki;
     39$wiki->write_node( "Pub Crawls", "The basic premise of the pub crawl is to visit a succession of pubs, rather than spending the entire evening or day in a single establishment. London offers an excellent choice of themes for your pub crawl.", undef, { category => "Pubs" } ) or die "Can't write node";
     40
     41my $output = $search->run(
     42                           return_output => 1,
     43                           vars          => { search => "pub" }
     44                         );
     45SKIP: {
     46    skip "TODO: summaries", 1;
     47    like( $output, qr|<b>pub</b>|i,
     48          "outputs at least one bolded occurence of 'pub'" );
     49} # end of SKIP
  • trunk/t/38_search_params.t

    r785 r956  
    88eval { require DBD::SQLite; };
    99if ( $@ ) {
    10     plan skip_all => "DBD::SQLite not installed";
    11     exit 0;
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1212}
    1313
     
    1515if ( $@ ) {
    1616    plan skip_all => "Plucene not installed";
    17     exit 0;
    1817}
    1918
  • trunk/t/39_search_form.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1011}
    1112
     
    1819if ( $@ ) {
    1920    plan skip_all => "Test::HTML::Content not installed";
    20     exit 0;
    2121}
    2222
  • trunk/t/40_search_as_feed.t

    r818 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed";
    10 } else {
    11     plan tests => 7;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
     11}
    1212
    13     # Clear out the database from any previous runs.
    14     unlink "t/node.db";
    15     unlink <t/indexes/*>;
     13plan tests => 7;
    1614
    17     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    18     my $config = OpenGuides::Test->make_basic_config;
    19     $config->script_name( "wiki.cgi" );
    20     $config->script_url( "http://example.com/" );
     15# Clear out the database from any previous runs.
     16unlink "t/node.db";
     17unlink <t/indexes/*>;
    2118
    22     # Plucene is the recommended searcher now.
    23     eval { require Wiki::Toolkit::Search::Plucene; };
    24     if ( $@ ) { $config->use_plucene( 0 ) };
     19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     20my $config = OpenGuides::Test->make_basic_config;
     21$config->script_name( "wiki.cgi" );
     22$config->script_url( "http://example.com/" );
    2523
    26     my $search = OpenGuides::Search->new( config => $config );
    27     isa_ok( $search, "OpenGuides::Search" );
     24# Plucene is the recommended searcher now.
     25eval { require Wiki::Toolkit::Search::Plucene; };
     26if ( $@ ) { $config->use_plucene( 0 ) };
    2827
    29     # Pop some test data in
    30     my $wiki = $search->{wiki}; # white boxiness
    31     $wiki->write_node( "Banana", "banana" );
    32     $wiki->write_node( "Monkey", "banana brains" );
    33     $wiki->write_node( "Monkey Brains", "BRANES" );
    34     $wiki->write_node( "Want Pie Now", "weebl" );
    35     $wiki->write_node( "Punctuation", "*" );
    36     $wiki->write_node( "Choice", "Eenie meenie minie mo");
     28my $search = OpenGuides::Search->new( config => $config );
     29isa_ok( $search, "OpenGuides::Search" );
    3730
    38     # RSS search, should give 2 hits
    39     my $output = $search->run(
    40                              return_output => 1,
    41                              vars => { search => "banana", format => "rss" },
    42                            );
     31# Pop some test data in
     32my $wiki = $search->{wiki}; # white boxiness
     33$wiki->write_node( "Banana", "banana" );
     34$wiki->write_node( "Monkey", "banana brains" );
     35$wiki->write_node( "Monkey Brains", "BRANES" );
     36$wiki->write_node( "Want Pie Now", "weebl" );
     37$wiki->write_node( "Punctuation", "*" );
     38$wiki->write_node( "Choice", "Eenie meenie minie mo");
    4339
    44     like($output, qr/<rdf:RDF/, "Really was RSS");
    45     like($output, qr/<items>/, "Really was RSS");
     40# RSS search, should give 2 hits
     41my $output = $search->run(
     42                         return_output => 1,
     43                         vars => { search => "banana", format => "rss" },
     44                       );
    4645
    47     my @found = ($output =~ /(<rdf:li)/g);
    48     is( scalar @found, 2, "found right entries in feed" );
     46like($output, qr/<rdf:RDF/, "Really was RSS");
     47like($output, qr/<items>/, "Really was RSS");
     48
     49my @found = ($output =~ /(<rdf:li)/g);
     50is( scalar @found, 2, "found right entries in feed" );
    4951
    5052
    51     # Atom search, should give 1 hit
    52     $output = $search->run(
    53                             return_output => 1,
    54                             vars => { search => "weebl", format => "atom" },
    55                           );
    56     like($output, qr/<feed/, "Really was Atom");
    57     like($output, qr/<entry>/, "Really was Atom");
     53# Atom search, should give 1 hit
     54$output = $search->run(
     55                        return_output => 1,
     56                        vars => { search => "weebl", format => "atom" },
     57                      );
     58like($output, qr/<feed/, "Really was Atom");
     59like($output, qr/<entry>/, "Really was Atom");
    5860
    59     @found = ($output =~ /(<entry>)/g);
    60     is( scalar @found, 1, "found right entries in feed" );
    61 }
     61@found = ($output =~ /(<entry>)/g);
     62is( scalar @found, 1, "found right entries in feed" );
  • trunk/t/42_edit_conflict.t

    r929 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10     exit 0;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1111}
    1212
     
    1414if ( $@ ) {
    1515    plan skip_all => "Test::HTML::Content not installed";
    16     exit 0;
    1716}
    1817
  • trunk/t/43_preview_edits.t

    r939 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10     exit 0;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1111}
    1212
     
    1414if ( $@ ) {
    1515    plan skip_all => "Test::HTML::Content not installed";
    16     exit 0;
    1716}
    1817
  • trunk/t/44_node_image.t

    r944 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10     exit 0;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1111}
    1212
    1313eval { require Test::HTML::Content; };
    1414if ( $@ ) {
    15     plan skip_all => "Test::HTML::Content not installed";
    16     exit 0;
     15    plan skip_all => "Test::HTML::Content not installed.";
    1716}
    1817
  • trunk/t/45_home_recent_changes.t

    r944 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10     exit 0;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1111}
    1212
  • trunk/t/51_display_node.t

    r954 r956  
    88my $have_sqlite = $@ ? 0 : 1;
    99
    10 SKIP: {
    11     skip "DBD::SQLite not installed - no database to test with", 5
    12       unless $have_sqlite;
     10if ( $@ ) {
     11    my ($error) = $@ =~ /^(.*?)\n/;
     12    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
     13}
    1314
    14     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    15     my $config = OpenGuides::Config->new(
    16            vars => {
    17                      dbtype             => "sqlite",
    18                      dbname             => "t/node.db",
    19                      indexing_directory => "t/indexes",
    20                      script_name        => "wiki.cgi",
    21                      script_url         => "http://example.com/",
    22                      site_name          => "Test Site",
    23                      template_path      => "./templates",
    24                      home_name          => "Home",
    25                    }
    26     );
    27     eval { require Wiki::Toolkit::Search::Plucene; };
    28     if ( $@ ) { $config->use_plucene ( 0 ) };
     15plan tests => 7;
    2916
    30     my $guide = OpenGuides->new( config => $config );
    31     isa_ok( $guide, "OpenGuides" );
    32     my $wiki = $guide->wiki;
    33     isa_ok( $wiki, "Wiki::Toolkit" );
    34     $wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } );
    35     my $output = eval {
    36         $guide->display_node( id => "Test Page", return_output => 1 );
    37     };
    38     is( $@, "", "->display_node doesn't die" );
     17Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     18my $config = OpenGuides::Config->new(
     19       vars => {
     20                 dbtype             => "sqlite",
     21                 dbname             => "t/node.db",
     22                 indexing_directory => "t/indexes",
     23                 script_name        => "wiki.cgi",
     24                 script_url         => "http://example.com/",
     25                 site_name          => "Test Site",
     26                 template_path      => "./templates",
     27                 home_name          => "Home",
     28               }
     29);
     30eval { require Wiki::Toolkit::Search::Plucene; };
     31if ( $@ ) { $config->use_plucene ( 0 ) };
    3932
    40     like( $output, qr{\<a.*?\Qhref="alternate.cgi?id=Test_Page;action=edit"\E>Edit\s+this\s+page</a>}, "...and edit link is redirected to source URL" );
    41     $config->home_name( "My Home Page" );
    42     $output = $guide->display_node( return_output => 1 );
    43     like( $output, qr/My\s+Home\s+Page/, "...and defaults to the home node, and takes notice of what we want to call it" );
    44     like( $output, qr{\Q<a href="wiki.cgi?action=edit;id=My_Home_Page"\E>Edit\s+this\s+page</a>}, "...and home page has an edit link" );
    45     my %tt_vars = $guide->display_node( return_tt_vars => 1 );
    46     ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" );
    47 }
     33my $guide = OpenGuides->new( config => $config );
     34isa_ok( $guide, "OpenGuides" );
     35my $wiki = $guide->wiki;
     36isa_ok( $wiki, "Wiki::Toolkit" );
     37$wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } );
     38my $output = eval {
     39    $guide->display_node( id => "Test Page", return_output => 1 );
     40};
     41is( $@, "", "->display_node doesn't die" );
     42
     43like( $output, qr{\<a.*?\Qhref="alternate.cgi?id=Test_Page;action=edit"\E>Edit\s+this\s+page</a>}, "...and edit link is redirected to source URL" );
     44$config->home_name( "My Home Page" );
     45$output = $guide->display_node( return_output => 1 );
     46like( $output, qr/My\s+Home\s+Page/, "...and defaults to the home node, and takes notice of what we want to call it" );
     47like( $output, qr{\Q<a href="wiki.cgi?action=edit;id=My_Home_Page"\E>Edit\s+this\s+page</a>}, "...and home page has an edit link" );
     48my %tt_vars = $guide->display_node( return_tt_vars => 1 );
     49ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" );
  • trunk/t/52_display_diffs.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 5;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
     14plan tests => 5;
    1515
    16 SKIP: {
    17     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    18     my $config = OpenGuides::Test->make_basic_config;
    19     my $guide = OpenGuides->new( config => $config );
    20     my $wiki = $guide->wiki;
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18my $guide = OpenGuides->new( config => $config );
     19my $wiki = $guide->wiki;
    2120
    22     # Clear out the database from any previous runs.
    23     foreach my $del_node ( $wiki->list_all_nodes ) {
    24         print "# Deleting node $del_node\n";
    25         $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
    26     }
     21# Clear out the database from any previous runs.
     22foreach my $del_node ( $wiki->list_all_nodes ) {
     23    print "# Deleting node $del_node\n";
     24    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     25}
    2726
    28     $wiki->write_node( "I Like Pie", "Best pie is meat pie." )
    29       or die "Couldn't write node";
    30     my %data = $wiki->retrieve_node( "I Like Pie" );
    31     $wiki->write_node( "I Like Pie", "Best pie is apple pie.",
    32                        $data{checksum} )
    33       or die "Couldn't write node";
    34     %data = $wiki->retrieve_node( "I Like Pie" );
    35     $wiki->write_node( "I Like Pie", "Best pie is lentil pie.",
    36                        $data{checksum} )
    37       or die "Couldn't write node";
     27$wiki->write_node( "I Like Pie", "Best pie is meat pie." )
     28  or die "Couldn't write node";
     29my %data = $wiki->retrieve_node( "I Like Pie" );
     30$wiki->write_node( "I Like Pie", "Best pie is apple pie.",
     31                   $data{checksum} )
     32  or die "Couldn't write node";
     33%data = $wiki->retrieve_node( "I Like Pie" );
     34$wiki->write_node( "I Like Pie", "Best pie is lentil pie.",
     35                   $data{checksum} )
     36  or die "Couldn't write node";
    3837
    39     my $output = eval {
    40         $guide->display_diffs(
    41                                id            => "I Like Pie",
    42                                version       => 3,
    43                                other_version => 2,
    44                                return_output => 1,
    45                              );
    46     };
    47     is( $@, "", "->display_diffs doesn't die" );
    48     like( $output,
    49           qr/differences between version 2 and version 3/i,
    50           "...version numbers included in output" );
    51     like( $output, qr|<span class="node_name">I Like Pie</span>|,
    52           "...node name inlined in output" );
    53     unlike( $output, qr/contents are identical/i,
    54             "...'contents are identical' not printed when contents differ" );
    55     like( $output, qr/<th.*Version\s+2.*Version\s+3.*apple.*lentil/s,
    56           "...versions are right way round" );
    57 }
     38my $output = eval {
     39    $guide->display_diffs(
     40                           id            => "I Like Pie",
     41                           version       => 3,
     42                           other_version => 2,
     43                           return_output => 1,
     44                         );
     45};
     46is( $@, "", "->display_diffs doesn't die" );
     47like( $output,
     48      qr/differences between version 2 and version 3/i,
     49      "...version numbers included in output" );
     50like( $output, qr|<span class="node_name">I Like Pie</span>|,
     51      "...node name inlined in output" );
     52unlike( $output, qr/contents are identical/i,
     53        "...'contents are identical' not printed when contents differ" );
     54like( $output, qr/<th.*Version\s+2.*Version\s+3.*apple.*lentil/s,
     55      "...versions are right way round" );
  • trunk/t/53_show_index.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 23; # 25 when all enabled
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
     14plan tests => 23; # 25 when all enabled
     15
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18$config->script_name( "wiki.cgi" );
     19$config->script_url( "http://example.com/" );
     20my $guide = OpenGuides->new( config => $config );
     21isa_ok( $guide, "OpenGuides" );
     22my $wiki = $guide->wiki;
     23isa_ok( $wiki, "Wiki::Toolkit" );
     24
     25# Clear out the database from any previous runs.
     26foreach my $del_node ( $wiki->list_all_nodes ) {
     27    print "# Deleting node $del_node\n";
     28    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     29}
     30
     31$wiki->write_node( "Test Page", "foo", undef,
     32                   { category => "Alpha", latitude=>51.754349, longitude=>-1.258200 } )
     33  or die "Couldn't write node";
     34$wiki->write_node( "Test Page 2", "foo", undef,
     35                   { category => "Alpha" } )
     36  or die "Couldn't write node";
     37
     38# Test the normal, HTML version
     39my $output = eval {
     40    $guide->show_index(
     41                        type          => "category",
     42                        value         => "Alpha",
     43                        return_output => 1,
     44                      );
     45};
     46is( $@, "", "->show_index doesn't die" );
     47like( $output, qr|wiki.cgi\?Test_Page|,
     48      "...and includes correct links" );
     49unlike( $output, qr|<title>\s*-|, "...sets <title> correctly" );
     50
     51# Test the RDF version
     52$output = $guide->show_index(
     53                              type          => "category",
     54                              value         => "Alpha",
     55                              return_output => 1,
     56                              format        => "rdf"
     57                            );
     58like( $output, qr|Content-Type: application/rdf\+xml|,
     59      "RDF output gets content-type of application/rdf+xml" );
     60like( $output, qr|<rdf:RDF|, "Really is rdf" );
     61like( $output, qr|<dc:title>Category Alpha</dc:title>|, "Right rdf title" );
     62my @entries = ($output =~ /(\<rdf\:li\>)/g);
     63is( 2, scalar @entries, "Right number of nodes included in rdf" );
     64
     65# Test the RSS version
     66$output = eval {
     67    $guide->show_index(
     68                        type          => "category",
     69                        value         => "Alpha",
     70                        return_output => 1,
     71                        format        => "rss",
     72                      );
     73};
     74is( $@, "", "->show_index doesn't die when asked for rss" );
     75like( $output, qr|Content-Type: application/rdf\+xml|,
     76      "RSS output gets content-type of application/rdf+xml" );
     77like( $output, "/\<rdf\:RDF.*?http\:\/\/purl.org\/rss\//s", "Really is rss" );
     78#like( $output, qr|<title>Category Alpha</title>|, "Right rss title" );
     79@entries = ($output =~ /(\<\/item\>)/g);
     80is( 2, scalar @entries, "Right number of nodes included in rss" );
     81
     82# Test the Atom version
     83$output = eval {
     84    $guide->show_index(
     85                        type          => "category",
     86                        value         => "Alpha",
     87                        return_output => 1,
     88                        format        => "atom",
     89                      );
     90};
     91is( $@, "", "->show_index doesn't die when asked for atom" );
     92like( $output, qr|Content-Type: application/atom\+xml|,
     93      "Atom output gets content-type of application/atom+xml" );
     94like( $output, qr|<feed|, "Really is atom" );
     95#like( $output, qr|<title>Category Alpha</title>|, "Right atom title" );
     96@entries = ($output =~ /(\<entry\>)/g);
     97is( 2, scalar @entries, "Right number of nodes included in atom" );
     98
     99
     100# Test the map version
     101# They will need a Helmert Transform provider for this to work
     102$config->gmaps_api_key("yes I have one");
     103$config->geo_handler(1);
     104$config->force_wgs84(0);
     105
     106my $has_helmert = 0;
     107eval {
     108    use OpenGuides::Utils;
     109    $has_helmert = OpenGuides::Utils->get_wgs84_coords(latitude=>1,longitude=>1,config=>$config);
     110};
     111
    15112SKIP: {
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     $config->script_name( "wiki.cgi" );
    19     $config->script_url( "http://example.com/" );
    20     my $guide = OpenGuides->new( config => $config );
    21     isa_ok( $guide, "OpenGuides" );
    22     my $wiki = $guide->wiki;
    23     isa_ok( $wiki, "Wiki::Toolkit" );
     113    skip "No Helmert Transform provider installed, can't test geo stuff", 6
     114      unless $has_helmert;
    24115
    25     # Clear out the database from any previous runs.
    26     foreach my $del_node ( $wiki->list_all_nodes ) {
    27         print "# Deleting node $del_node\n";
    28         $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
    29     }
    30 
    31     $wiki->write_node( "Test Page", "foo", undef,
    32                        { category => "Alpha", latitude=>51.754349, longitude=>-1.258200 } )
    33       or die "Couldn't write node";
    34     $wiki->write_node( "Test Page 2", "foo", undef,
    35                        { category => "Alpha" } )
    36       or die "Couldn't write node";
    37 
    38     # Test the normal, HTML version
    39     my $output = eval {
     116    $output = eval {
    40117        $guide->show_index(
    41                             type          => "category",
    42                             value         => "Alpha",
    43118                            return_output => 1,
     119                            format        => "map",
    44120                          );
    45121    };
    46     is( $@, "", "->show_index doesn't die" );
    47     like( $output, qr|wiki.cgi\?Test_Page|,
    48           "...and includes correct links" );
    49     unlike( $output, qr|<title>\s*-|, "...sets <title> correctly" );
     122    is( $@, "", "->show_index doesn't die when asked for map" );
     123    like( $output, qr|Content-Type: text/html|,
     124          "Map output gets content-type of text/html" );
     125    like( $output, qr|new GMap|, "Really is google map" );
     126    my @points = ($output =~ /point\d+ = (new GPoint\(.*?, .*?\))/g);
     127    is( 1, scalar @points, "Right number of nodes included on map" );
    50128
    51     # Test the RDF version
    52     $output = $guide->show_index(
    53                                   type          => "category",
    54                                   value         => "Alpha",
    55                                   return_output => 1,
    56                                   format        => "rdf"
    57                                 );
    58     like( $output, qr|Content-Type: application/rdf\+xml|,
    59           "RDF output gets content-type of application/rdf+xml" );
    60     like( $output, qr|<rdf:RDF|, "Really is rdf" );
    61     like( $output, qr|<dc:title>Category Alpha</dc:title>|, "Right rdf title" );
    62     my @entries = ($output =~ /(\<rdf\:li\>)/g);
    63     is( 2, scalar @entries, "Right number of nodes included in rdf" );
    64 
    65     # Test the RSS version
    66     $output = eval {
    67         $guide->show_index(
    68                             type          => "category",
    69                             value         => "Alpha",
    70                             return_output => 1,
    71                             format        => "rss",
    72                           );
    73     };
    74     is( $@, "", "->show_index doesn't die when asked for rss" );
    75     like( $output, qr|Content-Type: application/rdf\+xml|,
    76           "RSS output gets content-type of application/rdf+xml" );
    77     like( $output, "/\<rdf\:RDF.*?http\:\/\/purl.org\/rss\//s", "Really is rss" );
    78     #like( $output, qr|<title>Category Alpha</title>|, "Right rss title" );
    79     @entries = ($output =~ /(\<\/item\>)/g);
    80     is( 2, scalar @entries, "Right number of nodes included in rss" );
    81 
    82     # Test the Atom version
    83     $output = eval {
    84         $guide->show_index(
    85                             type          => "category",
    86                             value         => "Alpha",
    87                             return_output => 1,
    88                             format        => "atom",
    89                           );
    90     };
    91     is( $@, "", "->show_index doesn't die when asked for atom" );
    92     like( $output, qr|Content-Type: application/atom\+xml|,
    93           "Atom output gets content-type of application/atom+xml" );
    94     like( $output, qr|<feed|, "Really is atom" );
    95     #like( $output, qr|<title>Category Alpha</title>|, "Right atom title" );
    96     @entries = ($output =~ /(\<entry\>)/g);
    97     is( 2, scalar @entries, "Right number of nodes included in atom" );
    98 
    99 
    100     # Test the map version
    101     # They will need a Helmert Transform provider for this to work
    102     $config->gmaps_api_key("yes I have one");
    103     $config->geo_handler(1);
    104     $config->force_wgs84(0);
    105 
    106     my $has_helmert = 0;
    107     eval {
    108         use OpenGuides::Utils;
    109         $has_helmert = OpenGuides::Utils->get_wgs84_coords(latitude=>1,longitude=>1,config=>$config);
    110     };
    111 
    112     SKIP: {
    113         skip "No Helmert Transform provider installed, can't test geo stuff", 6
    114           unless $has_helmert;
    115 
    116         $output = eval {
    117             $guide->show_index(
    118                                 return_output => 1,
    119                                 format        => "map",
    120                               );
    121         };
    122         is( $@, "", "->show_index doesn't die when asked for map" );
    123         like( $output, qr|Content-Type: text/html|,
    124               "Map output gets content-type of text/html" );
    125         like( $output, qr|new GMap|, "Really is google map" );
    126         my @points = ($output =~ /point\d+ = (new GPoint\(.*?, .*?\))/g);
    127         is( 1, scalar @points, "Right number of nodes included on map" );
    128 
    129         # -1.259687,51.754813
    130         like( $points[0], qr|51.75481|, "Has latitude");
    131         like( $points[0], qr|-1.25968|, "Has longitude");
    132     }
     129    # -1.259687,51.754813
     130    like( $points[0], qr|51.75481|, "Has latitude");
     131    like( $points[0], qr|-1.25968|, "Has longitude");
    133132}
  • trunk/t/54_redirect.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 2;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
    15 SKIP: {
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Config->new(
    18            vars => {
    19                      dbtype             => "sqlite",
    20                      dbname             => "t/node.db",
    21                      indexing_directory => "t/indexes",
    22                      script_name        => "wiki.cgi",
    23                      script_url         => "http://example.com/",
    24                      site_name          => "Test Site",
    25                      template_path      => "./templates",
    26                    }
    27     );
    28     eval { require Wiki::Toolkit::Search::Plucene; };
    29     if ( $@ ) { $config->use_plucene ( 0 ) };
    30            
    31     my $guide = OpenGuides->new( config => $config );
    32     my $wiki = $guide->wiki;
     14plan tests => 2;
    3315
    34     # Clear out the database from any previous runs.
    35     foreach my $del_node ( $wiki->list_all_nodes ) {
    36         $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
    37     }
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Config->new(
     18       vars => {
     19                 dbtype             => "sqlite",
     20                 dbname             => "t/node.db",
     21                 indexing_directory => "t/indexes",
     22                 script_name        => "wiki.cgi",
     23                 script_url         => "http://example.com/",
     24                 site_name          => "Test Site",
     25                 template_path      => "./templates",
     26               }
     27);
     28eval { require Wiki::Toolkit::Search::Plucene; };
     29if ( $@ ) { $config->use_plucene ( 0 ) };
     30       
     31my $guide = OpenGuides->new( config => $config );
     32my $wiki = $guide->wiki;
    3833
    39     $wiki->write_node( "Test Page", "#REDIRECT [[Test Page 2]]" )
    40       or die "Can't write node";
    41     $wiki->write_node( "Test Page 2", "foo" )
    42       or die "Can't write node";
    43     my $output = eval {
    44         $guide->display_node( id => "Test Page", return_output => 1 );
    45     };
    46     is( $@, "", "->display_node doesn't die when page is a redirect" );
     34# Clear out the database from any previous runs.
     35foreach my $del_node ( $wiki->list_all_nodes ) {
     36    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     37}
    4738
    48     # Old versions of CGI.pm mistakenly print location: instead of Location:
    49     like( $output,
    50           qr/[lL]ocation: http:\/\/example.com\/wiki.cgi\?id=Test_Page_2\;oldid=Test_Page/,
    51           "...and redirects to the right place" );
    52 }
     39$wiki->write_node( "Test Page", "#REDIRECT [[Test Page 2]]" )
     40  or die "Can't write node";
     41$wiki->write_node( "Test Page 2", "foo" )
     42  or die "Can't write node";
     43my $output = eval {
     44    $guide->display_node( id => "Test Page", return_output => 1 );
     45};
     46is( $@, "", "->display_node doesn't die when page is a redirect" );
     47
     48# Old versions of CGI.pm mistakenly print location: instead of Location:
     49like( $output,
     50      qr/[lL]ocation: http:\/\/example.com\/wiki.cgi\?id=Test_Page_2\;oldid=Test_Page/,
     51      "...and redirects to the right place" );
  • trunk/t/55_node_history.t

    r949 r956  
    66eval { require DBD::SQLite; };
    77
    8 if ($@) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10 } else {
    11     plan tests => 2;
     8if ( $@ ) {
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1211}
    1312
    14 SKIP: {
    15     Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     $config->script_name( "mywiki.cgi" );
    19     $config->script_url( "http://example.com/" );
    20     my $guide = OpenGuides->new( config => $config );
     13plan tests => 2;
    2114
    22     $guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { comment => "<myfaketag>" } ) or die "Can't write node";
    23     my %data = $guide->wiki->retrieve_node( "South Croydon Station" );
    24     $guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", $data{checksum}, { comment => "<myfaketag>" } ) or die "Can't write node";
     15Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18$config->script_name( "mywiki.cgi" );
     19$config->script_url( "http://example.com/" );
     20my $guide = OpenGuides->new( config => $config );
    2521
    26     my $output = $guide->display_node(
    27                                        id => "South Croydon Station",
    28                                        version => 1,
    29                                        return_output => 1,
    30                                      );
    31     like( $output, qr'South_Croydon_Station',
    32           "node param escaped properly in links in historic view" );
    33     unlike( $output, qr'South%20Croydon%20Station',
    34             "...in all links" );
    35 }
     22$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { comment => "<myfaketag>" } ) or die "Can't write node";
     23my %data = $guide->wiki->retrieve_node( "South Croydon Station" );
     24$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", $data{checksum}, { comment => "<myfaketag>" } ) or die "Can't write node";
    3625
     26my $output = $guide->display_node(
     27                                   id => "South Croydon Station",
     28                                   version => 1,
     29                                   return_output => 1,
     30                                 );
     31like( $output, qr'South_Croydon_Station',
     32      "node param escaped properly in links in historic view" );
     33unlike( $output, qr'South%20Croydon%20Station',
     34        "...in all links" );
     35
  • trunk/t/56_diffs_with_macros.t

    r785 r956  
    88eval { require DBD::SQLite; };
    99if ( $@ ) {
    10     plan skip_all => "DBD::SQLite not installed";
    11     exit 0;
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1212}
    1313
  • trunk/t/61_bug_textareas.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 1;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
    15 SKIP: {
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
     14plan tests => 1;
    1915
    20     my $out = OpenGuides::Template->output(
    21         wiki     => $wiki,
    22         config   => $config,
    23         template => "edit_form.tt",
    24         vars     => {
    25                       locales  => [
    26                                     { name => "Barville" },
    27                                     { name => "Fooville" },
    28                                   ],
    29                     },
    30     );
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    3119
    32     like( $out, qr/Barville\nFooville/,
    33          "locales properly separated in textarea" );
    34 }
     20my $out = OpenGuides::Template->output(
     21    wiki     => $wiki,
     22    config   => $config,
     23    template => "edit_form.tt",
     24    vars     => {
     25                  locales  => [
     26                                { name => "Barville" },
     27                                { name => "Fooville" },
     28                              ],
     29                },
     30);
    3531
    36 
     32like( $out, qr/Barville\nFooville/,
     33     "locales properly separated in textarea" );
  • trunk/t/62_bug_trailing_whitespace.t

    r785 r956  
    77
    88eval { require DBD::SQLite; };
     9
    910if ( $@ ) {
    10     plan skip_all => "DBD::SQLite not installed";
    11     exit 0;
     11    my ($error) = $@ =~ /^(.*?)\n/;
     12    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1213}
    1314
  • trunk/t/63_bug_map_link_no_address.t

    r949 r956  
    66eval { require DBD::SQLite; };
    77
    8 if ($@) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10 } else {
    11     plan tests => 1;
     8if ( $@ ) {
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1211}
    1312
    14 SKIP: {
    15     Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     my $guide = OpenGuides->new( config => $config );
     13plan tests => 1;
    1914
    20     $guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { map_link => "http://www.streetmap.co.uk/newmap.srf?x=532804&y=164398&z=1" } ) or die "Couldn't write node";
     15Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18my $guide = OpenGuides->new( config => $config );
    2119
    22     my $output = $guide->display_node(
    23                                        id => "South Croydon Station",
    24                                        return_output => 1,
    25                                      );
    26     like( $output, qr/Map of this place/, "map link included when no address" );
    27 }
     20$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { map_link => "http://www.streetmap.co.uk/newmap.srf?x=532804&y=164398&z=1" } ) or die "Couldn't write node";
    2821
     22my $output = $guide->display_node(
     23                                   id => "South Croydon Station",
     24                                   return_output => 1,
     25                                 );
     26like( $output, qr/Map of this place/, "map link included when no address" );
     27
  • trunk/t/64_bug_node_history.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 1;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
    15 SKIP: {
     14plan tests => 1;
    1615
    17     Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    18     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    19     my $config = OpenGuides::Config->new(
    20            vars => {
    21                      dbtype             => "sqlite",
    22                      dbname             => "t/node.db",
    23                      indexing_directory => "t/indexes",
    24                      script_url         => "http://wiki.example.com/",
    25                      script_name        => "mywiki.cgi",
    26                      site_name          => "Wiki::Toolkit Test Site",
    27                      template_path      => cwd . "/templates",
    28                    }
    29     );
    30     eval { require Wiki::Toolkit::Search::Plucene; };
    31     if ( $@ ) { $config->use_plucene ( 0 ) };
     16Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
     17Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     18my $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                 template_path      => cwd . "/templates",
     27               }
     28);
     29eval { require Wiki::Toolkit::Search::Plucene; };
     30if ( $@ ) { $config->use_plucene ( 0 ) };
    3231
    33     my $guide = OpenGuides->new( config => $config );
     32my $guide = OpenGuides->new( config => $config );
    3433
    35     $guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { comment => "<myfaketag>" } ) or die "Can't write node";
    36     my %data = $guide->wiki->retrieve_node( "South Croydon Station" );
    37     $guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", $data{checksum}, { comment => "<myfaketag>" } ) or die "Can't write node";
     34$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { comment => "<myfaketag>" } ) or die "Can't write node";
     35my %data = $guide->wiki->retrieve_node( "South Croydon Station" );
     36$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", $data{checksum}, { comment => "<myfaketag>" } ) or die "Can't write node";
    3837
    39     my $output = $guide->list_all_versions(
    40                                             id => "South Croydon Station",
    41                                             return_output => 1,
    42                                           );
    43     unlike( $output, qr'<myfaketag>', "HTML escaped in comments" );
    44 }
    45 
     38my $output = $guide->list_all_versions(
     39                                        id => "South Croydon Station",
     40                                        return_output => 1,
     41                                      );
     42unlike( $output, qr'<myfaketag>', "HTML escaped in comments" );
  • trunk/t/65_bug_metadata_escape.t

    r785 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9     plan skip_all => "DBD:SQLite not installed";
    10 } else {
    11     plan tests => 1;
    12 
    13     Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    14     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    15     my $config = OpenGuides::Config->new(
    16            vars => {
    17                      dbtype             => "sqlite",
    18                      dbname             => "t/node.db",
    19                      indexing_directory => "t/indexes",
    20                      script_url         => "http://wiki.example.com/",
    21                      script_name        => "mywiki.cgi",
    22                      site_name          => "Wiki::Toolkit Test Site",
    23                      template_path      => cwd . "/templates",
    24                    }
    25     );
    26     eval { require Wiki::Toolkit::Search::Plucene; };
    27     if ( $@ ) { $config->use_plucene ( 0 ) };
    28 
    29     my $guide = OpenGuides->new( config => $config );
    30 
    31     $guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { phone => "<hr><h1>hello mum</h1><hr>" } ) or die "Can't write node";
    32 
    33     my $output = $guide->display_node(
    34                                        id => "South Croydon Station",
    35                                        return_output => 1,
    36                                      );
    37     unlike( $output, qr'<hr><h1>hello mum</h1><hr>',
    38             "HTML escaped in metadata on node display" );
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    3911}
    4012
     13plan tests => 1;
     14
     15Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Config->new(
     18       vars => {
     19                 dbtype             => "sqlite",
     20                 dbname             => "t/node.db",
     21                 indexing_directory => "t/indexes",
     22                 script_url         => "http://wiki.example.com/",
     23                 script_name        => "mywiki.cgi",
     24                 site_name          => "Wiki::Toolkit Test Site",
     25                 template_path      => cwd . "/templates",
     26               }
     27);
     28eval { require Wiki::Toolkit::Search::Plucene; };
     29if ( $@ ) { $config->use_plucene ( 0 ) };
     30
     31my $guide = OpenGuides->new( config => $config );
     32
     33$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { phone => "<hr><h1>hello mum</h1><hr>" } ) or die "Can't write node";
     34
     35my $output = $guide->display_node(
     36                                   id => "South Croydon Station",
     37                                   return_output => 1,
     38                                 );
     39unlike( $output, qr'<hr><h1>hello mum</h1><hr>',
     40        "HTML escaped in metadata on node display" );
  • trunk/t/66_bug_latlong_representation.t

    r785 r956  
    1010eval { require DBD::SQLite; };
    1111if ( $@ ) {
    12     plan skip_all => "DBD::SQLite not installed";
    13 }
     12    my ($error) = $@ =~ /^(.*?)\n/;
     13    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
     14}
    1415
    1516eval { require Geo::Coordinates::UTM; };
  • trunk/t/67_bug_first_version.t

    r785 r956  
    88eval { require DBD::SQLite; };
    99if ( $@ ) {
    10     plan skip_all => "DBD::SQLite not installed";
    11     exit 0;
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1212}
    1313
  • trunk/t/68_bug_website_displayed.t

    r949 r956  
    66eval { require DBD::SQLite; };
    77
    8 if ($@) {
    9     plan skip_all => "DBD::SQLite not installed - no database to test with";
    10 } else {
    11     plan tests => 1;
     8if ( $@ ) {
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1211}
    1312
    14 SKIP: {
    15     Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     my $guide = OpenGuides->new( config => $config );
     13plan tests => 1;
    1914
    20     $guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { website => "http://www.example.com/" } ) or die "Couldn't write node";
     15Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18my $guide = OpenGuides->new( config => $config );
    2119
    22     my $output = $guide->display_node(
    23                                        id => "South Croydon Station",
    24                                        return_output => 1,
    25                                      );
    26     like( $output, qr#Website:</span> <span class="url"><a href="http://www.example.com/">http://www.example.com/</a>#, "website correctly displayed" );
    27 }
     20$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { website => "http://www.example.com/" } ) or die "Couldn't write node";
    2821
     22my $output = $guide->display_node(
     23                                     id => "South Croydon Station",
     24                                     return_output => 1,
     25                                 );
     26like( $output, qr#Website:</span> <span class="url"><a href="http://www.example.com/">http://www.example.com/</a>#, "website correctly displayed" );
     27
  • trunk/t/70_admin_home.t

    r954 r956  
    66
    77eval { require DBD::SQLite; };
    8 my $have_sqlite = $@ ? 0 : 1;
     8if ( $@ ) {
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
     11}
    912
    10 SKIP: {
    11     skip "DBD::SQLite not installed - no database to test with", 17
    12       unless $have_sqlite;
     13plan tests => 13;
    1314
    14     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    15     my $config = OpenGuides::Test->make_basic_config;
    16     $config->script_name( "wiki.cgi" );
    17     $config->script_url( "http://example.com/" );
    18     my $guide = OpenGuides->new( config => $config );
    19     isa_ok( $guide, "OpenGuides" );
    20     my $wiki = $guide->wiki;
    21     isa_ok( $wiki, "Wiki::Toolkit" );
     15Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     16my $config = OpenGuides::Test->make_basic_config;
     17$config->script_name( "wiki.cgi" );
     18$config->script_url( "http://example.com/" );
     19my $guide = OpenGuides->new( config => $config );
     20isa_ok( $guide, "OpenGuides" );
     21my $wiki = $guide->wiki;
     22isa_ok( $wiki, "Wiki::Toolkit" );
    2223
    23     # Clear out the database from any previous runs.
    24     foreach my $del_node ( $wiki->list_all_nodes ) {
    25         print "# Deleting node $del_node\n";
    26         $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
    27     }
     24# Clear out the database from any previous runs.
     25foreach my $del_node ( $wiki->list_all_nodes ) {
     26    print "# Deleting node $del_node\n";
     27    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     28}
    2829
    2930
    30     # Add 3 different pages, one of which with two versions
    31     $wiki->write_node( "Test Page", "foo", undef,
    32                        { category => "Alpha" } )
    33       or die "Couldn't write node";
    34     $wiki->write_node( "Test Page 2", "foo", undef,
    35                        { category => "Alpha" } )
    36       or die "Couldn't write node";
    37     $wiki->write_node( "Locale Bar", "foo", undef,
    38                        { category => "Locales" } )
    39       or die "Couldn't write locale";
    40     my %data = $wiki->retrieve_node( "Locale Bar" );
    41     $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
    42                        { category => "Locales" } )
    43       or die "Couldn't write locale for the 2nd time";
     31# Add 3 different pages, one of which with two versions
     32$wiki->write_node( "Test Page", "foo", undef,
     33                   { category => "Alpha" } )
     34  or die "Couldn't write node";
     35$wiki->write_node( "Test Page 2", "foo", undef,
     36                   { category => "Alpha" } )
     37  or die "Couldn't write node";
     38$wiki->write_node( "Locale Bar", "foo", undef,
     39                   { category => "Locales" } )
     40  or die "Couldn't write locale";
     41my %data = $wiki->retrieve_node( "Locale Bar" );
     42$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
     43                   { category => "Locales" } )
     44  or die "Couldn't write locale for the 2nd time";
    4445
    4546
    46     # Test the tt vars
    47     my %ttvars = eval {
    48            $guide->display_admin_interface( return_tt_vars=> 1 );
    49     };
    50     is( $@, "", "->display_admin_interface doesn't die" );
     47# Test the tt vars
     48my %ttvars = eval {
     49       $guide->display_admin_interface( return_tt_vars=> 1 );
     50};
     51is( $@, "", "->display_admin_interface doesn't die" );
    5152
    52     is( scalar @{$ttvars{'nodes'}}, 2, "Right number of nodes" );
    53     is( scalar @{$ttvars{'locales'}}, 1, "Right number of locales" );
    54     is( scalar @{$ttvars{'categories'}}, 0, "Right number of categories" );
     53is( scalar @{$ttvars{'nodes'}}, 2, "Right number of nodes" );
     54is( scalar @{$ttvars{'locales'}}, 1, "Right number of locales" );
     55is( scalar @{$ttvars{'categories'}}, 0, "Right number of categories" );
    5556
    56     is( $ttvars{'nodes'}->[0]->{name}, "Test Page", "Right nodes" );
    57     is( $ttvars{'nodes'}->[1]->{name}, "Test Page 2", "Right nodes" );
    58     is( $ttvars{'locales'}->[0]->{name}, "Bar", "Right locale, right name" );
     57is( $ttvars{'nodes'}->[0]->{name}, "Test Page", "Right nodes" );
     58is( $ttvars{'nodes'}->[1]->{name}, "Test Page 2", "Right nodes" );
     59is( $ttvars{'locales'}->[0]->{name}, "Bar", "Right locale, right name" );
    5960
    60     # Test the normal, HTML version
    61     my $output = eval {
    62         $guide->display_admin_interface( return_output=>1 );
    63     };
    64     is( $@, "", "->display_admin_interface doesn't die" );
     61# Test the normal, HTML version
     62my $output = eval {
     63    $guide->display_admin_interface( return_output=>1 );
     64};
     65is( $@, "", "->display_admin_interface doesn't die" );
    6566
    66     like( $output, qr|Site Administration|, "Right page" );
    67     like( $output, qr|Test Page|, "Has nodes" );
    68     like( $output, qr|Bar|, "Has locales" );
    69 }
     67like( $output, qr|Site Administration|, "Right page" );
     68like( $output, qr|Test Page|, "Has nodes" );
     69like( $output, qr|Bar|, "Has locales" );
  • trunk/t/71_missing_metadata.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 26;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
    15 SKIP: {
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     $config->script_name( "wiki.cgi" );
    19     $config->script_url( "http://example.com/" );
    20     my $guide = OpenGuides->new( config => $config );
    21     isa_ok( $guide, "OpenGuides" );
    22     my $wiki = $guide->wiki;
    23     isa_ok( $wiki, "Wiki::Toolkit" );
     14plan tests => 26;
    2415
    25     # Clear out the database from any previous runs.
    26     foreach my $del_node ( $wiki->list_all_nodes ) {
    27         print "# Deleting node $del_node\n";
    28         $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
    29     }
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18$config->script_name( "wiki.cgi" );
     19$config->script_url( "http://example.com/" );
     20my $guide = OpenGuides->new( config => $config );
     21isa_ok( $guide, "OpenGuides" );
     22my $wiki = $guide->wiki;
     23isa_ok( $wiki, "Wiki::Toolkit" );
     24
     25# Clear out the database from any previous runs.
     26foreach my $del_node ( $wiki->list_all_nodes ) {
     27    print "# Deleting node $del_node\n";
     28    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     29}
    3030
    3131
    32     # Add 3 different pages, one of which with two versions
    33     $wiki->write_node( "Test Page", "foo", undef,
    34                        { category => "Alpha", lat=>"" } )
    35       or die "Couldn't write node";
    36     $wiki->write_node( "Test Page 2", "foo2", undef,
    37                        { category => "Alpha", lat=>"22.22" } )
    38       or die "Couldn't write node";
    39     $wiki->write_node( "Test Page 3", "foo33", undef,
    40                        { category => "Alpha" } )
    41       or die "Couldn't write node";
    42     $wiki->write_node( "Category Foo", "foo", undef,
    43                        { category => "Categories", lat=>"-8.77" } )
    44       or die "Couldn't write category";
    45     $wiki->write_node( "Locale Bar", "foo", undef,
    46                        { category => "Locales", lat=>"8.22" } )
    47       or die "Couldn't write locale";
    48     my %data = $wiki->retrieve_node( "Locale Bar" );
    49     $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
    50                        { category => "Locales", lat=>"8.88" } )
    51       or die "Couldn't write locale for the 2nd time";
     32# Add 3 different pages, one of which with two versions
     33$wiki->write_node( "Test Page", "foo", undef,
     34                   { category => "Alpha", lat=>"" } )
     35  or die "Couldn't write node";
     36$wiki->write_node( "Test Page 2", "foo2", undef,
     37                   { category => "Alpha", lat=>"22.22" } )
     38  or die "Couldn't write node";
     39$wiki->write_node( "Test Page 3", "foo33", undef,
     40                   { category => "Alpha" } )
     41  or die "Couldn't write node";
     42$wiki->write_node( "Category Foo", "foo", undef,
     43                   { category => "Categories", lat=>"-8.77" } )
     44  or die "Couldn't write category";
     45$wiki->write_node( "Locale Bar", "foo", undef,
     46                   { category => "Locales", lat=>"8.22" } )
     47  or die "Couldn't write locale";
     48my %data = $wiki->retrieve_node( "Locale Bar" );
     49$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
     50                   { category => "Locales", lat=>"8.88" } )
     51  or die "Couldn't write locale for the 2nd time";
    5252
    5353
    54     # Try without search parameters
    55     my %ttvars = eval {
    56            $guide->show_missing_metadata( return_tt_vars=> 1 );
    57     };
    58     my @nodes;
    59     is( $@, "", "->show_missing_metadata doesn't die" );
     54# Try without search parameters
     55my %ttvars = eval {
     56       $guide->show_missing_metadata( return_tt_vars=> 1 );
     57};
     58my @nodes;
     59is( $@, "", "->show_missing_metadata doesn't die" );
    6060
    61     is( scalar @{$ttvars{'nodes'}}, 0, "No nodes when no search params" );
    62     is( $ttvars{'done_search'}, 0, "Didn't search" );
     61is( scalar @{$ttvars{'nodes'}}, 0, "No nodes when no search params" );
     62is( $ttvars{'done_search'}, 0, "Didn't search" );
    6363
    6464
    65     # Now try searching for those without lat
    66     %ttvars = eval {
    67            $guide->show_missing_metadata(
    68                                     metadata_type => 'lat',
    69                                     return_tt_vars => 1
    70             );
    71     };
     65# Now try searching for those without lat
     66%ttvars = eval {
     67       $guide->show_missing_metadata(
     68                                metadata_type => 'lat',
     69                                return_tt_vars => 1
     70        );
     71};
    7272
    73     @nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
    74     is( scalar @nodes, 2, "Two without / with empty lat" );
    75     is( $ttvars{'done_search'}, 1, "Did search" );
    76     is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
    77     is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
     73@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
     74is( scalar @nodes, 2, "Two without / with empty lat" );
     75is( $ttvars{'done_search'}, 1, "Did search" );
     76is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
     77is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
    7878
    7979
    80     # Now try searching for those without lat=22.22
    81     %ttvars = eval {
    82            $guide->show_missing_metadata(
    83                                     metadata_type => 'lat',
    84                                     metadata_value => '22.22',
    85                                     return_tt_vars => 1
    86             );
    87     };
     80# Now try searching for those without lat=22.22
     81%ttvars = eval {
     82       $guide->show_missing_metadata(
     83                                metadata_type => 'lat',
     84                                metadata_value => '22.22',
     85                                return_tt_vars => 1
     86        );
     87};
    8888
    89     @nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
    90     is( scalar @nodes, 4, "Four without that lat" );
    91     is( $ttvars{'done_search'}, 1, "Did search" );
    92     is( $nodes[0]->{'name'}, "Category Foo", "Right nodes" );
    93     is( $nodes[1]->{'name'}, "Locale Bar", "Right nodes" );
    94     is( $nodes[2]->{'name'}, "Test Page", "Right nodes" );
    95     is( $nodes[3]->{'name'}, "Test Page 3", "Right nodes" );
     89@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
     90is( scalar @nodes, 4, "Four without that lat" );
     91is( $ttvars{'done_search'}, 1, "Did search" );
     92is( $nodes[0]->{'name'}, "Category Foo", "Right nodes" );
     93is( $nodes[1]->{'name'}, "Locale Bar", "Right nodes" );
     94is( $nodes[2]->{'name'}, "Test Page", "Right nodes" );
     95is( $nodes[3]->{'name'}, "Test Page 3", "Right nodes" );
    9696
    9797
    98     # Try again, but exclude locale and category
    99     %ttvars = eval {
    100            $guide->show_missing_metadata(
    101                                     metadata_type => 'lat',
    102                                     metadata_value => '22.22',
    103                                     exclude_locales => 1,
    104                                     exclude_categories => 2,
    105                                     return_tt_vars => 1
    106             );
    107     };
     98# Try again, but exclude locale and category
     99%ttvars = eval {
     100       $guide->show_missing_metadata(
     101                                metadata_type => 'lat',
     102                                metadata_value => '22.22',
     103                                exclude_locales => 1,
     104                                exclude_categories => 2,
     105                                return_tt_vars => 1
     106        );
     107};
    108108
    109     @nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
    110     is( scalar @nodes, 2, "Two without that lat" );
    111     is( $ttvars{'done_search'}, 1, "Did search" );
    112     is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
    113     is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
     109@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
     110is( scalar @nodes, 2, "Two without that lat" );
     111is( $ttvars{'done_search'}, 1, "Did search" );
     112is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
     113is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
    114114
    115115
    116     # Test the normal, HTML version
    117     my $output = eval {
    118         $guide->show_missing_metadata( return_output=>1 );
    119     };
    120     is( $@, "", "->how_missing_metadata doesn't die" );
     116# Test the normal, HTML version
     117my $output = eval {
     118    $guide->show_missing_metadata( return_output=>1 );
     119};
     120is( $@, "", "->how_missing_metadata doesn't die" );
    121121
    122     like( $output, qr|Missing Metadata|, "Right page" );
    123     like( $output, qr|Metadata Type|, "Has prompts" );
    124     unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" );
     122like( $output, qr|Missing Metadata|, "Right page" );
     123like( $output, qr|Metadata Type|, "Has prompts" );
     124unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" );
    125125
    126     $output = eval {
    127         $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' );
    128     };
    129     is( $@, "", "->how_missing_metadata doesn't die" );
    130     like( $output, qr|<h3>Pages</h3>|, "searched" );
    131     like( $output, qr|Test Page|, "had node" );
    132 }
     126$output = eval {
     127    $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' );
     128};
     129is( $@, "", "->how_missing_metadata doesn't die" );
     130like( $output, qr|<h3>Pages</h3>|, "searched" );
     131like( $output, qr|Test Page|, "had node" );
  • trunk/t/72_node_moderation.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 19;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
    15 SKIP: {
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     $config->script_name( "wiki.cgi" );
    19     $config->script_url( "http://example.com/" );
    20     my $guide = OpenGuides->new( config => $config );
    21     isa_ok( $guide, "OpenGuides" );
    22     my $wiki = $guide->wiki;
    23     isa_ok( $wiki, "Wiki::Toolkit" );
     14plan tests => 19;
    2415
    25     # Clear out the database from any previous runs.
    26     foreach my $del_node ( $wiki->list_all_nodes ) {
    27         print "# Deleting node $del_node\n";
    28         $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
    29     }
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18$config->script_name( "wiki.cgi" );
     19$config->script_url( "http://example.com/" );
     20my $guide = OpenGuides->new( config => $config );
     21isa_ok( $guide, "OpenGuides" );
     22my $wiki = $guide->wiki;
     23isa_ok( $wiki, "Wiki::Toolkit" );
     24
     25# Clear out the database from any previous runs.
     26foreach my $del_node ( $wiki->list_all_nodes ) {
     27    print "# Deleting node $del_node\n";
     28    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     29}
    3030
    3131
    32     # Add a page
    33     my $q = CGI->new;
    34     $q->param( -name => "content", -value => "foo" );
    35     $q->param( -name => "categories", -value => "Alpha" );
    36     $q->param( -name => "locales", -value => "" );
    37     $q->param( -name => "phone", -value => "" );
    38     $q->param( -name => "fax", -value => "" );
    39     $q->param( -name => "website", -value => "" );
    40     $q->param( -name => "hours_text", -value => "" );
    41     $q->param( -name => "address", -value => "" );
    42     $q->param( -name => "postcode", -value => "" );
    43     $q->param( -name => "map_link", -value => "" );
    44     $q->param( -name => "os_x", -value => "" );
    45     $q->param( -name => "os_y", -value => "" );
    46     $q->param( -name => "username", -value => "bob" );
    47     $q->param( -name => "comment", -value => "foo" );
    48     $q->param( -name => "edit_type", -value => "Minor tidying" );
    49     $ENV{REMOTE_ADDR} = "127.0.0.1";
     32# Add a page
     33my $q = CGI->new;
     34$q->param( -name => "content", -value => "foo" );
     35$q->param( -name => "categories", -value => "Alpha" );
     36$q->param( -name => "locales", -value => "" );
     37$q->param( -name => "phone", -value => "" );
     38$q->param( -name => "fax", -value => "" );
     39$q->param( -name => "website", -value => "" );
     40$q->param( -name => "hours_text", -value => "" );
     41$q->param( -name => "address", -value => "" );
     42$q->param( -name => "postcode", -value => "" );
     43$q->param( -name => "map_link", -value => "" );
     44$q->param( -name => "os_x", -value => "" );
     45$q->param( -name => "os_y", -value => "" );
     46$q->param( -name => "username", -value => "bob" );
     47$q->param( -name => "comment", -value => "foo" );
     48$q->param( -name => "edit_type", -value => "Minor tidying" );
     49$ENV{REMOTE_ADDR} = "127.0.0.1";
    5050
    51     my $output = $guide->commit_node(
    52                                       return_output => 1,
    53                                       id => "Wombats",
    54                                       cgi_obj => $q,
    55                                     );
     51my $output = $guide->commit_node(
     52                                  return_output => 1,
     53                                  id => "Wombats",
     54                                  cgi_obj => $q,
     55                                );
    5656
    57     # Check it's moderated
    58     my %details = $wiki->retrieve_node("Wombats");
    59     is($details{'moderated'}, 1, "Moderated");
    60     is($wiki->node_required_moderation("Wombats"), 0, "No moderation");
     57# Check it's moderated
     58my %details = $wiki->retrieve_node("Wombats");
     59is($details{'moderated'}, 1, "Moderated");
     60is($wiki->node_required_moderation("Wombats"), 0, "No moderation");
    6161
    62     # Turn on moderation
    63     $wiki->set_node_moderation(
    64                                 name => "Wombats",
    65                                 required => 1,
    66     );
    67     is($wiki->node_required_moderation("Wombats"), 1, "Moderation");
     62# Turn on moderation
     63$wiki->set_node_moderation(
     64                            name => "Wombats",
     65                            required => 1,
     66);
     67is($wiki->node_required_moderation("Wombats"), 1, "Moderation");
    6868
    6969
    70     # Now add a new one, with new categories and locales
    71     $q->param( -name => "categories", -value => "Alpha\r\nBeta" );
    72     $q->param( -name => "locales", -value => "Hello" );
    73     $q->param( -name => "edit_type", -value => "Normal edit" );
    74     $q->param( -name => "checksum", -value => $details{checksum} );
    75     $output = $guide->commit_node(
    76                                       return_output => 1,
    77                                       id => "Wombats",
    78                                       cgi_obj => $q,
    79                                     );
     70# Now add a new one, with new categories and locales
     71$q->param( -name => "categories", -value => "Alpha\r\nBeta" );
     72$q->param( -name => "locales", -value => "Hello" );
     73$q->param( -name => "edit_type", -value => "Normal edit" );
     74$q->param( -name => "checksum", -value => $details{checksum} );
     75$output = $guide->commit_node(
     76                                  return_output => 1,
     77                                  id => "Wombats",
     78                                  cgi_obj => $q,
     79                                );
    8080
    81     # Check that the current version is still 1
    82     %details = $wiki->retrieve_node("Wombats");
    83     is($details{'version'}, 1, "Still on v1");
    84     is($details{'moderated'}, 1, "v1 Moderated");
     81# Check that the current version is still 1
     82%details = $wiki->retrieve_node("Wombats");
     83is($details{'version'}, 1, "Still on v1");
     84is($details{'moderated'}, 1, "v1 Moderated");
    8585
    86     # Check that version 2 isn't moderated
    87     my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2);
    88     is($v2{'version'}, 2, "Is v2");
    89     is($v2{'moderated'}, 0, "Not moderated");
     86# Check that version 2 isn't moderated
     87my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2);
     88is($v2{'version'}, 2, "Is v2");
     89is($v2{'moderated'}, 0, "Not moderated");
    9090
    91     # Check that the new categories and locales aren't there
    92     is(1, $wiki->node_exists("Category Alpha"), "Right Categories");
    93     is(0, $wiki->node_exists("Category Beta"), "Right Categories");
    94     is(0, $wiki->node_exists("Locale Hello"), "Right Locales");
     91# Check that the new categories and locales aren't there
     92is(1, $wiki->node_exists("Category Alpha"), "Right Categories");
     93is(0, $wiki->node_exists("Category Beta"), "Right Categories");
     94is(0, $wiki->node_exists("Locale Hello"), "Right Locales");
    9595
    9696
    97     # Moderate
    98     $guide->moderate_node(
    99                             id       => "Wombats",
    100                             version  => 2,
    101                             password => $guide->config->admin_pass
    102     );
     97# Moderate
     98$guide->moderate_node(
     99                        id       => "Wombats",
     100                        version  => 2,
     101                        password => $guide->config->admin_pass
     102);
    103103
    104104
    105     # Check that the current version is 2
    106     %details = $wiki->retrieve_node(name=>"Wombats");
    107     is($details{'version'}, 2, "Is v2");
    108     is($details{'moderated'}, 1, "Moderated");
     105# Check that the current version is 2
     106%details = $wiki->retrieve_node(name=>"Wombats");
     107is($details{'version'}, 2, "Is v2");
     108is($details{'moderated'}, 1, "Moderated");
    109109
    110     # Check that version 2 is moderated
    111     %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2);
    112     is($v2{'version'}, 2, "Is v2");
    113     is($v2{'moderated'}, 1, "Moderated");
     110# Check that version 2 is moderated
     111%v2 = $wiki->retrieve_node(name=>"Wombats",version=>2);
     112is($v2{'version'}, 2, "Is v2");
     113is($v2{'moderated'}, 1, "Moderated");
    114114
    115     # Check that the new categories and locales exist
    116     is(1, $wiki->node_exists("Category Alpha"), "Right Categories");
    117     is(1, $wiki->node_exists("Category Beta"), "Right Categories");
    118     is(1, $wiki->node_exists("Locale Hello"), "Right Locales");
    119 }
     115# Check that the new categories and locales exist
     116is(1, $wiki->node_exists("Category Alpha"), "Right Categories");
     117is(1, $wiki->node_exists("Category Beta"), "Right Categories");
     118is(1, $wiki->node_exists("Locale Hello"), "Right Locales");
  • trunk/t/73_toggle_moderation.t

    r949 r956  
    77eval { require DBD::SQLite; };
    88
    9 if ($@) {
    10     plan skip_all => "DBD::SQLite not installed - no database to test with";
    11 } else {
    12     plan tests => 14;
     9if ( $@ ) {
     10    my ($error) = $@ =~ /^(.*?)\n/;
     11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1312}
    1413
    15 SKIP: {
    16     Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
    17     my $config = OpenGuides::Test->make_basic_config;
    18     $config->script_name( "wiki.cgi" );
    19     $config->script_url( "http://example.com/" );
    20     my $guide = OpenGuides->new( config => $config );
    21     isa_ok( $guide, "OpenGuides" );
    22     my $wiki = $guide->wiki;
    23     isa_ok( $wiki, "Wiki::Toolkit" );
     14plan tests => 14;
    2415
    25     # Clear out the database from any previous runs.
    26     foreach my $del_node ( $wiki->list_all_nodes ) {
    27         print "# Deleting node $del_node\n";
    28         $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
    29     }
     16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     17my $config = OpenGuides::Test->make_basic_config;
     18$config->script_name( "wiki.cgi" );
     19$config->script_url( "http://example.com/" );
     20my $guide = OpenGuides->new( config => $config );
     21isa_ok( $guide, "OpenGuides" );
     22my $wiki = $guide->wiki;
     23isa_ok( $wiki, "Wiki::Toolkit" );
     24
     25# Clear out the database from any previous runs.
     26foreach my $del_node ( $wiki->list_all_nodes ) {
     27    print "# Deleting node $del_node\n";
     28    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
     29}
    3030
    3131
    32     # Add 3 different pages, one of which with two versions
    33     $wiki->write_node( "Test Page", "foo", undef,
    34                        { category => "Alpha", lat=>"" } )
    35       or die "Couldn't write node";
    36     $wiki->write_node( "Test Page 2", "foo2", undef,
    37                        { category => "Alpha", lat=>"22.22" } )
    38       or die "Couldn't write node";
    39     $wiki->write_node( "Test Page 3", "foo33", undef,
    40                        { category => "Alpha" } )
    41       or die "Couldn't write node";
    42     $wiki->write_node( "Category Foo", "foo", undef,
    43                        { category => "Categories", lat=>"-8.77" } )
    44       or die "Couldn't write category";
    45     $wiki->write_node( "Locale Bar", "foo", undef,
    46                        { category => "Locales", lat=>"8.22" } )
    47       or die "Couldn't write locale";
    48     my %data = $wiki->retrieve_node( "Locale Bar" );
    49     $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
    50                        { category => "Locales", lat=>"8.88" } )
    51       or die "Couldn't write locale for the 2nd time";
     32# Add 3 different pages, one of which with two versions
     33$wiki->write_node( "Test Page", "foo", undef,
     34                   { category => "Alpha", lat=>"" } )
     35  or die "Couldn't write node";
     36$wiki->write_node( "Test Page 2", "foo2", undef,
     37                   { category => "Alpha", lat=>"22.22" } )
     38  or die "Couldn't write node";
     39$wiki->write_node( "Test Page 3", "foo33", undef,
     40                   { category => "Alpha" } )
     41  or die "Couldn't write node";
     42$wiki->write_node( "Category Foo", "foo", undef,
     43                   { category => "Categories", lat=>"-8.77" } )
     44  or die "Couldn't write category";
     45$wiki->write_node( "Locale Bar", "foo", undef,
     46                   { category => "Locales", lat=>"8.22" } )
     47  or die "Couldn't write locale";
     48my %data = $wiki->retrieve_node( "Locale Bar" );
     49$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
     50                   { category => "Locales", lat=>"8.88" } )
     51  or die "Couldn't write locale for the 2nd time";
    5252
    5353
    54     # First up, try with no password
    55     my $output = $guide->set_node_moderation(
    56                                 id => "Test Page 3",
    57                                 moderation_flag => 0,
    58                                 return_output => 1
    59     );
    60     like($output, qr|Change moderation status|, "Confirm page");
    61     like($output, qr|Confirm Moderation|, "Confirm page");
     54# First up, try with no password
     55my $output = $guide->set_node_moderation(
     56                            id => "Test Page 3",
     57                            moderation_flag => 0,
     58                            return_output => 1
     59);
     60like($output, qr|Change moderation status|, "Confirm page");
     61like($output, qr|Confirm Moderation|, "Confirm page");
    6262
    6363
    64     # Now, try with the wrong password
    65     $output = $guide->set_node_moderation(
    66                                 id => "Test Page 3",
    67                                 moderation_flag => 0,
    68                                 password => "I_AM_WRONG",
    69                                 return_output => 1
    70     );
    71     like($output, qr|Incorrect Password|, "Wrong password");
    72     like($output, qr|Incorrect password for page moderation|, "Wrong password");
     64# Now, try with the wrong password
     65$output = $guide->set_node_moderation(
     66                            id => "Test Page 3",
     67                            moderation_flag => 0,
     68                            password => "I_AM_WRONG",
     69                            return_output => 1
     70);
     71like($output, qr|Incorrect Password|, "Wrong password");
     72like($output, qr|Incorrect password for page moderation|, "Wrong password");
    7373
    7474
    75     # Check that "Test Page 3" doesn't have moderation set
    76     my %node = $wiki->retrieve_node("Test Page 3");
    77     is($node{'node_requires_moderation'}, 0, "Doesn't have moderation on by default");
     75# Check that "Test Page 3" doesn't have moderation set
     76my %node = $wiki->retrieve_node("Test Page 3");
     77is($node{'node_requires_moderation'}, 0, "Doesn't have moderation on by default");
    7878
    79     # Set the moderation flag on it to off
    80     $guide->set_node_moderation(
    81                                 id => "Test Page 3",
    82                                 moderation_flag => 0,
    83                                 password => $guide->config->admin_pass
    84     );
    85     %node = $wiki->retrieve_node("Test Page 3");
    86     is($node{'node_requires_moderation'}, 0, "Doesn't have moderation set when called with 0");
     79# Set the moderation flag on it to off
     80$guide->set_node_moderation(
     81                            id => "Test Page 3",
     82                            moderation_flag => 0,
     83                            password => $guide->config->admin_pass
     84);
     85%node = $wiki->retrieve_node("Test Page 3");
     86is($node{'node_requires_moderation'}, 0, "Doesn't have moderation set when called with 0");
    8787
    88     # Set it to on
    89     $guide->set_node_moderation(
    90                                 id => "Test Page 3",
    91                                 moderation_flag => 1,
    92                                 password => $guide->config->admin_pass
    93     );
    94     %node = $wiki->retrieve_node("Test Page 3");
    95     is($node{'node_requires_moderation'}, 1, "Turned on properly");
    96    
    97     # Set it back to off
    98     $guide->set_node_moderation(
    99                                 id => "Test Page 3",
    100                                 moderation_flag => 0,
    101                                 password => $guide->config->admin_pass
    102     );
    103     %node = $wiki->retrieve_node("Test Page 3");
    104     is($node{'node_requires_moderation'}, 0, "Turned off properly");
     88# Set it to on
     89$guide->set_node_moderation(
     90                            id => "Test Page 3",
     91                            moderation_flag => 1,
     92                            password => $guide->config->admin_pass
     93);
     94%node = $wiki->retrieve_node("Test Page 3");
     95is($node{'node_requires_moderation'}, 1, "Turned on properly");
     96
     97# Set it back to off
     98$guide->set_node_moderation(
     99                            id => "Test Page 3",
     100                            moderation_flag => 0,
     101                            password => $guide->config->admin_pass
     102);
     103%node = $wiki->retrieve_node("Test Page 3");
     104is($node{'node_requires_moderation'}, 0, "Turned off properly");
    105105
    106106
    107     # Test we were sent to the right place
    108     $output = $guide->set_node_moderation(
    109                                 id => "Test Page 3",
    110                                 moderation_flag => 0,
    111                                 password => $guide->config->admin_pass,
    112                                 return_output => 1
    113     );
    114     like($output, qr|Location: http://example.com/wiki.cgi\?action=admin;moderation=changed|, "Right location");
    115     like($output, qr|Status: 302|, "Right status");
     107# Test we were sent to the right place
     108$output = $guide->set_node_moderation(
     109                            id => "Test Page 3",
     110                            moderation_flag => 0,
     111                            password => $guide->config->admin_pass,
     112                            return_output => 1
     113);
     114like($output, qr|Location: http://example.com/wiki.cgi\?action=admin;moderation=changed|, "Right location");
     115like($output, qr|Status: 302|, "Right status");
    116116
    117     # And again, but this time with a made up node
    118     $output = $guide->set_node_moderation(
    119                                 id => "THIS PAGE DOES NOT EXIST",
    120                                 moderation_flag => 0,
    121                                 password => $guide->config->admin_pass,
    122                                 return_output => 1
    123     );
    124     like($output, qr|Location: http://example.com/wiki.cgi\?action=admin;moderation=unknown_node|, "Right location");
    125     like($output, qr|Status: 302|, "Right status");
    126 }
     117# And again, but this time with a made up node
     118$output = $guide->set_node_moderation(
     119                            id => "THIS PAGE DOES NOT EXIST",
     120                            moderation_flag => 0,
     121                            password => $guide->config->admin_pass,
     122                            return_output => 1
     123);
     124like($output, qr|Location: http://example.com/wiki.cgi\?action=admin;moderation=unknown_node|, "Right location");
     125like($output, qr|Status: 302|, "Right status");
  • trunk/t/74_ping_plugin.t

    r925 r956  
    77eval { require DBD::SQLite; };
    88if ( $@ ) {
    9   plan skip_all => "DBD::SQLite not installed - no database to test with";
    10 } else {
    11   plan tests => 11;
     9    my ($error) = $@ =~ /^(.*?)\n/;
     10    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
    1211}
     12
     13plan tests => 11;
    1314
    1415eval { require Wiki::Toolkit::Plugin::Ping; };
Note: See TracChangeset for help on using the changeset viewer.