Author: bob Date: 2012-05-05 11:27:25 +0100 (Sat, 05 May 2012) New Revision: 1382
Added: trunk/t/001_load.t trunk/t/002_pod.t trunk/t/101_utils.t trunk/t/102_macros.t trunk/t/103_cookies.t trunk/t/104_recent_changes_cookies.t trunk/t/105_template.t trunk/t/106_test_tester.t trunk/t/107_commit_node.t trunk/t/108_http_headers.t trunk/t/109_autocreate.t trunk/t/200_edit_form.t trunk/t/201_rdf.t trunk/t/202_feed_recent_changes.t trunk/t/203_feed_node_all_versions.t trunk/t/204_feed_node_listings.t trunk/t/205_write_geo_data.t trunk/t/206_geo_data_search_form.t trunk/t/207_geo_data_edit_form.t trunk/t/208_wgs84_coords.t trunk/t/300_search_raw.t trunk/t/301_search.t trunk/t/302_search_simple_metadata.t trunk/t/303_search_advanced_search.t trunk/t/303_search_advanced_search_utm.t trunk/t/304_search_paging.t trunk/t/305_search_two_searches.t trunk/t/306_search_order.t trunk/t/307_search_summaries.t trunk/t/308_search_params.t trunk/t/309_search_form.t trunk/t/400_search_as_feed.t trunk/t/401_deletion.t trunk/t/402_edit_conflict.t trunk/t/403_preview_edits.t trunk/t/404_node_image.t trunk/t/405_home_recent_changes.t trunk/t/406_map_in_node_display.t trunk/t/407_navbar_placement.t trunk/t/408_google_analytics.t trunk/t/409_custom_header.t trunk/t/500_http_response_codes.t trunk/t/501_display_node.t trunk/t/502_display_diffs.t trunk/t/503_show_index.t trunk/t/504_redirect.t trunk/t/505_node_history.t trunk/t/506_diffs_with_macros.t trunk/t/507_random_page.t trunk/t/508_navbar_common_locales_categories.t trunk/t/509_preferences.t trunk/t/601_bug_textareas.t trunk/t/602_bug_trailing_whitespace.t trunk/t/603_bug_map_link_no_address.t trunk/t/604_bug_node_history.t trunk/t/605_bug_metadata_escape.t trunk/t/606_bug_latlong_representation.t trunk/t/607_bug_first_version.t trunk/t/608_bug_website_displayed.t trunk/t/609_bug_zero_geo.t trunk/t/700_admin_home.t trunk/t/701_missing_metadata.t trunk/t/702_node_moderation.t trunk/t/703_toggle_moderation.t trunk/t/704_ping_plugin.t trunk/t/705_revert_user.t trunk/t/706_detect_spam.t trunk/t/707_send_email.t trunk/t/708_about.t trunk/t/709_host_blacklist.t trunk/t/801_node_moderate_whitelist.t trunk/t/802_stylesheet.t trunk/t/803_show_delete_to_admins_only.t trunk/t/804_navbar_admin.t trunk/t/805_universal_edit_link.t trunk/t/806_recent_changes.t trunk/t/807_more_recent_changes.t trunk/t/808_recent_changes_overtime.t trunk/t/809_recent_changes_ip_addr.t trunk/t/900_css_category_locale_classes.t trunk/t/901_username_in_templates.t trunk/t/902_node_name_from_cgi_obj.t trunk/t/903_redirect_without_spaces.t trunk/t/904_leaflet.t trunk/t/905_multiple_index.t trunk/t/906_show_index_form.t trunk/t/templates/105_test.tt Removed: trunk/t/01_load.t trunk/t/02_pod.t trunk/t/11_utils.t trunk/t/12_macros.t trunk/t/13_cookies.t trunk/t/14_recent_changes_cookies.t trunk/t/15_template.t trunk/t/16_test_tester.t trunk/t/17_commit_node.t trunk/t/18_http_headers.t trunk/t/19_autocreate.t trunk/t/20_edit_form.t trunk/t/21_rdf.t trunk/t/22_feed_recent_changes.t trunk/t/23_feed_node_all_versions.t trunk/t/24_feed_node_listings.t trunk/t/25_write_geo_data.t trunk/t/26_geo_data_search_form.t trunk/t/27_geo_data_edit_form.t trunk/t/28_wgs84_coords.t trunk/t/30_search_raw.t trunk/t/31_search.t trunk/t/32_search_simple_metadata.t trunk/t/33_search_advanced_search.t trunk/t/33_search_advanced_search_utm.t trunk/t/34_search_paging.t trunk/t/35_search_two_searches.t trunk/t/36_search_order.t trunk/t/37_search_summaries.t trunk/t/38_search_params.t trunk/t/39_search_form.t trunk/t/40_search_as_feed.t trunk/t/41_deletion.t trunk/t/42_edit_conflict.t trunk/t/43_preview_edits.t trunk/t/44_node_image.t trunk/t/45_home_recent_changes.t trunk/t/46_map_in_node_display.t trunk/t/47_navbar_placement.t trunk/t/48_google_analytics.t trunk/t/49_custom_header.t trunk/t/50_http_response_codes.t trunk/t/51_display_node.t trunk/t/52_display_diffs.t trunk/t/53_show_index.t trunk/t/54_redirect.t trunk/t/55_node_history.t trunk/t/56_diffs_with_macros.t trunk/t/57_random_page.t trunk/t/58_navbar_common_locales_categories.t trunk/t/59_preferences.t trunk/t/61_bug_textareas.t trunk/t/62_bug_trailing_whitespace.t trunk/t/63_bug_map_link_no_address.t trunk/t/64_bug_node_history.t trunk/t/65_bug_metadata_escape.t trunk/t/66_bug_latlong_representation.t trunk/t/67_bug_first_version.t trunk/t/68_bug_website_displayed.t trunk/t/69_bug_zero_geo.t trunk/t/70_admin_home.t trunk/t/71_missing_metadata.t trunk/t/72_node_moderation.t trunk/t/73_toggle_moderation.t trunk/t/74_ping_plugin.t trunk/t/75_revert_user.t trunk/t/76_detect_spam.t trunk/t/77_send_email.t trunk/t/78_about.t trunk/t/79_host_blacklist.t trunk/t/81_node_moderate_whitelist.t trunk/t/82_stylesheet.t trunk/t/83_show_delete_to_admins_only.t trunk/t/84_navbar_admin.t trunk/t/85_universal_edit_link.t trunk/t/86_recent_changes.t trunk/t/87_more_recent_changes.t trunk/t/88_recent_changes_overtime.t trunk/t/89_recent_changes_ip_addr.t trunk/t/90_css_category_locale_classes.t trunk/t/91_username_in_templates.t trunk/t/92_node_name_from_cgi_obj.t trunk/t/93_redirect_without_spaces.t trunk/t/94_leaflet.t trunk/t/95_multiple_index.t trunk/t/96_show_index_form.t trunk/t/templates/15_test.tt Modified: trunk/Changes trunk/MANIFEST Log: renumber tests and a test template. Update MANIFEST to reflect this. closes #297
Modified: trunk/Changes =================================================================== --- trunk/Changes 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/Changes 2012-05-05 10:27:25 UTC (rev 1382) @@ -35,6 +35,7 @@ and sends them back there. Fixed bug with recent changes display when minor edit suppressed (for which we require version 0.80 of Wiki::Toolkit). + Renumber tests so we have more room (#297).
0.66 12 April 2012 All templates now have access to the "username" TT variable.
Modified: trunk/MANIFEST =================================================================== --- trunk/MANIFEST 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/MANIFEST 2012-05-05 10:27:25 UTC (rev 1382) @@ -87,92 +87,92 @@ templates/spam_detected.tt templates/userstats.tt templates/wanted_pages.tt -t/01_load.t -t/02_pod.t -t/11_utils.t -t/12_macros.t -t/13_cookies.t -t/14_recent_changes_cookies.t -t/15_template.t -t/16_test_tester.t -t/17_commit_node.t -t/18_http_headers.t -t/19_autocreate.t -t/20_edit_form.t -t/21_rdf.t -t/22_feed_recent_changes.t -t/23_feed_node_all_versions.t -t/24_feed_node_listings.t -t/25_write_geo_data.t -t/26_geo_data_search_form.t -t/27_geo_data_edit_form.t -t/28_wgs84_coords.t -t/30_search_raw.t -t/31_search.t -t/32_search_simple_metadata.t -t/33_search_advanced_search.t -t/33_search_advanced_search_utm.t -t/34_search_paging.t -t/35_search_two_searches.t -t/36_search_order.t -t/37_search_summaries.t -t/38_search_params.t -t/39_search_form.t -t/40_search_as_feed.t -t/41_deletion.t -t/42_edit_conflict.t -t/43_preview_edits.t -t/44_node_image.t -t/45_home_recent_changes.t -t/46_map_in_node_display.t -t/47_navbar_placement.t -t/48_google_analytics.t -t/49_custom_header.t -t/50_http_response_codes.t -t/51_display_node.t -t/52_display_diffs.t -t/53_show_index.t -t/54_redirect.t -t/55_node_history.t -t/56_diffs_with_macros.t -t/57_random_page.t -t/58_navbar_common_locales_categories.t -t/59_preferences.t -t/61_bug_textareas.t -t/62_bug_trailing_whitespace.t -t/63_bug_map_link_no_address.t -t/64_bug_node_history.t -t/65_bug_metadata_escape.t -t/66_bug_latlong_representation.t -t/67_bug_first_version.t -t/68_bug_website_displayed.t -t/69_bug_zero_geo.t -t/70_admin_home.t -t/71_missing_metadata.t -t/72_node_moderation.t -t/73_toggle_moderation.t -t/74_ping_plugin.t -t/75_revert_user.t -t/76_detect_spam.t -t/77_send_email.t -t/78_about.t -t/79_host_blacklist.t -t/81_node_moderate_whitelist.t -t/82_stylesheet.t -t/83_show_delete_to_admins_only.t -t/84_navbar_admin.t -t/85_universal_edit_link.t -t/86_recent_changes.t -t/87_more_recent_changes.t -t/88_recent_changes_overtime.t -t/89_recent_changes_ip_addr.t -t/90_css_category_locale_classes.t -t/91_username_in_templates.t -t/92_node_name_from_cgi_obj.t -t/93_redirect_without_spaces.t -t/94_leaflet.t -t/95_multiple_index.t -t/96_show_index_form.t -t/templates/15_test.tt +t/001_load.t +t/002_pod.t +t/101_utils.t +t/102_macros.t +t/103_cookies.t +t/104_recent_changes_cookies.t +t/105_template.t +t/106_test_tester.t +t/107_commit_node.t +t/108_http_headers.t +t/109_autocreate.t +t/200_edit_form.t +t/201_rdf.t +t/202_feed_recent_changes.t +t/203_feed_node_all_versions.t +t/204_feed_node_listings.t +t/205_write_geo_data.t +t/206_geo_data_search_form.t +t/207_geo_data_edit_form.t +t/208_wgs84_coords.t +t/300_search_raw.t +t/301_search.t +t/302_search_simple_metadata.t +t/303_search_advanced_search.t +t/303_search_advanced_search_utm.t +t/304_search_paging.t +t/305_search_two_searches.t +t/306_search_order.t +t/307_search_summaries.t +t/308_search_params.t +t/309_search_form.t +t/400_search_as_feed.t +t/401_deletion.t +t/402_edit_conflict.t +t/403_preview_edits.t +t/404_node_image.t +t/405_home_recent_changes.t +t/406_map_in_node_display.t +t/407_navbar_placement.t +t/408_google_analytics.t +t/409_custom_header.t +t/500_http_response_codes.t +t/501_display_node.t +t/502_display_diffs.t +t/503_show_index.t +t/504_redirect.t +t/505_node_history.t +t/506_diffs_with_macros.t +t/507_random_page.t +t/508_navbar_common_locales_categories.t +t/509_preferences.t +t/601_bug_textareas.t +t/602_bug_trailing_whitespace.t +t/603_bug_map_link_no_address.t +t/604_bug_node_history.t +t/605_bug_metadata_escape.t +t/606_bug_latlong_representation.t +t/607_bug_first_version.t +t/608_bug_website_displayed.t +t/609_bug_zero_geo.t +t/700_admin_home.t +t/701_missing_metadata.t +t/702_node_moderation.t +t/703_toggle_moderation.t +t/704_ping_plugin.t +t/705_revert_user.t +t/706_detect_spam.t +t/707_send_email.t +t/708_about.t +t/709_host_blacklist.t +t/801_node_moderate_whitelist.t +t/802_stylesheet.t +t/803_show_delete_to_admins_only.t +t/804_navbar_admin.t +t/805_universal_edit_link.t +t/806_recent_changes.t +t/807_more_recent_changes.t +t/808_recent_changes_overtime.t +t/809_recent_changes_ip_addr.t +t/900_css_category_locale_classes.t +t/901_username_in_templates.t +t/902_node_name_from_cgi_obj.t +t/903_redirect_without_spaces.t +t/904_leaflet.t +t/905_multiple_index.t +t/906_show_index_form.t +t/templates/105_test.tt wiki.cgi META.json
Copied: trunk/t/001_load.t (from rev 1381, trunk/t/01_load.t) =================================================================== --- trunk/t/001_load.t (rev 0) +++ trunk/t/001_load.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,11 @@ +use strict; +use Test::More tests => 8; + +use_ok( "OpenGuides" ); +use_ok( "OpenGuides::CGI" ); +use_ok( "OpenGuides::Config" ); +use_ok( "OpenGuides::Feed" ); +use_ok( "OpenGuides::RDF" ); +use_ok( "OpenGuides::Search" ); +use_ok( "OpenGuides::Template" ); +use_ok( "OpenGuides::Utils" );
Copied: trunk/t/002_pod.t (from rev 1381, trunk/t/02_pod.t) =================================================================== --- trunk/t/002_pod.t (rev 0) +++ trunk/t/002_pod.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,6 @@ +use strict; +use Test::More; +eval "use Test::Pod 1.00"; +plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; +my @poddirs = qw( blib blib/script ); +all_pod_files_ok( all_pod_files( @poddirs ) );
Deleted: trunk/t/01_load.t =================================================================== --- trunk/t/01_load.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/01_load.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,11 +0,0 @@ -use strict; -use Test::More tests => 8; - -use_ok( "OpenGuides" ); -use_ok( "OpenGuides::CGI" ); -use_ok( "OpenGuides::Config" ); -use_ok( "OpenGuides::Feed" ); -use_ok( "OpenGuides::RDF" ); -use_ok( "OpenGuides::Search" ); -use_ok( "OpenGuides::Template" ); -use_ok( "OpenGuides::Utils" );
Deleted: trunk/t/02_pod.t =================================================================== --- trunk/t/02_pod.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/02_pod.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,6 +0,0 @@ -use strict; -use Test::More; -eval "use Test::Pod 1.00"; -plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; -my @poddirs = qw( blib blib/script ); -all_pod_files_ok( all_pod_files( @poddirs ) );
Copied: trunk/t/101_utils.t (from rev 1381, trunk/t/11_utils.t) =================================================================== --- trunk/t/101_utils.t (rev 0) +++ trunk/t/101_utils.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,70 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Utils; +use OpenGuides::Test; +use Test::More tests => 10; + +eval { my $wiki = OpenGuides::Utils->make_wiki_object; }; +ok( $@, "->make_wiki_object croaks if no config param supplied" ); + +eval { my $wiki = OpenGuides::Utils->make_wiki_object( config => "foo" ); }; +ok( $@, "...and if config param isn't an OpenGuides::Config object" ); + +eval { + my $wiki = OpenGuides::Utils->make_wiki_object( + config => OpenGuides::Config->new( file => 'fake' ) + ); +}; + +like( $@, qr/File 'fake' does not exist/, '...and Config::Tiny errors are reported'); + +my $have_sqlite = 1; +my $sqlite_error; + +eval { require DBD::SQLite; }; +if ( $@ ) { + ($sqlite_error) = $@ =~ /^(.*?)\n/; + $have_sqlite = 0; +} + +SKIP: { + skip "DBD::SQLite could not be used - no database to test with. " + . "($sqlite_error)", 7 + unless $have_sqlite; + + # Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + + + my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_url => "", + script_name => "", + } + ); + + eval { require Wiki::Toolkit::Search::Plucene; }; + if ( $@ ) { $config->use_plucene ( 0 ) }; + + my $wiki = eval { + OpenGuides::Utils->make_wiki_object( config => $config ); + }; + is( $@, "", + "...but not with an OpenGuides::Config object with suitable data" ); + isa_ok( $wiki, "Wiki::Toolkit" ); + + ok( $wiki->store, "...and store defined" ); + ok( $wiki->search_obj, "...and search defined" ); + ok( $wiki->formatter, "...and formatter defined" ); + + # Now test ->detect_redirect + is( OpenGuides::Utils->detect_redirect( content => "#REDIRECT [[Foo]]" ), + "Foo", + "->detect_redirect successfully detects redirect content" ); + ok( !OpenGuides::Utils->detect_redirect( content => "Mmmm, tea." ), + "...and successfully detects non-redirect content" ); +}
Copied: trunk/t/102_macros.t (from rev 1381, trunk/t/12_macros.t) =================================================================== --- trunk/t/102_macros.t (rev 0) +++ trunk/t/102_macros.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,207 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 19; + +SKIP: { + # Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + + my $config = OpenGuides::Test->make_basic_config; + my $guide = OpenGuides->new( config => $config ); + my $wiki = $guide->wiki; + + # Test @INDEX_LINK + $wiki->write_node( "Test 1", "@INDEX_LINK [[Category Foo]]" ) + or die "Can't write node"; + $wiki->write_node( "Test 2", "@INDEX_LINK [[Category Bar|Bars]]" ) + or die "Can't write node"; + + my $output; + $output = $guide->display_node( + return_output => 1, + id => "Test 1", + ); + like( $output, qr/View all pages in Category Foo/, + "@INDEX_LINK has right default link text" ); + like( $output, qr/action=index;cat=foo/, "...and URL looks right" ); + + $output = $guide->display_node( + return_output => 1, + id => "Test 2", + ); + like( $output, qr/>Bars</a>/, "Default link text can be overridden" ); + like( $output, qr/action=index;cat=bar/, "...and URL looks right" ); + + # Test @INDEX_LIST + $wiki->write_node( "Test 3", "@INDEX_LIST [[Category Foo]]" ) + or die "Can't write node"; + $wiki->write_node( "Test 4", "@INDEX_LIST [[Locale Bar]]" ) + or die "Can't write node"; + $wiki->write_node( "Test 5", "@INDEX_LIST [[Category Nonexistent]]" ) + or die "Can't write node"; + $wiki->write_node( "Test 6", "@INDEX_LIST [[Locale Nonexistent]]" ) + or die "Can't write node"; + $wiki->write_node( "Wibble", "wibble", undef, + { + category => "foo", + locale => "bar", + } + ) + or die "Can't write node"; + $output = $guide->display_node( + return_output => 1, + id => "Test 3", + ); + like ( $output, qr|<a href=".*">Wibble</a>|, + '@INDEX_LIST works for categories' ); + $output = $guide->display_node( + return_output => 1, + id => "Test 5", + ); + like ( $output, qr|No pages currently in category|, + "...and fails nicely if no pages in category" ); + $output = $guide->display_node( + return_output => 1, + id => "Test 4", + ); + like ( $output, qr|<a href=".*">Wibble</a>|, + '@INDEX_LIST works for locales' ); + $output = $guide->display_node( + return_output => 1, + id => "Test 6", + ); + like ( $output, qr|No pages currently in locale|, + "...and fails nicely if no pages in locale" ); + + # Test @MAP_LINK + OpenGuides::Test->write_data( + guide => $guide, + node => "Test 1", + content => "@MAP_LINK [[Category Foo]]", + return_output => 1, + ); + OpenGuides::Test->write_data( + guide => $guide, + node => "Test 2", + content => "@MAP_LINK [[Category Foo|Map]]", + return_output => 1, + ); + $output = $guide->display_node( + return_output => 1, + id => "Test 1", + ); + like( $output, qr/View map of pages in Category Foo/, + "@MAP_LINK has right default link text" ); + like( $output, qr/\bcat=foo\b/, "...and URL looks right" ); + + $output = $guide->display_node( + return_output => 1, + id => "Test 2", + ); + like( $output, qr/>Map</a>/, "Default link text can be overridden" ); + like( $output, qr/\bcat=foo\b/, "...and URL looks right" ); + + # Test @RANDOM_PAGE_LINK + OpenGuides::Test->write_data( + guide => $guide, + node => "Test Random", + content => "@RANDOM_PAGE_LINK", + return_output => 1, + ); + $output = $guide->display_node( + return_output => 1, + id => "Test Random", + ); + like( $output, qr/View a random page on this guide/, + "@RANDOM_PAGE_LINK has right default link text" ); + + # Not sure yet how to let people override link text in the above. TODO. + + OpenGuides::Test->write_data( + guide => $guide, + node => "Test Random", + content => "@RANDOM_PAGE_LINK " + . "[[Category Pubs]]", + return_output => 1, + ); + $output = $guide->display_node( + return_output => 1, + id => "Test Random", + ); + like( $output, qr/View a random page in Category Pubs/, + "@RANDOM_PAGE_LINK has right default link text for categories" ); + OpenGuides::Test->write_data( + guide => $guide, + node => "Test Random", + content => "@RANDOM_PAGE_LINK " + . "[[Category Pubs|Random pub]]", + return_output => 1, + ); + $output = $guide->display_node( + return_output => 1, + id => "Test Random", + ); + like( $output, qr/>Random pub</a>/, "...and can be overridden" ); + + OpenGuides::Test->write_data( + guide => $guide, + node => "Test Random", + content => "@RANDOM_PAGE_LINK " + . "[[Locale Fulham]]", + return_output => 1, + ); + $output = $guide->display_node( + return_output => 1, + id => "Test Random", + ); + like( $output, qr/View a random page in Locale Fulham/, + "@RANDOM_PAGE_LINK has right default link text for categories" ); + OpenGuides::Test->write_data( + guide => $guide, + node => "Test Random", + content => "@RANDOM_PAGE_LINK " + . "[[Locale Fulham|" + . "Random thing in Fulham]]", + return_output => 1, + ); + $output = $guide->display_node( + return_output => 1, + id => "Test Random", + ); + like( $output, qr/>Random thing in Fulham</a>/, + "...and can be overridden" ); + + # Test @INCLUDE_NODE + OpenGuides::Test->write_data( + guide => $guide, + node => "Test 1", + content => "Hello, I am Test 1!\r\n" + . "@INCLUDE_NODE [[Test 2]]", + return_output => 1, + ); + OpenGuides::Test->write_data( + guide => $guide, + node => "Test 2", + content => "Hello, I am Test 2!", + return_output => 1, + ); + $output = $guide->display_node( + return_output => 1, + id => "Test 1", + ); + like( $output, qr/Hello, I am Test 1!/, + "Node with @INCLUDE_NODE has its own content" ); + like( $output, qr/Hello, I am Test 2!/, + "...and the included content" ); +}
Copied: trunk/t/103_cookies.t (from rev 1381, trunk/t/13_cookies.t) =================================================================== --- trunk/t/103_cookies.t (rev 0) +++ trunk/t/103_cookies.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,116 @@ +use strict; +use OpenGuides::Config; +use OpenGuides::CGI; +use Time::Piece; +use Time::Seconds; +use Test::More tests => 30; + +eval { OpenGuides::CGI->make_prefs_cookie; }; +ok( $@, "->make_prefs_cookie dies if no config object supplied" ); + +eval { OpenGuides::CGI->make_prefs_cookie( config => "foo" ); }; +ok( $@, "...or if config isn't an OpenGuides::Config" ); + +my $config = OpenGuides::Config->new( vars => { site_name => "Test Site" } ); + +eval { OpenGuides::CGI->make_prefs_cookie( config => $config ); }; +is( $@, "", "...but not if it is" ); + +# Use nonsense values here to make sure the test is a good one regardless +# of defaults - can't do this for cookie_expires, unfortunately. +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "un_pref", + include_geocache_link => "gc_pref", + preview_above_edit_box => "pv_pref", + latlong_traditional => "ll_pref", + omit_help_links => "hl_pref", + show_minor_edits_in_rc => "me_pref", + default_edit_type => "et_pref", + cookie_expires => "never", + track_recent_changes_views => "rc_pref", + display_google_maps => "gm_pref", + is_admin => "admin_pref", +); +isa_ok( $cookie, "CGI::Cookie", "->make_prefs_cookie returns a cookie" ); + +my $expiry_string = $cookie->expires; +# Hack off the timezone bit since strptime can't parse it portably. +# Timezones taken from RFC 822. +$expiry_string =~ s/ (UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|1[A-IK-Z]|+\d\d\d\d|-\d\d\d\d)$//; +print "# (String hacked to $expiry_string)\n"; +my $expiry = Time::Piece->strptime( $expiry_string, "%a, %d-%b-%Y %T"); +print "# Expires: " . $cookie->expires . ", ie $expiry\n"; +my $now = localtime; +print "# cookie should still be valid in a year, ie " . ($now + ONE_YEAR) . "\n"; +ok( $expiry - ( $now + ONE_YEAR ) > 0, "cookie expiry date correct" ); + +$ENV{HTTP_COOKIE} = $cookie; + +eval { OpenGuides::CGI->get_prefs_from_cookie; }; +ok( $@, "->get_prefs_from_cookie dies if no config object supplied" ); + +eval { OpenGuides::CGI->get_prefs_from_cookie( config => "foo" ); }; +ok( $@, "...or if config isn't an OpenGuides::Config" ); + +eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); }; +is( $@, "", "...but not if it is" ); + +my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); +is( $prefs{username}, "un_pref", "get_prefs_from_cookie can find username" ); +is( $prefs{include_geocache_link}, "gc_pref", "...and geocache prefs" ); +is( $prefs{preview_above_edit_box}, "pv_pref", "...and preview prefs" ); +is( $prefs{latlong_traditional}, "ll_pref", "...and latlong prefs" ); +is( $prefs{omit_help_links}, "hl_pref", "...and help link prefs" ); +is( $prefs{show_minor_edits_in_rc}, "me_pref", "...and minor edits prefs" ); +is( $prefs{default_edit_type}, "et_pref", "...and default edit prefs" ); +is( $prefs{cookie_expires}, "never", "...and requested cookie expiry" ); +is( $prefs{track_recent_changes_views}, "rc_pref", + "...and recent changes tracking" ); +is( $prefs{display_google_maps}, "gm_pref", + "...and map display preference" ); +is( $prefs{is_admin}, "admin_pref", + "...and admin preference" ); +# Now make sure that true/false preferences are taken account of when +# they're false. +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + include_geocache_link => 0, + preview_above_edit_box => 0, + latlong_traditional => 0, + omit_help_links => 0, + show_minor_edits_in_rc => 0, + track_recent_changes_views => 0, + display_google_maps => 0, + is_admin => 0, +); + +$ENV{HTTP_COOKIE} = $cookie; + +%prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); +ok( !$prefs{include_geocache_link}, "geocache prefs taken note of when false"); +ok( !$prefs{preview_above_edit_box}, "...and preview prefs" ); +ok( !$prefs{latlong_traditional}, "...and latlong prefs" ); +ok( !$prefs{omit_help_links}, "...and help link prefs" ); +ok( !$prefs{show_minor_edits_in_rc}, "...and minor edits prefs" ); +ok( !$prefs{track_recent_changes_views}, "...and recent changes prefs" ); +ok( !$prefs{display_google_maps}, "...and Google Maps prefs" ); +ok( !$prefs{is_admin}, "...and admin prefs" ); + +# Check that cookie parsing fails nicely if no cookie set. +delete $ENV{HTTP_COOKIE}; +%prefs = eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); }; +is( $@, "", "->get_prefs_from_cookie doesn't die if no cookie set" ); +is( keys %prefs, 11, "...and returns ten default values" ); + +# Check that the prefs cookie is still looked for even if we send along a +# non-prefs cookie. +my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( + config => $config ); +my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, is_admin => 1 ); +$ENV{HTTP_COOKIE} = $prefs_cookie; +%prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config, + cookies => [ $rc_cookie ] ); +ok( $prefs{is_admin}, + "->get_prefs_from_cookie still works with ENV if we send RC cookie" );
Copied: trunk/t/104_recent_changes_cookies.t (from rev 1381, trunk/t/14_recent_changes_cookies.t) =================================================================== --- trunk/t/104_recent_changes_cookies.t (rev 0) +++ trunk/t/104_recent_changes_cookies.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,110 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Time::Piece; +use Time::Seconds; +use Test::More tests => 11; + +eval { OpenGuides::CGI->make_recent_changes_cookie; }; +ok( $@, "->make_recent_changes_cookie dies if no config object supplied" ); + +eval { OpenGuides::CGI->make_recent_changes_cookie( config => "foo" ); }; +ok( $@, "...or if config isn't an OpenGuides::Config" ); + +my $config = OpenGuides::Config->new( vars => { site_name => "Test Site" } ); + +eval { OpenGuides::CGI->make_recent_changes_cookie( config => $config ); }; +is( $@, "", "...but not if it is" ); + +my $cookie = OpenGuides::CGI->make_recent_changes_cookie( config => $config ); +isa_ok( $cookie, "CGI::Cookie", + "->make_recent_changes_cookie returns a cookie" ); + +my $expiry_string = $cookie->expires; +# Hack off the timezone bit since strptime can't parse it portably. +# Timezones taken from RFC 822. +$expiry_string =~ s/ (UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|1[A-IK-Z]|+\d\d\d\d|-\d\d\d\d)$//; +print "# (String hacked to $expiry_string)\n"; +my $expiry = Time::Piece->strptime( $expiry_string, "%a, %d-%b-%Y %T"); +print "# Expires: " . $cookie->expires . ", ie $expiry\n"; +my $now = localtime; +print "# cookie should still be valid in a year, ie " . ($now + ONE_YEAR) . "\n"; +ok( $expiry - ( $now + ONE_YEAR ) > 0, "cookie expiry date correct" ); + +$ENV{HTTP_COOKIE} = $cookie; + +eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie; }; +ok( $@, "->get_last_recent_changes_visit_from_cookie dies if no config object supplied" ); + +eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => "foo" ); }; +ok( $@, "...or if config isn't an OpenGuides::Config" ); + +eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); }; +is( $@, "", "...but not if it is" ); + +# Check that cookie parsing fails nicely if no cookie set. +delete $ENV{HTTP_COOKIE}; +eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); }; +is( $@, "", "->get_last_recent_changes_visit_from_cookie doesn't die if no cookie set" ); + +# Now test that the prefs option is taken note of. +my $have_sqlite = 1; +my $sqlite_error; + +eval { require DBD::SQLite; }; +if ( $@ ) { + ($sqlite_error) = $@ =~ /^(.*?)\n/; + $have_sqlite = 0; +} + +SKIP: { + skip "DBD::SQLite could not be used - no database to test with. ($sqlite_error)", 2 + unless $have_sqlite; + OpenGuides::Test::refresh_db(); + + + my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + } + ); + eval { require Wiki::Toolkit::Search::Plucene; }; + if ( $@ ) { $config->use_plucene ( 0 ) }; + + my $guide = OpenGuides->new( config => $config ); + + my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + track_recent_changes_views => 1, + ); + my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( + config => $config + ); + $ENV{HTTP_COOKIE} = $prefs_cookie . "; " . $rc_cookie; + my $output = $guide->display_node( + id => "RecentChanges", + return_output => 1, + ); + like( $output, qr/Set-Cookie:/, "recent changes cookie set when asked" ); + + $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + track_recent_changes_views => 0, + ); + $ENV{HTTP_COOKIE} = $prefs_cookie . "; " . $rc_cookie; + $output = $guide->display_node( + id => "RecentChanges", + return_output => 1, + ); + unlike( $output, qr/Set-Cookie:/, "...and not when not" ); +}
Copied: trunk/t/105_template.t (from rev 1381, trunk/t/15_template.t) =================================================================== --- trunk/t/105_template.t (rev 0) +++ trunk/t/105_template.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,247 @@ +use strict; +use Cwd; +use CGI::Cookie; +use Wiki::Toolkit::Formatter::UseMod; +use OpenGuides; +use OpenGuides::Template; +use OpenGuides::Test; +use Test::More tests => 29; + +my $config = OpenGuides::Test->make_basic_config; +$config->template_path( cwd . "/t/templates" ); +$config->site_name( "Wiki::Toolkit Test Site" ); +$config->script_url( "http://wiki.example.com/" ); +$config->script_name( "mywiki.cgi" ); +$config->contact_email( 'wiki@example.com' ); +$config->stylesheet_url( "http://wiki.example.com/styles.css" ); +$config->home_name( "Home Page" ); +$config->formatting_rules_node( "Rules" ); +$config->formatting_rules_link( "" ); + +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +eval { OpenGuides::Template->output( wiki => $wiki, + config => $config ); }; +ok( $@, "->output croaks if no template file supplied" ); + +eval { + OpenGuides::Template->output( wiki => $wiki, + config => $config, + template => "105_test.tt" ); +}; +is( $@, "", "...but not if one is" ); + +my $output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", + vars => { foo => "bar" } +); +like( $output, qr/^Content-Type: text/html/, + "Content-Type header included and defaults to text/html" ); +like( $output, qr/FOO: bar/, "variables substituted" ); + +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", + content_type => "" +); +unlike( $output, qr/^Content-Type: text/html/, + "Content-Type header omitted if content_type arg explicitly blank" ); + +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", + noheaders => 1, + http_response => 500 +); + +unlike( $output, qr/^Status: /, + "Headers omitted if noheaders arg given" ); + +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "15_idonotexist.tt" +); +like( $output, qr/Failed to process template/, "fails nice on TT error" ); + +# Test TT variables are auto-set from config. +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt" +); + +like( $output, qr/SITE NAME: Wiki::Toolkit Test Site/, "site_name var set" ); +like( $output, qr/CGI URL: mywiki.cgi/, "cgi_url var set" ); +like( $output, qr/FULL CGI URL: http://wiki.example.com/mywiki.cgi/, + "full_cgi_url var set" ); +like( $output, qr/CONTACT EMAIL: wiki@example.com/, "contact_email var set" ); +like( $output, qr/STYLESHEET: http://wiki.example.com/styles.css/, + "stylesheet var set" ); +like( $output, qr/HOME LINK: http://wiki.example.com/mywiki.cgi/, "home_link var set" ); +like( $output, qr/HOME NAME: Home Page/, "home_name var set" ); +like( $output, + qr/FORMATTING RULES LINK: http://wiki.example.com/mywiki.cgi?Rules/, + "formatting_rules_link var set" ); + +# Test openguides_version TT variable. +like( $output, qr/OPENGUIDES VERSION: 0.\d\d/, + "openguides_version set" ); + +# Test TT variables auto-set from node name. +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + node => "Test Node", + template => "105_test.tt" +); + +like( $output, qr/NODE NAME: Test Node/, "node_name var set" ); +like( $output, qr/NODE PARAM: Test_Node/, "node_param var set" ); + +# Test that cookies go in. +my $cookie = CGI::Cookie->new( -name => "x", -value => "y" ); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", + cookies => $cookie +); +like( $output, qr/Set-Cookie: $cookie/, "cookie in header" ); + +# Test that external URLs for text formatting work. +$config = OpenGuides::Config->new( + vars => { + template_path => cwd . '/t/templates', + site_name => 'Wiki::Toolkit Test Site', + script_url => 'http://wiki.example.com/', + script_name => 'mywiki.cgi', + formatting_rules_node => 'Some External Help', + formatting_rules_link => 'http://www.example.com/wikitext', + } +); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt" +); +like ( $output, qr/FORMATTING RULES LINK: http://www.example.com/wikitext/, + "formatting_rules_link var honoured for explicit URLs" ); + +# Test that home_link is set correctly when script_name is blank. +$config = OpenGuides::Config->new( + vars => { + template_path => cwd . '/t/templates', + site_name => 'Wiki::Toolkit Test Site', + script_url => 'http://wiki.example.com/', + script_name => '', + } +); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt" +); +like( $output, qr/HOME LINK: http://wiki.example.com/, + "home_link var set OK when script_name blank" ); + +# Test that full_cgi_url comes out right if the trailing '/' is +# missing from script_url in the config file. +$config = OpenGuides::Config->new( + vars => { + template_path => cwd . '/t/templates', + site_name => 'Wiki::Toolkit Test Site', + script_url => 'http://wiki.example.com', + script_name => 'wiki.cgi', + } +); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt" +); +like( $output, qr/FULL CGI URL: http://wiki.example.com/wiki.cgi/, + "full_cgi_url OK when trailing '/' missed off script_url" ); + +# Test that TT vars are picked up from user cookie prefs. +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + omit_formatting_link => 1, +); +$ENV{HTTP_COOKIE} = $cookie; +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt" +); +like( $output, qr/FORMATTING RULES LINK: /, + "formatting_rules_link TT var blank as set in cookie" ); + +# Test that explicitly supplied vars override vars in cookie. +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", + vars => { omit_formatting_link => "fish" }, +); +like( $output, qr/OMIT FORMATTING LINK: fish/, + "explicitly supplied TT vars override cookie ones" ); + +# Test that enable_page_deletion is set correctly in various circumstances. +$config = OpenGuides::Config->new( + vars => { + template_path => cwd . "/t/templates", + site_name => "Test Site", + script_url => "/", + script_name => "", + }, +); + +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", +); +like( $output, qr/ENABLE PAGE DELETION: 0/, + "enable_page_deletion var set correctly when not specified in conf" ); + +$config->enable_page_deletion( "n" ); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", +); +like( $output, qr/ENABLE PAGE DELETION: 0/, + "enable_page_deletion var set correctly when set to 'n' in conf" ); + +$config->enable_page_deletion( "y" ); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", +); +like( $output, qr/ENABLE PAGE DELETION: 1/, + "enable_page_deletion var set correctly when set to 'y' in conf" ); + +$config->enable_page_deletion( 0 ); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", +); +like( $output, qr/ENABLE PAGE DELETION: 0/, + "enable_page_deletion var set correctly when set to '0' in conf" ); + +$config->enable_page_deletion( 1 ); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "105_test.tt", +); +like( $output, qr/ENABLE PAGE DELETION: 1/, + "enable_page_deletion var set correctly when set to '1' in conf" );
Copied: trunk/t/106_test_tester.t (from rev 1381, trunk/t/16_test_tester.t) =================================================================== --- trunk/t/106_test_tester.t (rev 0) +++ trunk/t/106_test_tester.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,44 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +plan tests => 2; + + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->site_name( "Test Site" ); +my $guide = OpenGuides->new( config => $config ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "London Zoo", + content => "It's a zoo.", + ); +my $wiki = $guide->wiki; +my %data = $wiki->retrieve_node( "London Zoo" ); +is( $data{content}, "It's a zoo.", "first write with write_data went in" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "London Zoo", + content => "It's still a zoo.", + ); +%data = $wiki->retrieve_node( "London Zoo" ); +is( $data{content}, "It's still a zoo.", "...so does second" ); +
Copied: trunk/t/107_commit_node.t (from rev 1381, trunk/t/17_commit_node.t) =================================================================== --- trunk/t/107_commit_node.t (rev 0) +++ trunk/t/107_commit_node.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,108 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Feed; +use OpenGuides::Utils; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +plan tests => 7; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + use_plucene => 1 + } +); + +# Basic sanity check first. +my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + +my $feed = OpenGuides::Feed->new( wiki => $wiki, + config => $config ); + + +# Write the first version +my $guide = OpenGuides->new( config => $config ); + +# Set up CGI parameters ready for a node write. +my $q = OpenGuides::Test->make_cgi_object( + content => "foo", + username => "bob", + comment => "foo", + node_image => "image", + edit_type => "Minor tidying" +); + +my $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check we have it +ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); + +my %node = $wiki->retrieve_node("Wombats"); +is( $node{version}, 1, "First version" ); +is( $node{metadata}->{edit_type}[0], "Minor tidying", "Right edit type" ); + + +# Now write a second version of it +$q->param( -name => "edit_type", -value => "Normal edit" ); +$q->param( -name => "checksum", -value => $node{checksum} ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check it's as expected +%node = $wiki->retrieve_node("Wombats"); +is( $node{version}, 2, "First version" ); +is( $node{metadata}->{edit_type}[0], "Normal edit", "Right edit type" ); + +# Now try to commit some invalid data, and make sure we get an edit form back +$q = OpenGuides::Test->make_cgi_object( + content => "foo", + os_x => "fooooo", + username => "bob", + comment => "foo", + node_image => "image", + edit_type => "Minor tidying" +); + +$output = $guide->commit_node( + return_output => 1, + id => "Wombats again", + cgi_obj => $q, + ); + +like( $output, qr/Your input was invalid/, + "Edit form displayed and invalid input message shown if invalid input" ); + +like( $output, qr/os_x must be integer/, + "Edit form displayed and os_x integer message displayed" );
Copied: trunk/t/108_http_headers.t (from rev 1381, trunk/t/18_http_headers.t) =================================================================== --- trunk/t/108_http_headers.t (rev 0) +++ trunk/t/108_http_headers.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,59 @@ +use strict; +use Cwd; +use OpenGuides; +use OpenGuides::Template; +use OpenGuides::Test; +use Test::More tests => 5; + +my $config = OpenGuides::Test->make_basic_config; +$config->template_path( cwd . "/t/templates" ); + +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +eval { + OpenGuides::Template->output( wiki => $wiki, + config => $config, + template => "15_test.tt" ); +}; +is( $@, "", "is happy doing output" ); + +my $output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "15_test.tt" +); +like( $output, qr/^Content-Type: text/html/, + "Content-Type header included and defaults to text/html" ); + +# Now supply a http charset +$config->http_charset( "UTF-8" ); + +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "15_test.tt" +); +like( $output, qr/^Content-Type: text/html; charset=UTF-8/, + "Content-Type header included charset" ); + +# Suppy charset and content type +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + content_type => "text/xml", + template => "15_test.tt" +); +like( $output, qr/^Content-Type: text/xml; charset=UTF-8/, + "Content-Type header included charset" ); + +# Content type but no charset +$config->http_charset( "" ); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + content_type => "text/xml", + template => "15_test.tt" +); +like( $output, qr/^Content-Type: text/xml/, + "Content-Type header didn't include charset" );
Copied: trunk/t/109_autocreate.t (from rev 1381, trunk/t/19_autocreate.t) =================================================================== --- trunk/t/109_autocreate.t (rev 0) +++ trunk/t/109_autocreate.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,129 @@ +use strict; +use Cwd; +use Wiki::Toolkit::Plugin::Categoriser; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 13; + +my $config = OpenGuides::Test->make_basic_config; +$config->custom_template_path( cwd . "/t/templates/" ); +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; +my $categoriser = Wiki::Toolkit::Plugin::Categoriser->new; +$wiki->register_plugin( plugin => $categoriser ); + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Check that unwelcome characters are stripped from autocreated cats/locales. +# Double spaces: +OpenGuides::Test->write_data( + guide => $guide, + node => "Arbat", + categories => "Delicious Russian Food", + return_output => 1, + ); + +ok( !$wiki->node_exists( "Category Delicious Russian Food" ), + "Categories with double spaces in are not auto-created." ); +ok( $wiki->node_exists( "Category Delicious Russian Food" ), + "...but the corresponding category with single spaces is." ); +ok ( !$categoriser->in_category( node => "Arbat", + category => "Delicious Russian Food" ), + "...and the new node is not in the double-spaced category." ); +ok ( $categoriser->in_category( node => "Arbat", + category => "Delicious Russian Food" ), + "...but it is in the single-spaced one." ); + +# Newlines: +OpenGuides::Test->write_data( + guide => $guide, + node => "Liaison", + categories => "Dim\nSum", + return_output => 1, + ); + +ok( !$wiki->node_exists( "Category Dim\nSum" ), + "Categories with newlines in are not auto-created." ); +ok( $wiki->node_exists( "Category Dim Sum" ), + "...but the corresponding category with single spaces is." ); +ok ( !$categoriser->in_category( node => "Liaison", + category => "Dim\nSum" ), + "...and the new node is not in the newlined category." ); +ok ( $categoriser->in_category( node => "Liaison", + category => "Dim Sum" ), + "...but it is in the single-spaced one." ); + + +# Write a custom template to autofill content in autocreated nodes. +eval { + unlink cwd . "/t/templates/custom_autocreate_content.tt"; +}; +open( FILE, ">", cwd . "/t/templates/custom_autocreate_content.tt" ) + or die $!; +print FILE <<EOF; +Auto-generated list of places in +[% IF index_type == "Category" %]this category[% ELSE %][% index_value %][% END %]: +@INDEX_LIST [[[% node_name %]]] +EOF +close FILE or die $!; + +# Check that autocapitalisation works correctly in categories with hyphens. +OpenGuides::Test->write_data( + guide => $guide, + node => "Vivat Bacchus", + categories => "Restaurants\r\nVegan-friendly", + locales => "Farringdon", + return_output => 1, + ); + +ok( $wiki->node_exists( "Category Vegan-Friendly" ), + "Categories with hyphens in are auto-created correctly." ); + +# Check that the custom autocreate template was picked up. +my $content = $wiki->retrieve_node( "Category Vegan-Friendly" ); +$content =~ s/\s+$//s; +$content =~ s/\s+/ /gs; +is( $content, "Auto-generated list of places in this category: " + . "@INDEX_LIST [[Category Vegan-Friendly]]", + "Custom autocreate template works properly for categories" ); + +$content = $wiki->retrieve_node( "Locale Farringdon" ); +$content =~ s/\s+$//s; +$content =~ s/\s+/ /gs; +is( $content, "Auto-generated list of places in Farringdon: " + . "@INDEX_LIST [[Locale Farringdon]]", + "...and locales" ); + +# Now make sure that we have a fallback if there's no autocreate template. +unlink cwd . "/t/templates/custom_autocreate_content.tt"; + +OpenGuides::Test->write_data( + guide => $guide, + node => "Bleeding Heart", + categories => "Pubs", + locales => "EC1", + return_output => 1, + ); +$content = $wiki->retrieve_node( "Category Pubs" ); +$content =~ s/\s+$//s; +is( $content, "Things in this category " + . "(@MAP_LINK [[Category Pubs|view them on a map]]):\n" + . "@INDEX_LIST [[Category Pubs]]", + "Default content is picked up if autocreate template doesn't exist" ); + +$content = $wiki->retrieve_node( "Locale EC1" ); +$content =~ s/\s+$//s; +is( $content, "Things in EC1 " + . "(@MAP_LINK [[Locale EC1|view them on a map]]):\n" + . "@INDEX_LIST [[Locale EC1]]", + "...and for locales too." );
Deleted: trunk/t/11_utils.t =================================================================== --- trunk/t/11_utils.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/11_utils.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,70 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Utils; -use OpenGuides::Test; -use Test::More tests => 10; - -eval { my $wiki = OpenGuides::Utils->make_wiki_object; }; -ok( $@, "->make_wiki_object croaks if no config param supplied" ); - -eval { my $wiki = OpenGuides::Utils->make_wiki_object( config => "foo" ); }; -ok( $@, "...and if config param isn't an OpenGuides::Config object" ); - -eval { - my $wiki = OpenGuides::Utils->make_wiki_object( - config => OpenGuides::Config->new( file => 'fake' ) - ); -}; - -like( $@, qr/File 'fake' does not exist/, '...and Config::Tiny errors are reported'); - -my $have_sqlite = 1; -my $sqlite_error; - -eval { require DBD::SQLite; }; -if ( $@ ) { - ($sqlite_error) = $@ =~ /^(.*?)\n/; - $have_sqlite = 0; -} - -SKIP: { - skip "DBD::SQLite could not be used - no database to test with. " - . "($sqlite_error)", 7 - unless $have_sqlite; - - # Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - - - my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_url => "", - script_name => "", - } - ); - - eval { require Wiki::Toolkit::Search::Plucene; }; - if ( $@ ) { $config->use_plucene ( 0 ) }; - - my $wiki = eval { - OpenGuides::Utils->make_wiki_object( config => $config ); - }; - is( $@, "", - "...but not with an OpenGuides::Config object with suitable data" ); - isa_ok( $wiki, "Wiki::Toolkit" ); - - ok( $wiki->store, "...and store defined" ); - ok( $wiki->search_obj, "...and search defined" ); - ok( $wiki->formatter, "...and formatter defined" ); - - # Now test ->detect_redirect - is( OpenGuides::Utils->detect_redirect( content => "#REDIRECT [[Foo]]" ), - "Foo", - "->detect_redirect successfully detects redirect content" ); - ok( !OpenGuides::Utils->detect_redirect( content => "Mmmm, tea." ), - "...and successfully detects non-redirect content" ); -}
Deleted: trunk/t/12_macros.t =================================================================== --- trunk/t/12_macros.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/12_macros.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,207 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 19; - -SKIP: { - # Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - - my $config = OpenGuides::Test->make_basic_config; - my $guide = OpenGuides->new( config => $config ); - my $wiki = $guide->wiki; - - # Test @INDEX_LINK - $wiki->write_node( "Test 1", "@INDEX_LINK [[Category Foo]]" ) - or die "Can't write node"; - $wiki->write_node( "Test 2", "@INDEX_LINK [[Category Bar|Bars]]" ) - or die "Can't write node"; - - my $output; - $output = $guide->display_node( - return_output => 1, - id => "Test 1", - ); - like( $output, qr/View all pages in Category Foo/, - "@INDEX_LINK has right default link text" ); - like( $output, qr/action=index;cat=foo/, "...and URL looks right" ); - - $output = $guide->display_node( - return_output => 1, - id => "Test 2", - ); - like( $output, qr/>Bars</a>/, "Default link text can be overridden" ); - like( $output, qr/action=index;cat=bar/, "...and URL looks right" ); - - # Test @INDEX_LIST - $wiki->write_node( "Test 3", "@INDEX_LIST [[Category Foo]]" ) - or die "Can't write node"; - $wiki->write_node( "Test 4", "@INDEX_LIST [[Locale Bar]]" ) - or die "Can't write node"; - $wiki->write_node( "Test 5", "@INDEX_LIST [[Category Nonexistent]]" ) - or die "Can't write node"; - $wiki->write_node( "Test 6", "@INDEX_LIST [[Locale Nonexistent]]" ) - or die "Can't write node"; - $wiki->write_node( "Wibble", "wibble", undef, - { - category => "foo", - locale => "bar", - } - ) - or die "Can't write node"; - $output = $guide->display_node( - return_output => 1, - id => "Test 3", - ); - like ( $output, qr|<a href=".*">Wibble</a>|, - '@INDEX_LIST works for categories' ); - $output = $guide->display_node( - return_output => 1, - id => "Test 5", - ); - like ( $output, qr|No pages currently in category|, - "...and fails nicely if no pages in category" ); - $output = $guide->display_node( - return_output => 1, - id => "Test 4", - ); - like ( $output, qr|<a href=".*">Wibble</a>|, - '@INDEX_LIST works for locales' ); - $output = $guide->display_node( - return_output => 1, - id => "Test 6", - ); - like ( $output, qr|No pages currently in locale|, - "...and fails nicely if no pages in locale" ); - - # Test @MAP_LINK - OpenGuides::Test->write_data( - guide => $guide, - node => "Test 1", - content => "@MAP_LINK [[Category Foo]]", - return_output => 1, - ); - OpenGuides::Test->write_data( - guide => $guide, - node => "Test 2", - content => "@MAP_LINK [[Category Foo|Map]]", - return_output => 1, - ); - $output = $guide->display_node( - return_output => 1, - id => "Test 1", - ); - like( $output, qr/View map of pages in Category Foo/, - "@MAP_LINK has right default link text" ); - like( $output, qr/\bcat=foo\b/, "...and URL looks right" ); - - $output = $guide->display_node( - return_output => 1, - id => "Test 2", - ); - like( $output, qr/>Map</a>/, "Default link text can be overridden" ); - like( $output, qr/\bcat=foo\b/, "...and URL looks right" ); - - # Test @RANDOM_PAGE_LINK - OpenGuides::Test->write_data( - guide => $guide, - node => "Test Random", - content => "@RANDOM_PAGE_LINK", - return_output => 1, - ); - $output = $guide->display_node( - return_output => 1, - id => "Test Random", - ); - like( $output, qr/View a random page on this guide/, - "@RANDOM_PAGE_LINK has right default link text" ); - - # Not sure yet how to let people override link text in the above. TODO. - - OpenGuides::Test->write_data( - guide => $guide, - node => "Test Random", - content => "@RANDOM_PAGE_LINK " - . "[[Category Pubs]]", - return_output => 1, - ); - $output = $guide->display_node( - return_output => 1, - id => "Test Random", - ); - like( $output, qr/View a random page in Category Pubs/, - "@RANDOM_PAGE_LINK has right default link text for categories" ); - OpenGuides::Test->write_data( - guide => $guide, - node => "Test Random", - content => "@RANDOM_PAGE_LINK " - . "[[Category Pubs|Random pub]]", - return_output => 1, - ); - $output = $guide->display_node( - return_output => 1, - id => "Test Random", - ); - like( $output, qr/>Random pub</a>/, "...and can be overridden" ); - - OpenGuides::Test->write_data( - guide => $guide, - node => "Test Random", - content => "@RANDOM_PAGE_LINK " - . "[[Locale Fulham]]", - return_output => 1, - ); - $output = $guide->display_node( - return_output => 1, - id => "Test Random", - ); - like( $output, qr/View a random page in Locale Fulham/, - "@RANDOM_PAGE_LINK has right default link text for categories" ); - OpenGuides::Test->write_data( - guide => $guide, - node => "Test Random", - content => "@RANDOM_PAGE_LINK " - . "[[Locale Fulham|" - . "Random thing in Fulham]]", - return_output => 1, - ); - $output = $guide->display_node( - return_output => 1, - id => "Test Random", - ); - like( $output, qr/>Random thing in Fulham</a>/, - "...and can be overridden" ); - - # Test @INCLUDE_NODE - OpenGuides::Test->write_data( - guide => $guide, - node => "Test 1", - content => "Hello, I am Test 1!\r\n" - . "@INCLUDE_NODE [[Test 2]]", - return_output => 1, - ); - OpenGuides::Test->write_data( - guide => $guide, - node => "Test 2", - content => "Hello, I am Test 2!", - return_output => 1, - ); - $output = $guide->display_node( - return_output => 1, - id => "Test 1", - ); - like( $output, qr/Hello, I am Test 1!/, - "Node with @INCLUDE_NODE has its own content" ); - like( $output, qr/Hello, I am Test 2!/, - "...and the included content" ); -}
Deleted: trunk/t/13_cookies.t =================================================================== --- trunk/t/13_cookies.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/13_cookies.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,116 +0,0 @@ -use strict; -use OpenGuides::Config; -use OpenGuides::CGI; -use Time::Piece; -use Time::Seconds; -use Test::More tests => 30; - -eval { OpenGuides::CGI->make_prefs_cookie; }; -ok( $@, "->make_prefs_cookie dies if no config object supplied" ); - -eval { OpenGuides::CGI->make_prefs_cookie( config => "foo" ); }; -ok( $@, "...or if config isn't an OpenGuides::Config" ); - -my $config = OpenGuides::Config->new( vars => { site_name => "Test Site" } ); - -eval { OpenGuides::CGI->make_prefs_cookie( config => $config ); }; -is( $@, "", "...but not if it is" ); - -# Use nonsense values here to make sure the test is a good one regardless -# of defaults - can't do this for cookie_expires, unfortunately. -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "un_pref", - include_geocache_link => "gc_pref", - preview_above_edit_box => "pv_pref", - latlong_traditional => "ll_pref", - omit_help_links => "hl_pref", - show_minor_edits_in_rc => "me_pref", - default_edit_type => "et_pref", - cookie_expires => "never", - track_recent_changes_views => "rc_pref", - display_google_maps => "gm_pref", - is_admin => "admin_pref", -); -isa_ok( $cookie, "CGI::Cookie", "->make_prefs_cookie returns a cookie" ); - -my $expiry_string = $cookie->expires; -# Hack off the timezone bit since strptime can't parse it portably. -# Timezones taken from RFC 822. -$expiry_string =~ s/ (UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|1[A-IK-Z]|+\d\d\d\d|-\d\d\d\d)$//; -print "# (String hacked to $expiry_string)\n"; -my $expiry = Time::Piece->strptime( $expiry_string, "%a, %d-%b-%Y %T"); -print "# Expires: " . $cookie->expires . ", ie $expiry\n"; -my $now = localtime; -print "# cookie should still be valid in a year, ie " . ($now + ONE_YEAR) . "\n"; -ok( $expiry - ( $now + ONE_YEAR ) > 0, "cookie expiry date correct" ); - -$ENV{HTTP_COOKIE} = $cookie; - -eval { OpenGuides::CGI->get_prefs_from_cookie; }; -ok( $@, "->get_prefs_from_cookie dies if no config object supplied" ); - -eval { OpenGuides::CGI->get_prefs_from_cookie( config => "foo" ); }; -ok( $@, "...or if config isn't an OpenGuides::Config" ); - -eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); }; -is( $@, "", "...but not if it is" ); - -my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); -is( $prefs{username}, "un_pref", "get_prefs_from_cookie can find username" ); -is( $prefs{include_geocache_link}, "gc_pref", "...and geocache prefs" ); -is( $prefs{preview_above_edit_box}, "pv_pref", "...and preview prefs" ); -is( $prefs{latlong_traditional}, "ll_pref", "...and latlong prefs" ); -is( $prefs{omit_help_links}, "hl_pref", "...and help link prefs" ); -is( $prefs{show_minor_edits_in_rc}, "me_pref", "...and minor edits prefs" ); -is( $prefs{default_edit_type}, "et_pref", "...and default edit prefs" ); -is( $prefs{cookie_expires}, "never", "...and requested cookie expiry" ); -is( $prefs{track_recent_changes_views}, "rc_pref", - "...and recent changes tracking" ); -is( $prefs{display_google_maps}, "gm_pref", - "...and map display preference" ); -is( $prefs{is_admin}, "admin_pref", - "...and admin preference" ); -# Now make sure that true/false preferences are taken account of when -# they're false. -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - include_geocache_link => 0, - preview_above_edit_box => 0, - latlong_traditional => 0, - omit_help_links => 0, - show_minor_edits_in_rc => 0, - track_recent_changes_views => 0, - display_google_maps => 0, - is_admin => 0, -); - -$ENV{HTTP_COOKIE} = $cookie; - -%prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); -ok( !$prefs{include_geocache_link}, "geocache prefs taken note of when false"); -ok( !$prefs{preview_above_edit_box}, "...and preview prefs" ); -ok( !$prefs{latlong_traditional}, "...and latlong prefs" ); -ok( !$prefs{omit_help_links}, "...and help link prefs" ); -ok( !$prefs{show_minor_edits_in_rc}, "...and minor edits prefs" ); -ok( !$prefs{track_recent_changes_views}, "...and recent changes prefs" ); -ok( !$prefs{display_google_maps}, "...and Google Maps prefs" ); -ok( !$prefs{is_admin}, "...and admin prefs" ); - -# Check that cookie parsing fails nicely if no cookie set. -delete $ENV{HTTP_COOKIE}; -%prefs = eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); }; -is( $@, "", "->get_prefs_from_cookie doesn't die if no cookie set" ); -is( keys %prefs, 11, "...and returns ten default values" ); - -# Check that the prefs cookie is still looked for even if we send along a -# non-prefs cookie. -my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( - config => $config ); -my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, is_admin => 1 ); -$ENV{HTTP_COOKIE} = $prefs_cookie; -%prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config, - cookies => [ $rc_cookie ] ); -ok( $prefs{is_admin}, - "->get_prefs_from_cookie still works with ENV if we send RC cookie" );
Deleted: trunk/t/14_recent_changes_cookies.t =================================================================== --- trunk/t/14_recent_changes_cookies.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/14_recent_changes_cookies.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,110 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Time::Piece; -use Time::Seconds; -use Test::More tests => 11; - -eval { OpenGuides::CGI->make_recent_changes_cookie; }; -ok( $@, "->make_recent_changes_cookie dies if no config object supplied" ); - -eval { OpenGuides::CGI->make_recent_changes_cookie( config => "foo" ); }; -ok( $@, "...or if config isn't an OpenGuides::Config" ); - -my $config = OpenGuides::Config->new( vars => { site_name => "Test Site" } ); - -eval { OpenGuides::CGI->make_recent_changes_cookie( config => $config ); }; -is( $@, "", "...but not if it is" ); - -my $cookie = OpenGuides::CGI->make_recent_changes_cookie( config => $config ); -isa_ok( $cookie, "CGI::Cookie", - "->make_recent_changes_cookie returns a cookie" ); - -my $expiry_string = $cookie->expires; -# Hack off the timezone bit since strptime can't parse it portably. -# Timezones taken from RFC 822. -$expiry_string =~ s/ (UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|1[A-IK-Z]|+\d\d\d\d|-\d\d\d\d)$//; -print "# (String hacked to $expiry_string)\n"; -my $expiry = Time::Piece->strptime( $expiry_string, "%a, %d-%b-%Y %T"); -print "# Expires: " . $cookie->expires . ", ie $expiry\n"; -my $now = localtime; -print "# cookie should still be valid in a year, ie " . ($now + ONE_YEAR) . "\n"; -ok( $expiry - ( $now + ONE_YEAR ) > 0, "cookie expiry date correct" ); - -$ENV{HTTP_COOKIE} = $cookie; - -eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie; }; -ok( $@, "->get_last_recent_changes_visit_from_cookie dies if no config object supplied" ); - -eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => "foo" ); }; -ok( $@, "...or if config isn't an OpenGuides::Config" ); - -eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); }; -is( $@, "", "...but not if it is" ); - -# Check that cookie parsing fails nicely if no cookie set. -delete $ENV{HTTP_COOKIE}; -eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); }; -is( $@, "", "->get_last_recent_changes_visit_from_cookie doesn't die if no cookie set" ); - -# Now test that the prefs option is taken note of. -my $have_sqlite = 1; -my $sqlite_error; - -eval { require DBD::SQLite; }; -if ( $@ ) { - ($sqlite_error) = $@ =~ /^(.*?)\n/; - $have_sqlite = 0; -} - -SKIP: { - skip "DBD::SQLite could not be used - no database to test with. ($sqlite_error)", 2 - unless $have_sqlite; - OpenGuides::Test::refresh_db(); - - - my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - } - ); - eval { require Wiki::Toolkit::Search::Plucene; }; - if ( $@ ) { $config->use_plucene ( 0 ) }; - - my $guide = OpenGuides->new( config => $config ); - - my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - track_recent_changes_views => 1, - ); - my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( - config => $config - ); - $ENV{HTTP_COOKIE} = $prefs_cookie . "; " . $rc_cookie; - my $output = $guide->display_node( - id => "RecentChanges", - return_output => 1, - ); - like( $output, qr/Set-Cookie:/, "recent changes cookie set when asked" ); - - $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - track_recent_changes_views => 0, - ); - $ENV{HTTP_COOKIE} = $prefs_cookie . "; " . $rc_cookie; - $output = $guide->display_node( - id => "RecentChanges", - return_output => 1, - ); - unlike( $output, qr/Set-Cookie:/, "...and not when not" ); -}
Deleted: trunk/t/15_template.t =================================================================== --- trunk/t/15_template.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/15_template.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,247 +0,0 @@ -use strict; -use Cwd; -use CGI::Cookie; -use Wiki::Toolkit::Formatter::UseMod; -use OpenGuides; -use OpenGuides::Template; -use OpenGuides::Test; -use Test::More tests => 29; - -my $config = OpenGuides::Test->make_basic_config; -$config->template_path( cwd . "/t/templates" ); -$config->site_name( "Wiki::Toolkit Test Site" ); -$config->script_url( "http://wiki.example.com/" ); -$config->script_name( "mywiki.cgi" ); -$config->contact_email( 'wiki@example.com' ); -$config->stylesheet_url( "http://wiki.example.com/styles.css" ); -$config->home_name( "Home Page" ); -$config->formatting_rules_node( "Rules" ); -$config->formatting_rules_link( "" ); - -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -eval { OpenGuides::Template->output( wiki => $wiki, - config => $config ); }; -ok( $@, "->output croaks if no template file supplied" ); - -eval { - OpenGuides::Template->output( wiki => $wiki, - config => $config, - template => "15_test.tt" ); -}; -is( $@, "", "...but not if one is" ); - -my $output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", - vars => { foo => "bar" } -); -like( $output, qr/^Content-Type: text/html/, - "Content-Type header included and defaults to text/html" ); -like( $output, qr/FOO: bar/, "variables substituted" ); - -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", - content_type => "" -); -unlike( $output, qr/^Content-Type: text/html/, - "Content-Type header omitted if content_type arg explicitly blank" ); - -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", - noheaders => 1, - http_response => 500 -); - -unlike( $output, qr/^Status: /, - "Headers omitted if noheaders arg given" ); - -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_idonotexist.tt" -); -like( $output, qr/Failed to process template/, "fails nice on TT error" ); - -# Test TT variables are auto-set from config. -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); - -like( $output, qr/SITE NAME: Wiki::Toolkit Test Site/, "site_name var set" ); -like( $output, qr/CGI URL: mywiki.cgi/, "cgi_url var set" ); -like( $output, qr/FULL CGI URL: http://wiki.example.com/mywiki.cgi/, - "full_cgi_url var set" ); -like( $output, qr/CONTACT EMAIL: wiki@example.com/, "contact_email var set" ); -like( $output, qr/STYLESHEET: http://wiki.example.com/styles.css/, - "stylesheet var set" ); -like( $output, qr/HOME LINK: http://wiki.example.com/mywiki.cgi/, "home_link var set" ); -like( $output, qr/HOME NAME: Home Page/, "home_name var set" ); -like( $output, - qr/FORMATTING RULES LINK: http://wiki.example.com/mywiki.cgi?Rules/, - "formatting_rules_link var set" ); - -# Test openguides_version TT variable. -like( $output, qr/OPENGUIDES VERSION: 0.\d\d/, - "openguides_version set" ); - -# Test TT variables auto-set from node name. -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - node => "Test Node", - template => "15_test.tt" -); - -like( $output, qr/NODE NAME: Test Node/, "node_name var set" ); -like( $output, qr/NODE PARAM: Test_Node/, "node_param var set" ); - -# Test that cookies go in. -my $cookie = CGI::Cookie->new( -name => "x", -value => "y" ); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", - cookies => $cookie -); -like( $output, qr/Set-Cookie: $cookie/, "cookie in header" ); - -# Test that external URLs for text formatting work. -$config = OpenGuides::Config->new( - vars => { - template_path => cwd . '/t/templates', - site_name => 'Wiki::Toolkit Test Site', - script_url => 'http://wiki.example.com/', - script_name => 'mywiki.cgi', - formatting_rules_node => 'Some External Help', - formatting_rules_link => 'http://www.example.com/wikitext', - } -); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); -like ( $output, qr/FORMATTING RULES LINK: http://www.example.com/wikitext/, - "formatting_rules_link var honoured for explicit URLs" ); - -# Test that home_link is set correctly when script_name is blank. -$config = OpenGuides::Config->new( - vars => { - template_path => cwd . '/t/templates', - site_name => 'Wiki::Toolkit Test Site', - script_url => 'http://wiki.example.com/', - script_name => '', - } -); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); -like( $output, qr/HOME LINK: http://wiki.example.com/, - "home_link var set OK when script_name blank" ); - -# Test that full_cgi_url comes out right if the trailing '/' is -# missing from script_url in the config file. -$config = OpenGuides::Config->new( - vars => { - template_path => cwd . '/t/templates', - site_name => 'Wiki::Toolkit Test Site', - script_url => 'http://wiki.example.com', - script_name => 'wiki.cgi', - } -); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); -like( $output, qr/FULL CGI URL: http://wiki.example.com/wiki.cgi/, - "full_cgi_url OK when trailing '/' missed off script_url" ); - -# Test that TT vars are picked up from user cookie prefs. -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - omit_formatting_link => 1, -); -$ENV{HTTP_COOKIE} = $cookie; -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); -like( $output, qr/FORMATTING RULES LINK: /, - "formatting_rules_link TT var blank as set in cookie" ); - -# Test that explicitly supplied vars override vars in cookie. -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", - vars => { omit_formatting_link => "fish" }, -); -like( $output, qr/OMIT FORMATTING LINK: fish/, - "explicitly supplied TT vars override cookie ones" ); - -# Test that enable_page_deletion is set correctly in various circumstances. -$config = OpenGuides::Config->new( - vars => { - template_path => cwd . "/t/templates", - site_name => "Test Site", - script_url => "/", - script_name => "", - }, -); - -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", -); -like( $output, qr/ENABLE PAGE DELETION: 0/, - "enable_page_deletion var set correctly when not specified in conf" ); - -$config->enable_page_deletion( "n" ); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", -); -like( $output, qr/ENABLE PAGE DELETION: 0/, - "enable_page_deletion var set correctly when set to 'n' in conf" ); - -$config->enable_page_deletion( "y" ); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", -); -like( $output, qr/ENABLE PAGE DELETION: 1/, - "enable_page_deletion var set correctly when set to 'y' in conf" ); - -$config->enable_page_deletion( 0 ); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", -); -like( $output, qr/ENABLE PAGE DELETION: 0/, - "enable_page_deletion var set correctly when set to '0' in conf" ); - -$config->enable_page_deletion( 1 ); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", -); -like( $output, qr/ENABLE PAGE DELETION: 1/, - "enable_page_deletion var set correctly when set to '1' in conf" );
Deleted: trunk/t/16_test_tester.t =================================================================== --- trunk/t/16_test_tester.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/16_test_tester.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,44 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -plan tests => 2; - - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->site_name( "Test Site" ); -my $guide = OpenGuides->new( config => $config ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "London Zoo", - content => "It's a zoo.", - ); -my $wiki = $guide->wiki; -my %data = $wiki->retrieve_node( "London Zoo" ); -is( $data{content}, "It's a zoo.", "first write with write_data went in" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "London Zoo", - content => "It's still a zoo.", - ); -%data = $wiki->retrieve_node( "London Zoo" ); -is( $data{content}, "It's still a zoo.", "...so does second" ); -
Deleted: trunk/t/17_commit_node.t =================================================================== --- trunk/t/17_commit_node.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/17_commit_node.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,108 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Feed; -use OpenGuides::Utils; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -plan tests => 7; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - use_plucene => 1 - } -); - -# Basic sanity check first. -my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - -my $feed = OpenGuides::Feed->new( wiki => $wiki, - config => $config ); - - -# Write the first version -my $guide = OpenGuides->new( config => $config ); - -# Set up CGI parameters ready for a node write. -my $q = OpenGuides::Test->make_cgi_object( - content => "foo", - username => "bob", - comment => "foo", - node_image => "image", - edit_type => "Minor tidying" -); - -my $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check we have it -ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); - -my %node = $wiki->retrieve_node("Wombats"); -is( $node{version}, 1, "First version" ); -is( $node{metadata}->{edit_type}[0], "Minor tidying", "Right edit type" ); - - -# Now write a second version of it -$q->param( -name => "edit_type", -value => "Normal edit" ); -$q->param( -name => "checksum", -value => $node{checksum} ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check it's as expected -%node = $wiki->retrieve_node("Wombats"); -is( $node{version}, 2, "First version" ); -is( $node{metadata}->{edit_type}[0], "Normal edit", "Right edit type" ); - -# Now try to commit some invalid data, and make sure we get an edit form back -$q = OpenGuides::Test->make_cgi_object( - content => "foo", - os_x => "fooooo", - username => "bob", - comment => "foo", - node_image => "image", - edit_type => "Minor tidying" -); - -$output = $guide->commit_node( - return_output => 1, - id => "Wombats again", - cgi_obj => $q, - ); - -like( $output, qr/Your input was invalid/, - "Edit form displayed and invalid input message shown if invalid input" ); - -like( $output, qr/os_x must be integer/, - "Edit form displayed and os_x integer message displayed" );
Deleted: trunk/t/18_http_headers.t =================================================================== --- trunk/t/18_http_headers.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/18_http_headers.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,59 +0,0 @@ -use strict; -use Cwd; -use OpenGuides; -use OpenGuides::Template; -use OpenGuides::Test; -use Test::More tests => 5; - -my $config = OpenGuides::Test->make_basic_config; -$config->template_path( cwd . "/t/templates" ); - -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -eval { - OpenGuides::Template->output( wiki => $wiki, - config => $config, - template => "15_test.tt" ); -}; -is( $@, "", "is happy doing output" ); - -my $output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); -like( $output, qr/^Content-Type: text/html/, - "Content-Type header included and defaults to text/html" ); - -# Now supply a http charset -$config->http_charset( "UTF-8" ); - -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); -like( $output, qr/^Content-Type: text/html; charset=UTF-8/, - "Content-Type header included charset" ); - -# Suppy charset and content type -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - content_type => "text/xml", - template => "15_test.tt" -); -like( $output, qr/^Content-Type: text/xml; charset=UTF-8/, - "Content-Type header included charset" ); - -# Content type but no charset -$config->http_charset( "" ); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - content_type => "text/xml", - template => "15_test.tt" -); -like( $output, qr/^Content-Type: text/xml/, - "Content-Type header didn't include charset" );
Deleted: trunk/t/19_autocreate.t =================================================================== --- trunk/t/19_autocreate.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/19_autocreate.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,129 +0,0 @@ -use strict; -use Cwd; -use Wiki::Toolkit::Plugin::Categoriser; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 13; - -my $config = OpenGuides::Test->make_basic_config; -$config->custom_template_path( cwd . "/t/templates/" ); -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; -my $categoriser = Wiki::Toolkit::Plugin::Categoriser->new; -$wiki->register_plugin( plugin => $categoriser ); - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Check that unwelcome characters are stripped from autocreated cats/locales. -# Double spaces: -OpenGuides::Test->write_data( - guide => $guide, - node => "Arbat", - categories => "Delicious Russian Food", - return_output => 1, - ); - -ok( !$wiki->node_exists( "Category Delicious Russian Food" ), - "Categories with double spaces in are not auto-created." ); -ok( $wiki->node_exists( "Category Delicious Russian Food" ), - "...but the corresponding category with single spaces is." ); -ok ( !$categoriser->in_category( node => "Arbat", - category => "Delicious Russian Food" ), - "...and the new node is not in the double-spaced category." ); -ok ( $categoriser->in_category( node => "Arbat", - category => "Delicious Russian Food" ), - "...but it is in the single-spaced one." ); - -# Newlines: -OpenGuides::Test->write_data( - guide => $guide, - node => "Liaison", - categories => "Dim\nSum", - return_output => 1, - ); - -ok( !$wiki->node_exists( "Category Dim\nSum" ), - "Categories with newlines in are not auto-created." ); -ok( $wiki->node_exists( "Category Dim Sum" ), - "...but the corresponding category with single spaces is." ); -ok ( !$categoriser->in_category( node => "Liaison", - category => "Dim\nSum" ), - "...and the new node is not in the newlined category." ); -ok ( $categoriser->in_category( node => "Liaison", - category => "Dim Sum" ), - "...but it is in the single-spaced one." ); - - -# Write a custom template to autofill content in autocreated nodes. -eval { - unlink cwd . "/t/templates/custom_autocreate_content.tt"; -}; -open( FILE, ">", cwd . "/t/templates/custom_autocreate_content.tt" ) - or die $!; -print FILE <<EOF; -Auto-generated list of places in -[% IF index_type == "Category" %]this category[% ELSE %][% index_value %][% END %]: -@INDEX_LIST [[[% node_name %]]] -EOF -close FILE or die $!; - -# Check that autocapitalisation works correctly in categories with hyphens. -OpenGuides::Test->write_data( - guide => $guide, - node => "Vivat Bacchus", - categories => "Restaurants\r\nVegan-friendly", - locales => "Farringdon", - return_output => 1, - ); - -ok( $wiki->node_exists( "Category Vegan-Friendly" ), - "Categories with hyphens in are auto-created correctly." ); - -# Check that the custom autocreate template was picked up. -my $content = $wiki->retrieve_node( "Category Vegan-Friendly" ); -$content =~ s/\s+$//s; -$content =~ s/\s+/ /gs; -is( $content, "Auto-generated list of places in this category: " - . "@INDEX_LIST [[Category Vegan-Friendly]]", - "Custom autocreate template works properly for categories" ); - -$content = $wiki->retrieve_node( "Locale Farringdon" ); -$content =~ s/\s+$//s; -$content =~ s/\s+/ /gs; -is( $content, "Auto-generated list of places in Farringdon: " - . "@INDEX_LIST [[Locale Farringdon]]", - "...and locales" ); - -# Now make sure that we have a fallback if there's no autocreate template. -unlink cwd . "/t/templates/custom_autocreate_content.tt"; - -OpenGuides::Test->write_data( - guide => $guide, - node => "Bleeding Heart", - categories => "Pubs", - locales => "EC1", - return_output => 1, - ); -$content = $wiki->retrieve_node( "Category Pubs" ); -$content =~ s/\s+$//s; -is( $content, "Things in this category " - . "(@MAP_LINK [[Category Pubs|view them on a map]]):\n" - . "@INDEX_LIST [[Category Pubs]]", - "Default content is picked up if autocreate template doesn't exist" ); - -$content = $wiki->retrieve_node( "Locale EC1" ); -$content =~ s/\s+$//s; -is( $content, "Things in EC1 " - . "(@MAP_LINK [[Locale EC1|view them on a map]]):\n" - . "@INDEX_LIST [[Locale EC1]]", - "...and for locales too." );
Copied: trunk/t/200_edit_form.t (from rev 1381, trunk/t/20_edit_form.t) =================================================================== --- trunk/t/200_edit_form.t (rev 0) +++ trunk/t/200_edit_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,36 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; +} + +plan tests => 1; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); + +# Make sure the edit form doesn't display a search form. +my $output = $guide->display_edit_form( + id => "Crabtree Tavern", + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::no_tag( $output, "div", { id => "search_form" }, + "edit form doesn't contain search form" );
Copied: trunk/t/201_rdf.t (from rev 1381, trunk/t/21_rdf.t) =================================================================== --- trunk/t/201_rdf.t (rev 0) +++ trunk/t/201_rdf.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,181 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Config; +use OpenGuides::RDF; +use OpenGuides::Utils; +use OpenGuides::Test; +use URI::Escape; +use Test::More; + +eval { require DBD::SQLite; }; +my $have_sqlite = $@ ? 0 : 1; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 30; + +# clear out the database +OpenGuides::Test::refresh_db(); + + +my $config = OpenGuides::Test->make_basic_config; +$config->script_url( "http://wiki.example.com/" ); +$config->script_name( "mywiki.cgi" ); +$config->site_name( "Wiki::Toolkit Test Site" ); +$config->default_city( "London" ); +$config->default_country( "United Kingdom" ); +$config->geo_handler( 3 ); + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene ( 0 ) }; + + +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + + +my $rdf_writer = eval { + OpenGuides::RDF->new( wiki => $wiki, config => $config ); +}; +is( $@, "", "'new' doesn't croak if wiki and config objects supplied" ); +isa_ok( $rdf_writer, "OpenGuides::RDF" ); + +# Test the data for a node that exists. +OpenGuides::Test->write_data( + guide => $guide, + node => "Calthorpe Arms", + content => "CAMRA-approved pub near King's Cross", + comment => "Stub page, please update!", + username => "Anonymous", + postcode => "WC1X 8JR", + locales => "Bloomsbury\r\nSt Pancras", + phone => "test phone number", + website => "http://example.com", + hours_text => "test hours", + latitude => "51.524193", + longitude => "-0.114436", + summary => "a really nice pub", +); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Calthorpe Arms", + content => "CAMRA-approved pub near King's Cross", + comment => "Stub page, please update!", + username => "Kake", + postcode => "WC1X 8JR", + locales => "Bloomsbury\r\nSt Pancras", + phone => "test phone number", + website => "http://example.com", + hours_text => "test hours", + latitude => "51.524193", + longitude => "-0.114436", + summary => "a nice pub", + node_image => "http://example.com/calthorpe.jpg", +); + +my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); + +like( $rdfxml, qr|<?xml version="1.0" ?>|, "RDF uses no encoding when none set" ); +$config->http_charset( "UTF-8" ); +$guide = OpenGuides->new( config => $config ); +$rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); +like( $rdfxml, qr|<?xml version="1.0" encoding="UTF-8"?>|, "RDF uses declared encoding" ); + +like( $rdfxml, qr|<foaf:depiction rdf:resource="http://example.com/calthorpe.jpg" />|, "Node image"); + +like( $rdfxml, qr|<wail:Neighborhood rdf:nodeID="Bloomsbury">|, + "finds the first locale" ); +like( $rdfxml, qr|<wail:Neighborhood rdf:nodeID="St_Pancras">|, + "finds the second locale" ); + +like( $rdfxml, qr|contact:phonetest phone number</contact:phone>|, + "picks up phone number" ); + +like( $rdfxml, qr|dc:availabletest hours</dc:available>|, + "picks up opening hours text" ); + +like( $rdfxml, qr|<foaf:homepage rdf:resource="http://example.com" />|, "picks up website" ); + +like( $rdfxml, + qr|dc:titleWiki::Toolkit Test Site: Calthorpe Arms</dc:title>|, + "sets the title correctly" ); + +like( $rdfxml, qr|id=Kake;format=rdf#obj"|, + "last username to edit used as contributor" ); +like( $rdfxml, qr|id=Anonymous;format=rdf#obj"|, + "... as well as previous usernames" ); + +like( $rdfxml, qr|wiki:version2</wiki:version>|, "version picked up" ); + +like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" ); + +like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi%5C?Calthorpe_Arms" />|, + "set the dc:source with the version-independent uri" ); + +like( $rdfxml, qr|<wail:City rdf:nodeID="city">\n\s+wail:nameLondon</wail:name>|, "city" ). +like( $rdfxml, qr|wail:locatedIn\n\s+<wail:Country rdf:nodeID="country">\n\s+wail:nameUnited Kingdom</wail:name>|, "country" ). +like( $rdfxml, qr|wail:postalCodeWC1X 8JR</wail:postalCode>|, "postcode" ); +like( $rdfxml, qr|geo:lat51.524193</geo:lat>|, "latitude" ); +like( $rdfxml, qr|geo:long-0.114436</geo:long>|, "longitude" ); +like( $rdfxml, qr|dc:descriptiona nice pub</dc:description>|, "summary (description)" ); + +like( $rdfxml, qr|dc:date|, "date element included" ); +unlike( $rdfxml, qr|dc:date1970|, "hasn't defaulted to the epoch" ); + +# Check that default city and country can be set to blank. +$config = OpenGuides::Test->make_basic_config; +$config->default_city( "" ); +$config->default_country( "" ); +$guide = OpenGuides->new( config => $config ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Star Tavern", + latitude => 51.498, + longitude => -0.154, + ); +$rdf_writer = OpenGuides::RDF->new( wiki => $guide->wiki, config => $config ); +$rdfxml = $rdf_writer->emit_rdfxml( node => "Star Tavern" ); +unlike( $rdfxml, qr|<city>|, "no city in RDF when no default city" ); +unlike( $rdfxml, qr|<country>|, "...same for country" ); + +# Now test that there's a nice failsafe where a node doesn't exist. +$rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); }; +is( $@, "", "->emit_rdfxml doesn't die when called on a nonexistent node" ); + +like( $rdfxml, qr|wiki:version0</wiki:version>|, "...and wiki:version is 0" ); + +# Test the data for a node that redirects. +$wiki->write_node( "Calthorpe Arms Pub", + "#REDIRECT [[Calthorpe Arms]]", + undef, + { + comment => "Created as redirect to Calthorpe Arms page.", + username => "Earle", + } +); + +my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" ); + +like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/?id=Calthorpe_Arms;format=rdf#obj" />|, + "redirecting node gets owl:sameAs to target" ); + +$wiki->write_node( "Nonesuch Stores", + "A metaphysical wonderland", + undef, + { + comment => "Yup.", + username => "Nobody", + opening_hours_text => "Open All Hours", + } +); + +$rdfxml = $rdf_writer->emit_rdfxml( node => "Nonesuch Stores" ); + +like( $rdfxml, qr|<geo:SpatialThing rdf:ID="obj">|, + "having opening hours marks node as geospatial" ); +
Copied: trunk/t/202_feed_recent_changes.t (from rev 1381, trunk/t/22_feed_recent_changes.t) =================================================================== --- trunk/t/202_feed_recent_changes.t (rev 0) +++ trunk/t/202_feed_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,110 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Feed; +use OpenGuides::Test; +use OpenGuides::Utils; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +# Which feed types do we test? +my @feed_types = qw( rss atom ); +plan tests => 12 * scalar @feed_types; + +my %content_types = (rss=>'application/rdf+xml', atom=>'application/atom+xml'); + +foreach my $feed_type (@feed_types) { + # Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + + my $config = OpenGuides::Test->make_basic_config; + $config->script_name( "wiki.cgi" ); + $config->script_url( "http://example.com/" ); + $config->http_charset( "UTF-7" ); + + # Basic sanity check first. + my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + + my $feed = OpenGuides::Feed->new( wiki => $wiki, + config => $config ); + is( $feed->default_content_type($feed_type), $content_types{$feed_type}, "Return the right content type" ); + + like( $feed->html_equiv_link, qr|http://example.com/wiki.cgi%5C?%7C, + "html_equiv_link looks right" ); + + my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); }; + is( $@, "", "->make_feed for $feed_type doesn't croak" ); + + # Ensure that the feed actually contained rss/atom (a good guide + # that we actually got the right feed) + like( $feed_output, "/$feed_type/i", "Does contain the feed type" ); + + # Check the XML + like( $feed_output, qr/<?xml version="1.0" encoding="UTF-7"/, "Right XML type and encoding" ); + + # Now write some data, first a minor edit then a non-minor one. + my $guide = OpenGuides->new( config => $config ); + + OpenGuides::Test->write_data( + node => "Wombats", + guide => $guide, + username => "bob", + edit_type => "Minor tidying", + return_output => 1, + ); + OpenGuides::Test->write_data( + node => "Badgers", + guide => $guide, + username => "bob", + edit_type => "Normal edit", + return_output => 1, + ); + OpenGuides::Test->write_data( + node => "Wombles", + guide => $guide, + username => "Kake", + edit_type => "Normal edit", + return_output => 1, + ); + + # Check that the writes went in. + ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); + ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); + ok( $wiki->node_exists( "Wombles" ), "Wombles written" ); + + # Check that the minor edits can be filtered out. + my $output = $guide->display_feed( + feed_type => $feed_type, + feed_listing => "recent_changes", + items => 5, + username => "bob", + ignore_minor_edits => 1, + return_output => 1, + ); + unlike( $output, qr/Wombats/, "minor edits filtered out when required" ); + like( $output, qr/Badgers/, "but normal edits still in" ); + + # Check that the username parameter is taken notice of. + unlike( $output, qr/Wombles/, "username parameter taken note of" ); + + # Now make sure that the HTTP euiv link still works with a blank scriptname + $config->script_name( "" ); + $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + + $feed = OpenGuides::Feed->new( wiki => $wiki, + config => $config ); + like( $feed->html_equiv_link, qr|http://example.com/%5C?%7C, + "html_equiv_link looks right with blank script_name" ); +}
Copied: trunk/t/203_feed_node_all_versions.t (from rev 1381, trunk/t/23_feed_node_all_versions.t) =================================================================== --- trunk/t/203_feed_node_all_versions.t (rev 0) +++ trunk/t/203_feed_node_all_versions.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,150 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Feed; +use OpenGuides::Utils; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +# Which feed types do we test? +my @feed_types = qw( rss atom ); +plan tests => 14 * scalar @feed_types; + + +foreach my $feed_type (@feed_types) { + # Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + + my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + use_plucene => 1, + http_charset => "UTF-8" + } + ); + + # Basic sanity check first. + my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + + my $feed = OpenGuides::Feed->new( wiki => $wiki, + config => $config ); + + my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); }; + is( $@, "", "->make_feed for $feed_type doesn't croak" ); + + # Ensure that the feed actually contained rss/atom (a good guide + # that we actually got the right feed) + like( $feed_output, "/$feed_type/i", "Does contain the feed type" ); + + + # Now write some data: 3 versions of one node, and 1 of another + my $guide = OpenGuides->new( config => $config ); + + # Set up CGI parameters ready for a node write. + # Most of these are in here to avoid uninitialised value warnings. + my $q = CGI->new; + $q->param( -name => "content", -value => "foo" ); + $q->param( -name => "categories", -value => "" ); + $q->param( -name => "locales", -value => "" ); + $q->param( -name => "phone", -value => "" ); + $q->param( -name => "fax", -value => "" ); + $q->param( -name => "website", -value => "" ); + $q->param( -name => "hours_text", -value => "" ); + $q->param( -name => "address", -value => "" ); + $q->param( -name => "postcode", -value => "" ); + $q->param( -name => "map_link", -value => "" ); + $q->param( -name => "os_x", -value => "" ); + $q->param( -name => "os_y", -value => "" ); + $q->param( -name => "username", -value => "bob" ); + $q->param( -name => "comment", -value => "foo" ); + $q->param( -name => "edit_type", -value => "Minor tidying" ); + $ENV{REMOTE_ADDR} = "127.0.0.1"; + + # First version of Wombats + my $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + my %node = $wiki->retrieve_node(name=>"Wombats"); + + # Now second and third + $q->param( -name => "edit_type", -value => "Normal edit" ); + $q->param( -name => "checksum", -value => $node{"checksum"} ); + $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + + %node = $wiki->retrieve_node(name=>"Wombats"); + $q->param( -name => "username", -value => "Kake" ); + $q->param( -name => "checksum", -value => $node{"checksum"} ); + $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + + # Now a different node + $q->delete('checksum'); + $output = $guide->commit_node( + return_output => 1, + id => "Badgers", + cgi_obj => $q, + ); + + # Check that the writes went in. + ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); + ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); + is( scalar $wiki->list_node_all_versions("Wombats"), 3, "3 Wombat versions"); + is( scalar $wiki->list_node_all_versions("Badgers"), 1, "1 Badger version"); + + # Fetch for Badgers + $output = $guide->display_feed( + return_output => 1, + feed_type => $feed_type, + feed_listing => "node_all_versions", + name => "Badgers" + ); + unlike( $output, qr/<title>Wombats/, "Was on Badgers, so no wombats" ); + like( $output, qr/<title>Badgers/, "Badgers correctly found" ); + + # Now for Wombats + $output = $guide->display_feed( + return_output => 1, + feed_type => $feed_type, + feed_listing => "node_all_versions", + name => "Wombats" + ); + unlike( $output, qr/<title>Badgers/, "Was on Wombats, so no badgers" ); + like( $output, qr/<title>Wombats/, "Wombats correctly found" ); + + my @wombats = $output =~ /(<title>Wombats)/g; + is( scalar @wombats, 3, "All 3 wombat versions found" ); + + # Check the content type and charset + like( $output, qr/Content-Type: /, "Has content type" ); + like( $output, qr/$feed_type/, "Which is the right one" ); + like( $output, qr/charset=UTF-8/, "And a charset" ); +}
Copied: trunk/t/204_feed_node_listings.t (from rev 1381, trunk/t/24_feed_node_listings.t) =================================================================== --- trunk/t/204_feed_node_listings.t (rev 0) +++ trunk/t/204_feed_node_listings.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,175 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Feed; +use OpenGuides::Utils; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +# Which feed types do we test? +my @feed_types = qw( rss atom ); +plan tests => 17 * scalar @feed_types; + + +foreach my $feed_type (@feed_types) { + # Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + + my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + use_plucene => 1, + http_charset => "UTF-8" + } + ); + + # Basic sanity check first. + my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + + my $feed = OpenGuides::Feed->new( wiki => $wiki, + config => $config ); + + my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); }; + is( $@, "", "->make_feed for $feed_type doesn't croak" ); + + # Ensure that the feed actually contained rss/atom (a good guide + # that we actually got the right feed) + like( $feed_output, "/$feed_type/i", "Does contain the feed type" ); + + + # Now write some data: 3 versions of one node, and 1 of another + my $guide = OpenGuides->new( config => $config ); + + # Set up CGI parameters ready for a node write. + # Most of these are in here to avoid uninitialised value warnings. + my $q = CGI->new; + $q->param( -name => "content", -value => "foo" ); + $q->param( -name => "categories", -value => "" ); + $q->param( -name => "locales", -value => "" ); + $q->param( -name => "phone", -value => "" ); + $q->param( -name => "fax", -value => "" ); + $q->param( -name => "website", -value => "" ); + $q->param( -name => "hours_text", -value => "" ); + $q->param( -name => "address", -value => "" ); + $q->param( -name => "postcode", -value => "" ); + $q->param( -name => "map_link", -value => "" ); + $q->param( -name => "os_x", -value => "" ); + $q->param( -name => "os_y", -value => "" ); + $q->param( -name => "username", -value => "bob" ); + $q->param( -name => "comment", -value => "foo" ); + $q->param( -name => "edit_type", -value => "Minor tidying" ); + $ENV{REMOTE_ADDR} = "127.0.0.1"; + + # First version of Wombats + my $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + my %node = $wiki->retrieve_node(name=>"Wombats"); + + # Now second and third + $q->param( -name => "edit_type", -value => "Normal edit" ); + $q->param( -name => "checksum", -value => $node{"checksum"} ); + $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + + %node = $wiki->retrieve_node(name=>"Wombats"); + $q->param( -name => "username", -value => "Kake" ); + $q->param( -name => "checksum", -value => $node{"checksum"} ); + $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + + # Now a different node + $q->delete('checksum'); + $output = $guide->commit_node( + return_output => 1, + id => "Badgers", + cgi_obj => $q, + ); + + # Check that the writes went in. + ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); + ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); + is( scalar $wiki->list_node_all_versions("Wombats"), 3, "3 Wombat versions"); + is( scalar $wiki->list_node_all_versions("Badgers"), 1, "1 Badger version"); + + + + # Grab a list of all the nodes + my @all_names = $wiki->list_all_nodes(); + my @all_nodes; + foreach my $name (@all_names) { + my %node = $wiki->retrieve_node(name=>$name); + $node{name} = $name; + push @all_nodes, %node; + } + + # Ask build_feed_for_nodes to make a feed of these + $output = $feed->build_feed_for_nodes($feed_type,@all_nodes); + + like( $output, qr/<title>Wombats/, "Found wombats" ); + like( $output, qr/<title>Badgers/, "Found badgers" ); + + # Check it had the extra metadata + if($feed_type eq "rss") { + like( $output, qr/dc:date/, "Found metadata" ); + like( $output, qr/modwiki:diff/, "Found metadata" ); + like( $output, qr/modwiki:version/, "Found metadata" ); + } else { + like( $output, qr/<updated>/, "Found metadata" ); + like( $output, qr/<summary>/, "Found metadata" ); + like( $output, qr/<author>/, "Found metadata" ); + } + + + # Grab a list of the different versions of Wombats + my @wombats = $wiki->list_node_all_versions("Wombats"); + + # Ask build_mini_feed_for_nodes to make a mini feed of these + $output = $feed->build_mini_feed_for_nodes($feed_type,@wombats); + + like( $output, qr/<title>Wombats/, "Wombats had wombats" ); + unlike( $output, qr/<title>Badgers/, "Wombats didn't have Badgers" ); + + @wombats = $output =~ /(<title>Wombats)/g; + is( scalar @wombats, 3, "All 3 wombat versions found" ); + + # Check it was really the mini version + + if($feed_type eq "rss") { + like( $output, qr/<link>/, "Has link" ); + unlike( $output, qr/dc:contributor/, "Really mini version" ); + unlike( $output, qr/modwiki:history/, "Really mini version" ); + } else { + like( $output, qr/<link href=/, "Has link" ); + unlike( $output, qr/<summary>/, "Really mini version" ); + unlike( $output, qr/<author>/, "Really mini version" ); + } +}
Copied: trunk/t/205_write_geo_data.t (from rev 1381, trunk/t/25_write_geo_data.t) =================================================================== --- trunk/t/205_write_geo_data.t (rev 0) +++ trunk/t/205_write_geo_data.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,174 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +plan tests => 53; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + use_plucene => 1, + geo_handler => 1, + } +); + +# First check that British National Grid will accept both OS X/Y and lat/long, +# and will store both however the data was given to it. +my $guide = OpenGuides->new( config => $config ); +is( $guide->locator->x_field, "os_x", "correct x field" ); +is( $guide->locator->y_field, "os_y", "correct y field" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + os_x => 523465, + os_y => 177490, + categories => "Pubs", + ); +my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" ); +is( $data{metadata}{os_x}[0], 523465, "os_x stored correctly" ); +is( $data{metadata}{os_y}[0], 177490, "os_y stored correctly" ); +ok( defined $data{metadata}{latitude}[0], "latitude stored" ); +ok( defined $data{metadata}{longitude}[0], "longitude stored" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "El Sombrero", + latitude => 51.368, + longitude => -0.097, + categories => "Restaurants", + ); +%data = $guide->wiki->retrieve_node( "El Sombrero" ); +ok( defined $data{metadata}{os_x}[0], "os_x stored" ); +like( $data{metadata}{os_x}[0], qr/^\d+$/, "...as integer" ); +ok( defined $data{metadata}{os_y}[0], "os_y stored" ); +like( $data{metadata}{os_y}[0], qr/^\d+$/, "...as integer" ); +is( $data{metadata}{latitude}[0], 51.368, "latitude stored correctly" ); +is( $data{metadata}{longitude}[0], -0.097, "longitude stored correctly" ); + +eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + OpenGuides::Test->write_data( + guide => $guide, + node => "Locationless Page 1", + ); +}; +is( $@, "", + "commit doesn't warn when using BNG and node has no location data" ); +%data = $guide->wiki->retrieve_node( "Locationless Page 1" ); +ok( !defined $data{metadata}{latitude}[0], "...and latitude not stored" ); +ok( !defined $data{metadata}{longitude}[0], "...nor longitude" ); +ok( !defined $data{metadata}{os_x}[0], "...nor os_x" ); +ok( !defined $data{metadata}{os_y}[0], "...nor os_y" ); +ok( !defined $data{metadata}{osie_x}[0], "...nor osie_x" ); +ok( !defined $data{metadata}{osie_y}[0], "...nor osie_y" ); + +# Now check Irish National Grid. +$config->geo_handler( 2 ); +$guide = OpenGuides->new( config => $config ); +is( $guide->locator->x_field, "osie_x", "correct x field" ); +is( $guide->locator->y_field, "osie_y", "correct y field" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "I Made This Place Up", + osie_x => 100000, + osie_y => 200000, + ); +%data = $guide->wiki->retrieve_node( "I Made This Place Up" ); +is( $data{metadata}{osie_x}[0], 100000, "osie_x stored correctly" ); +is( $data{metadata}{osie_y}[0], 200000, "osie_y stored correctly" ); +ok( defined $data{metadata}{latitude}[0], "latitude stored" ); +ok( defined $data{metadata}{longitude}[0], "longitude stored" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Brambles Coffee Shop", + latitude => 54.6434, + longitude => -5.6731, + ); +%data = $guide->wiki->retrieve_node( "Brambles Coffee Shop" ); +ok( defined $data{metadata}{osie_x}[0], "osie_x stored" ); +like( $data{metadata}{osie_x}[0], qr/^\d+$/, "...as integer" ); +ok( defined $data{metadata}{osie_y}[0], "osie_y stored" ); +like( $data{metadata}{osie_y}[0], qr/^\d+$/, "...as integer" ); +is( $data{metadata}{latitude}[0], 54.6434, "latitude stored correctly" ); +is( $data{metadata}{longitude}[0], -5.6731, "longitude stored correctly" ); + +eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + OpenGuides::Test->write_data( + guide => $guide, + node => "Locationless Page 2", + ); +}; +is( $@, "", + "commit doesn't warn when using ING and node has no location data" ); +%data = $guide->wiki->retrieve_node( "Locationless Page 2" ); +ok( !defined $data{metadata}{latitude}[0], "...and latitude not stored" ); +ok( !defined $data{metadata}{longitude}[0], "...nor longitude" ); +ok( !defined $data{metadata}{os_x}[0], "...nor os_x" ); +ok( !defined $data{metadata}{os_y}[0], "...nor os_y" ); +ok( !defined $data{metadata}{osie_x}[0], "...nor osie_x" ); +ok( !defined $data{metadata}{osie_y}[0], "...nor osie_y" ); + +# Finally check UTM. +$config->geo_handler( 3 ); +$config->ellipsoid( "Airy" ); +$guide = OpenGuides->new( config => $config ); +is( $guide->locator->x_field, "easting", "correct x field" ); +is( $guide->locator->y_field, "northing", "correct y field" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "London Aquarium", + latitude => 51.502, + longitude => -0.118, + ); +%data = $guide->wiki->retrieve_node( "London Aquarium" ); +ok( defined $data{metadata}{easting}[0], "easting stored" ); +like( $data{metadata}{easting}[0], qr/^\d+$/, "...as integer" ); +ok( defined $data{metadata}{northing}[0], "northing stored" ); +like( $data{metadata}{northing}[0], qr/^\d+$/, "...as integer" ); +is( $data{metadata}{latitude}[0], 51.502, "latitude stored correctly" ); +is( $data{metadata}{longitude}[0], -0.118, "longitude stored correctly" ); + +eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + OpenGuides::Test->write_data( + guide => $guide, + node => "Locationless Page 3", + ); +}; +is( $@, "", + "commit doesn't warn when using UTM and node has no location data" ); +%data = $guide->wiki->retrieve_node( "Locationless Page 3" ); +ok( !defined $data{metadata}{latitude}[0], "...and latitude not stored" ); +ok( !defined $data{metadata}{longitude}[0], "...nor longitude" ); +ok( !defined $data{metadata}{os_x}[0], "...nor os_x" ); +ok( !defined $data{metadata}{os_y}[0], "...nor os_y" ); +ok( !defined $data{metadata}{osie_x}[0], "...nor osie_x" ); +ok( !defined $data{metadata}{osie_y}[0], "...nor osie_y" );
Copied: trunk/t/206_geo_data_search_form.t (from rev 1381, trunk/t/26_geo_data_search_form.t) =================================================================== --- trunk/t/206_geo_data_search_form.t (rev 0) +++ trunk/t/206_geo_data_search_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,124 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; +} + +plan tests => 12; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->use_plucene( 1 ); + +# British National Grid guides should have os_x/os_y/os_dist search fields. +my $guide = OpenGuides->new( config => $config ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Banana Leaf", + os_x => 532125, + os_y => 165504, + ); + +# Display the node, check that the distance search form defaults to OS co-ords +# (stops places being "found" 70m away from themselves due to rounding). +my $output = $guide->display_node( + id => "Banana Leaf", + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "select", { name => "os_dist" }, + "distance select defaults to os_dist with BNG" ); +# Use a regex; Test::HTML::Content can't do this yet I think (read docs, check) +like( $output, qr|select\sname="os_dist".*metres.*kilometres.*/select|is, + "...and to offering distances in metres/kilometres" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "os_x", value => "532125" }, + "...includes input 'os_x' with correct value"); +Test::HTML::Content::tag_ok( $output, "input", + { name => "os_y", value => "165504" }, + "...includes input 'os_y' with correct value"); + + +# Irish National Grid guides should have osie_x/osie_y/osie_dist. +$config->geo_handler( 2 ); +$guide = OpenGuides->new( config => $config ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "I Made This Place Up", + osie_x => 100000, + osie_y => 200000, + ); + +# Display node, check distance search form. +$output = $guide->display_node( + id => "I Made This Place Up", + return_output => 1, + ); + +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "select", { name => "osie_dist" }, + "distance select defaults to osie_dist with ING"); +like( $output, qr|select\sname="osie_dist".*metres.*kilometres.*/select|is, + "...and to offering distances in metres/kilometres" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "osie_x", value => "100000" }, + "...includes input 'osie_x' with correct value"); +Test::HTML::Content::tag_ok( $output, "input", + { name => "osie_y", value => "200000" }, + "...includes input 'osie_y' with correct value"); + + +# UTM guides should have latitude/longitude/latlong_dist. +$config->geo_handler( 3 ); +$config->ellipsoid( "Airy" ); +$guide = OpenGuides->new( config => $config ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "London Aquarium", + latitude => 51.502, + longitude => -0.118, + ); + +# Display node, check distance search form. +# UTM guides currently use latitude/longitude for searching. +$output = $guide->display_node( + id => "London Aquarium", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "select", { name => "latlong_dist" }, + "dist select defaults to latlong_dist with UTM" ); +like( $output, qr|select\sname="latlong_dist".*metres.*kilometres.*/select|is, + "...and to offering distances in metres/kilometres" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "latitude", value => "51.502" }, + "...includes input 'latitude' with correct value"); +Test::HTML::Content::tag_ok( $output, "input", + { name => "longitude", value => "-0.118" }, + "...includes input 'longitude' with correct value");
Copied: trunk/t/207_geo_data_edit_form.t (from rev 1381, trunk/t/27_geo_data_edit_form.t) =================================================================== --- trunk/t/207_geo_data_edit_form.t (rev 0) +++ trunk/t/207_geo_data_edit_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,152 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; +} + +plan tests => 18; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->use_plucene( 1 ); + +# British National Grid guides should have os_x/os_y fields. +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; +# Write some data. +OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + os_x => 523465, + os_y => 177490, + categories => "Pubs", + ); +my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" ); +# Set up the coord_field vars. +my %metadata_vars = OpenGuides::Template->extract_metadata_vars( + wiki => $wiki, + config => $config, + metadata => $data{metadata}, +); +my $output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "edit_form.tt", + vars => %metadata_vars, + ); +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" }, + "BNG defaults to 'os_x' input box..." ); +Test::HTML::Content::tag_ok( $output, "input", { name => "os_x", + value => 523465 }, + "...with correct value..." ); +Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" }, + "...and 'os_y' input box" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "os_y", + value => 177490 }, + "...with correct value..." ); +# Use a regex; Test::HTML::Content can't do this yet I think (read docs, check) +like( $output, qr|OS\sX\scoordinate:|s, + "...'OS X coordinate:' label included" ); +like( $output, qr|OS\sY\scoordinate:|s, + "...'OS Y coordinate:' label included" ); + +# Irish National Grid guides should have osie_x/osie_y fields. +$config->geo_handler( 2 ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; +# Write some data. +OpenGuides::Test->write_data( + guide => $guide, + node => "I Made This Place Up", + osie_x => 100000, + osie_y => 200000, + ); +%data = $guide->wiki->retrieve_node( "I Made This Place Up" ); +# Set up the coord_field vars. +%metadata_vars = OpenGuides::Template->extract_metadata_vars( + wiki => $wiki, + config => $config, + metadata => $data{metadata}, +); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "edit_form.tt", + vars => %metadata_vars, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" }, + "ING defaults to 'osie_x' input box..." ); +Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x", + value => 100000 }, + "...with correct value..." ); +Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" }, + "...and 'osie_y' input box" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y", + value => 200000 }, + "...with correct value..." ); +like( $output, qr|Irish\sNational\sGrid\sX\scoordinate:|s, + "...'Irish National Grid X coordinate:' label included" ); +like( $output, qr|Irish\sNational\sGrid\sY\scoordinate:|s, + "...'Irish National Grid Y coordinate:' label included" ); + +# UTM guides should have lat/long fields. +$config->geo_handler( 3 ); +$config->ellipsoid( "Airy" ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; +# Write some data. +OpenGuides::Test->write_data( + guide => $guide, + node => "London Aquarium", + latitude => 51.502, + longitude => -0.118, + ); +%data = $guide->wiki->retrieve_node( "London Aquarium" ); +# Set up the coord_field vars. +%metadata_vars = OpenGuides::Template->extract_metadata_vars( + wiki => $wiki, + config => $config, + metadata => $data{metadata}, +); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "edit_form.tt", + vars => %metadata_vars, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, + "UTM defaults to 'latitude' input box..." ); +Test::HTML::Content::tag_ok( $output, "input", { name => "latitude", + value => 51.502 }, + "...with correct value..." ); +Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, + "...and 'longitude' input box" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "longitude", + value => -0.118 }, + "...with correct value..." ); +like( $output, qr|Latitude (Airy decimal):|s, + "...'Latitude (Airy decimal):' label included" ); +like( $output, qr|Longitude (Airy decimal):|s, + "...'Longitude (Airy decimal):' label included" );
Copied: trunk/t/208_wgs84_coords.t (from rev 1381, trunk/t/28_wgs84_coords.t) =================================================================== --- trunk/t/208_wgs84_coords.t (rev 0) +++ trunk/t/208_wgs84_coords.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,81 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 6; + +# Clear out the database from any previous runs. + + OpenGuides::Test::refresh_db(); + +# Now we can start testing +my $config = OpenGuides::Test->make_basic_config; +$config->force_wgs84 (1); + +my $guide = OpenGuides->new( config => $config ); + +my ($longitude, $latitude) = (10, 12); + +my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( + longitude => $longitude, + latitude => $latitude, + config => $config); + +is( $wgs_long, $longitude, + "get_wgs84_coords returns the original longitude when force_wgs84 is on"); +is( $wgs_lat, $latitude, + "get_wgs84_coords returns the original latitude when force_wgs84 is on"); + + +# Now claim to be in the UK +eval{ require Geo::HelmertTransform; }; +my $have_helmert = $@ ? 0 : 1; +SKIP : { + skip "Geo::HelmertTransform not installed - can't do transforms", 4 + unless $have_helmert; + + $config->force_wgs84(0); + $config->geo_handler(1); + + # Set our location to be somewhere known + ($longitude,$latitude) = (-1.258200,51.754349); + my ($wgs84_lon,$wgs84_lat) = (-1.259687,51.754813); + + ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( + longitude => $longitude, + latitude => $latitude, + config => $config); + + # Round to 5 dp + my $fivedp = 1 * 1000 * 100; + $wgs_long = int($wgs_long * $fivedp)/$fivedp; + $wgs_lat = int($wgs_lat * $fivedp)/$fivedp; + $wgs84_lon = int($wgs84_lon * $fivedp)/$fivedp; + $wgs84_lat = int($wgs84_lat * $fivedp)/$fivedp; + + is( $wgs_long, $wgs84_lon, + "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); + is( $wgs_lat, $wgs84_lat, + "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); + + # Call it again, check we get the same result + ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( + longitude => $longitude, + latitude => $latitude, + config => $config); + $wgs_long = int($wgs_long * $fivedp)/$fivedp; + $wgs_lat = int($wgs_lat * $fivedp)/$fivedp; + is( $wgs_long, $wgs84_lon, + "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); + is( $wgs_lat, $wgs84_lat, + "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); +}
Deleted: trunk/t/20_edit_form.t =================================================================== --- trunk/t/20_edit_form.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/20_edit_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,36 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; -} - -plan tests => 1; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); - -# Make sure the edit form doesn't display a search form. -my $output = $guide->display_edit_form( - id => "Crabtree Tavern", - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::no_tag( $output, "div", { id => "search_form" }, - "edit form doesn't contain search form" );
Deleted: trunk/t/21_rdf.t =================================================================== --- trunk/t/21_rdf.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/21_rdf.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,181 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Config; -use OpenGuides::RDF; -use OpenGuides::Utils; -use OpenGuides::Test; -use URI::Escape; -use Test::More; - -eval { require DBD::SQLite; }; -my $have_sqlite = $@ ? 0 : 1; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 30; - -# clear out the database -OpenGuides::Test::refresh_db(); - - -my $config = OpenGuides::Test->make_basic_config; -$config->script_url( "http://wiki.example.com/" ); -$config->script_name( "mywiki.cgi" ); -$config->site_name( "Wiki::Toolkit Test Site" ); -$config->default_city( "London" ); -$config->default_country( "United Kingdom" ); -$config->geo_handler( 3 ); - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene ( 0 ) }; - - -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - - -my $rdf_writer = eval { - OpenGuides::RDF->new( wiki => $wiki, config => $config ); -}; -is( $@, "", "'new' doesn't croak if wiki and config objects supplied" ); -isa_ok( $rdf_writer, "OpenGuides::RDF" ); - -# Test the data for a node that exists. -OpenGuides::Test->write_data( - guide => $guide, - node => "Calthorpe Arms", - content => "CAMRA-approved pub near King's Cross", - comment => "Stub page, please update!", - username => "Anonymous", - postcode => "WC1X 8JR", - locales => "Bloomsbury\r\nSt Pancras", - phone => "test phone number", - website => "http://example.com", - hours_text => "test hours", - latitude => "51.524193", - longitude => "-0.114436", - summary => "a really nice pub", -); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Calthorpe Arms", - content => "CAMRA-approved pub near King's Cross", - comment => "Stub page, please update!", - username => "Kake", - postcode => "WC1X 8JR", - locales => "Bloomsbury\r\nSt Pancras", - phone => "test phone number", - website => "http://example.com", - hours_text => "test hours", - latitude => "51.524193", - longitude => "-0.114436", - summary => "a nice pub", - node_image => "http://example.com/calthorpe.jpg", -); - -my $rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); - -like( $rdfxml, qr|<?xml version="1.0" ?>|, "RDF uses no encoding when none set" ); -$config->http_charset( "UTF-8" ); -$guide = OpenGuides->new( config => $config ); -$rdfxml = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms" ); -like( $rdfxml, qr|<?xml version="1.0" encoding="UTF-8"?>|, "RDF uses declared encoding" ); - -like( $rdfxml, qr|<foaf:depiction rdf:resource="http://example.com/calthorpe.jpg" />|, "Node image"); - -like( $rdfxml, qr|<wail:Neighborhood rdf:nodeID="Bloomsbury">|, - "finds the first locale" ); -like( $rdfxml, qr|<wail:Neighborhood rdf:nodeID="St_Pancras">|, - "finds the second locale" ); - -like( $rdfxml, qr|contact:phonetest phone number</contact:phone>|, - "picks up phone number" ); - -like( $rdfxml, qr|dc:availabletest hours</dc:available>|, - "picks up opening hours text" ); - -like( $rdfxml, qr|<foaf:homepage rdf:resource="http://example.com" />|, "picks up website" ); - -like( $rdfxml, - qr|dc:titleWiki::Toolkit Test Site: Calthorpe Arms</dc:title>|, - "sets the title correctly" ); - -like( $rdfxml, qr|id=Kake;format=rdf#obj"|, - "last username to edit used as contributor" ); -like( $rdfxml, qr|id=Anonymous;format=rdf#obj"|, - "... as well as previous usernames" ); - -like( $rdfxml, qr|wiki:version2</wiki:version>|, "version picked up" ); - -like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" ); - -like( $rdfxml, qr|<dc:source rdf:resource="http://wiki.example.com/mywiki.cgi%5C?Calthorpe_Arms" />|, - "set the dc:source with the version-independent uri" ); - -like( $rdfxml, qr|<wail:City rdf:nodeID="city">\n\s+wail:nameLondon</wail:name>|, "city" ). -like( $rdfxml, qr|wail:locatedIn\n\s+<wail:Country rdf:nodeID="country">\n\s+wail:nameUnited Kingdom</wail:name>|, "country" ). -like( $rdfxml, qr|wail:postalCodeWC1X 8JR</wail:postalCode>|, "postcode" ); -like( $rdfxml, qr|geo:lat51.524193</geo:lat>|, "latitude" ); -like( $rdfxml, qr|geo:long-0.114436</geo:long>|, "longitude" ); -like( $rdfxml, qr|dc:descriptiona nice pub</dc:description>|, "summary (description)" ); - -like( $rdfxml, qr|dc:date|, "date element included" ); -unlike( $rdfxml, qr|dc:date1970|, "hasn't defaulted to the epoch" ); - -# Check that default city and country can be set to blank. -$config = OpenGuides::Test->make_basic_config; -$config->default_city( "" ); -$config->default_country( "" ); -$guide = OpenGuides->new( config => $config ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Star Tavern", - latitude => 51.498, - longitude => -0.154, - ); -$rdf_writer = OpenGuides::RDF->new( wiki => $guide->wiki, config => $config ); -$rdfxml = $rdf_writer->emit_rdfxml( node => "Star Tavern" ); -unlike( $rdfxml, qr|<city>|, "no city in RDF when no default city" ); -unlike( $rdfxml, qr|<country>|, "...same for country" ); - -# Now test that there's a nice failsafe where a node doesn't exist. -$rdfxml = eval { $rdf_writer->emit_rdfxml( node => "I Do Not Exist" ); }; -is( $@, "", "->emit_rdfxml doesn't die when called on a nonexistent node" ); - -like( $rdfxml, qr|wiki:version0</wiki:version>|, "...and wiki:version is 0" ); - -# Test the data for a node that redirects. -$wiki->write_node( "Calthorpe Arms Pub", - "#REDIRECT [[Calthorpe Arms]]", - undef, - { - comment => "Created as redirect to Calthorpe Arms page.", - username => "Earle", - } -); - -my $redirect_rdf = $rdf_writer->emit_rdfxml( node => "Calthorpe Arms Pub" ); - -like( $redirect_rdf, qr|<owl:sameAs rdf:resource="/?id=Calthorpe_Arms;format=rdf#obj" />|, - "redirecting node gets owl:sameAs to target" ); - -$wiki->write_node( "Nonesuch Stores", - "A metaphysical wonderland", - undef, - { - comment => "Yup.", - username => "Nobody", - opening_hours_text => "Open All Hours", - } -); - -$rdfxml = $rdf_writer->emit_rdfxml( node => "Nonesuch Stores" ); - -like( $rdfxml, qr|<geo:SpatialThing rdf:ID="obj">|, - "having opening hours marks node as geospatial" ); -
Deleted: trunk/t/22_feed_recent_changes.t =================================================================== --- trunk/t/22_feed_recent_changes.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/22_feed_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,110 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Feed; -use OpenGuides::Test; -use OpenGuides::Utils; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -# Which feed types do we test? -my @feed_types = qw( rss atom ); -plan tests => 12 * scalar @feed_types; - -my %content_types = (rss=>'application/rdf+xml', atom=>'application/atom+xml'); - -foreach my $feed_type (@feed_types) { - # Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - - my $config = OpenGuides::Test->make_basic_config; - $config->script_name( "wiki.cgi" ); - $config->script_url( "http://example.com/" ); - $config->http_charset( "UTF-7" ); - - # Basic sanity check first. - my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - - my $feed = OpenGuides::Feed->new( wiki => $wiki, - config => $config ); - is( $feed->default_content_type($feed_type), $content_types{$feed_type}, "Return the right content type" ); - - like( $feed->html_equiv_link, qr|http://example.com/wiki.cgi%5C?%7C, - "html_equiv_link looks right" ); - - my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); }; - is( $@, "", "->make_feed for $feed_type doesn't croak" ); - - # Ensure that the feed actually contained rss/atom (a good guide - # that we actually got the right feed) - like( $feed_output, "/$feed_type/i", "Does contain the feed type" ); - - # Check the XML - like( $feed_output, qr/<?xml version="1.0" encoding="UTF-7"/, "Right XML type and encoding" ); - - # Now write some data, first a minor edit then a non-minor one. - my $guide = OpenGuides->new( config => $config ); - - OpenGuides::Test->write_data( - node => "Wombats", - guide => $guide, - username => "bob", - edit_type => "Minor tidying", - return_output => 1, - ); - OpenGuides::Test->write_data( - node => "Badgers", - guide => $guide, - username => "bob", - edit_type => "Normal edit", - return_output => 1, - ); - OpenGuides::Test->write_data( - node => "Wombles", - guide => $guide, - username => "Kake", - edit_type => "Normal edit", - return_output => 1, - ); - - # Check that the writes went in. - ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); - ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); - ok( $wiki->node_exists( "Wombles" ), "Wombles written" ); - - # Check that the minor edits can be filtered out. - my $output = $guide->display_feed( - feed_type => $feed_type, - feed_listing => "recent_changes", - items => 5, - username => "bob", - ignore_minor_edits => 1, - return_output => 1, - ); - unlike( $output, qr/Wombats/, "minor edits filtered out when required" ); - like( $output, qr/Badgers/, "but normal edits still in" ); - - # Check that the username parameter is taken notice of. - unlike( $output, qr/Wombles/, "username parameter taken note of" ); - - # Now make sure that the HTTP euiv link still works with a blank scriptname - $config->script_name( "" ); - $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - - $feed = OpenGuides::Feed->new( wiki => $wiki, - config => $config ); - like( $feed->html_equiv_link, qr|http://example.com/%5C?%7C, - "html_equiv_link looks right with blank script_name" ); -}
Deleted: trunk/t/23_feed_node_all_versions.t =================================================================== --- trunk/t/23_feed_node_all_versions.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/23_feed_node_all_versions.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,150 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Feed; -use OpenGuides::Utils; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -# Which feed types do we test? -my @feed_types = qw( rss atom ); -plan tests => 14 * scalar @feed_types; - - -foreach my $feed_type (@feed_types) { - # Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - - my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - use_plucene => 1, - http_charset => "UTF-8" - } - ); - - # Basic sanity check first. - my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - - my $feed = OpenGuides::Feed->new( wiki => $wiki, - config => $config ); - - my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); }; - is( $@, "", "->make_feed for $feed_type doesn't croak" ); - - # Ensure that the feed actually contained rss/atom (a good guide - # that we actually got the right feed) - like( $feed_output, "/$feed_type/i", "Does contain the feed type" ); - - - # Now write some data: 3 versions of one node, and 1 of another - my $guide = OpenGuides->new( config => $config ); - - # Set up CGI parameters ready for a node write. - # Most of these are in here to avoid uninitialised value warnings. - my $q = CGI->new; - $q->param( -name => "content", -value => "foo" ); - $q->param( -name => "categories", -value => "" ); - $q->param( -name => "locales", -value => "" ); - $q->param( -name => "phone", -value => "" ); - $q->param( -name => "fax", -value => "" ); - $q->param( -name => "website", -value => "" ); - $q->param( -name => "hours_text", -value => "" ); - $q->param( -name => "address", -value => "" ); - $q->param( -name => "postcode", -value => "" ); - $q->param( -name => "map_link", -value => "" ); - $q->param( -name => "os_x", -value => "" ); - $q->param( -name => "os_y", -value => "" ); - $q->param( -name => "username", -value => "bob" ); - $q->param( -name => "comment", -value => "foo" ); - $q->param( -name => "edit_type", -value => "Minor tidying" ); - $ENV{REMOTE_ADDR} = "127.0.0.1"; - - # First version of Wombats - my $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - my %node = $wiki->retrieve_node(name=>"Wombats"); - - # Now second and third - $q->param( -name => "edit_type", -value => "Normal edit" ); - $q->param( -name => "checksum", -value => $node{"checksum"} ); - $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - - %node = $wiki->retrieve_node(name=>"Wombats"); - $q->param( -name => "username", -value => "Kake" ); - $q->param( -name => "checksum", -value => $node{"checksum"} ); - $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - - # Now a different node - $q->delete('checksum'); - $output = $guide->commit_node( - return_output => 1, - id => "Badgers", - cgi_obj => $q, - ); - - # Check that the writes went in. - ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); - ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); - is( scalar $wiki->list_node_all_versions("Wombats"), 3, "3 Wombat versions"); - is( scalar $wiki->list_node_all_versions("Badgers"), 1, "1 Badger version"); - - # Fetch for Badgers - $output = $guide->display_feed( - return_output => 1, - feed_type => $feed_type, - feed_listing => "node_all_versions", - name => "Badgers" - ); - unlike( $output, qr/<title>Wombats/, "Was on Badgers, so no wombats" ); - like( $output, qr/<title>Badgers/, "Badgers correctly found" ); - - # Now for Wombats - $output = $guide->display_feed( - return_output => 1, - feed_type => $feed_type, - feed_listing => "node_all_versions", - name => "Wombats" - ); - unlike( $output, qr/<title>Badgers/, "Was on Wombats, so no badgers" ); - like( $output, qr/<title>Wombats/, "Wombats correctly found" ); - - my @wombats = $output =~ /(<title>Wombats)/g; - is( scalar @wombats, 3, "All 3 wombat versions found" ); - - # Check the content type and charset - like( $output, qr/Content-Type: /, "Has content type" ); - like( $output, qr/$feed_type/, "Which is the right one" ); - like( $output, qr/charset=UTF-8/, "And a charset" ); -}
Deleted: trunk/t/24_feed_node_listings.t =================================================================== --- trunk/t/24_feed_node_listings.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/24_feed_node_listings.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,175 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Feed; -use OpenGuides::Utils; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -# Which feed types do we test? -my @feed_types = qw( rss atom ); -plan tests => 17 * scalar @feed_types; - - -foreach my $feed_type (@feed_types) { - # Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - - my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - use_plucene => 1, - http_charset => "UTF-8" - } - ); - - # Basic sanity check first. - my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - - my $feed = OpenGuides::Feed->new( wiki => $wiki, - config => $config ); - - my $feed_output = eval { $feed->make_feed(feed_type => $feed_type, feed_listing => 'recent_changes'); }; - is( $@, "", "->make_feed for $feed_type doesn't croak" ); - - # Ensure that the feed actually contained rss/atom (a good guide - # that we actually got the right feed) - like( $feed_output, "/$feed_type/i", "Does contain the feed type" ); - - - # Now write some data: 3 versions of one node, and 1 of another - my $guide = OpenGuides->new( config => $config ); - - # Set up CGI parameters ready for a node write. - # Most of these are in here to avoid uninitialised value warnings. - my $q = CGI->new; - $q->param( -name => "content", -value => "foo" ); - $q->param( -name => "categories", -value => "" ); - $q->param( -name => "locales", -value => "" ); - $q->param( -name => "phone", -value => "" ); - $q->param( -name => "fax", -value => "" ); - $q->param( -name => "website", -value => "" ); - $q->param( -name => "hours_text", -value => "" ); - $q->param( -name => "address", -value => "" ); - $q->param( -name => "postcode", -value => "" ); - $q->param( -name => "map_link", -value => "" ); - $q->param( -name => "os_x", -value => "" ); - $q->param( -name => "os_y", -value => "" ); - $q->param( -name => "username", -value => "bob" ); - $q->param( -name => "comment", -value => "foo" ); - $q->param( -name => "edit_type", -value => "Minor tidying" ); - $ENV{REMOTE_ADDR} = "127.0.0.1"; - - # First version of Wombats - my $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - my %node = $wiki->retrieve_node(name=>"Wombats"); - - # Now second and third - $q->param( -name => "edit_type", -value => "Normal edit" ); - $q->param( -name => "checksum", -value => $node{"checksum"} ); - $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - - %node = $wiki->retrieve_node(name=>"Wombats"); - $q->param( -name => "username", -value => "Kake" ); - $q->param( -name => "checksum", -value => $node{"checksum"} ); - $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - - # Now a different node - $q->delete('checksum'); - $output = $guide->commit_node( - return_output => 1, - id => "Badgers", - cgi_obj => $q, - ); - - # Check that the writes went in. - ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); - ok( $wiki->node_exists( "Badgers" ), "Badgers written" ); - is( scalar $wiki->list_node_all_versions("Wombats"), 3, "3 Wombat versions"); - is( scalar $wiki->list_node_all_versions("Badgers"), 1, "1 Badger version"); - - - - # Grab a list of all the nodes - my @all_names = $wiki->list_all_nodes(); - my @all_nodes; - foreach my $name (@all_names) { - my %node = $wiki->retrieve_node(name=>$name); - $node{name} = $name; - push @all_nodes, %node; - } - - # Ask build_feed_for_nodes to make a feed of these - $output = $feed->build_feed_for_nodes($feed_type,@all_nodes); - - like( $output, qr/<title>Wombats/, "Found wombats" ); - like( $output, qr/<title>Badgers/, "Found badgers" ); - - # Check it had the extra metadata - if($feed_type eq "rss") { - like( $output, qr/dc:date/, "Found metadata" ); - like( $output, qr/modwiki:diff/, "Found metadata" ); - like( $output, qr/modwiki:version/, "Found metadata" ); - } else { - like( $output, qr/<updated>/, "Found metadata" ); - like( $output, qr/<summary>/, "Found metadata" ); - like( $output, qr/<author>/, "Found metadata" ); - } - - - # Grab a list of the different versions of Wombats - my @wombats = $wiki->list_node_all_versions("Wombats"); - - # Ask build_mini_feed_for_nodes to make a mini feed of these - $output = $feed->build_mini_feed_for_nodes($feed_type,@wombats); - - like( $output, qr/<title>Wombats/, "Wombats had wombats" ); - unlike( $output, qr/<title>Badgers/, "Wombats didn't have Badgers" ); - - @wombats = $output =~ /(<title>Wombats)/g; - is( scalar @wombats, 3, "All 3 wombat versions found" ); - - # Check it was really the mini version - - if($feed_type eq "rss") { - like( $output, qr/<link>/, "Has link" ); - unlike( $output, qr/dc:contributor/, "Really mini version" ); - unlike( $output, qr/modwiki:history/, "Really mini version" ); - } else { - like( $output, qr/<link href=/, "Has link" ); - unlike( $output, qr/<summary>/, "Really mini version" ); - unlike( $output, qr/<author>/, "Really mini version" ); - } -}
Deleted: trunk/t/25_write_geo_data.t =================================================================== --- trunk/t/25_write_geo_data.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/25_write_geo_data.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,174 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -plan tests => 53; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - use_plucene => 1, - geo_handler => 1, - } -); - -# First check that British National Grid will accept both OS X/Y and lat/long, -# and will store both however the data was given to it. -my $guide = OpenGuides->new( config => $config ); -is( $guide->locator->x_field, "os_x", "correct x field" ); -is( $guide->locator->y_field, "os_y", "correct y field" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - os_x => 523465, - os_y => 177490, - categories => "Pubs", - ); -my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" ); -is( $data{metadata}{os_x}[0], 523465, "os_x stored correctly" ); -is( $data{metadata}{os_y}[0], 177490, "os_y stored correctly" ); -ok( defined $data{metadata}{latitude}[0], "latitude stored" ); -ok( defined $data{metadata}{longitude}[0], "longitude stored" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "El Sombrero", - latitude => 51.368, - longitude => -0.097, - categories => "Restaurants", - ); -%data = $guide->wiki->retrieve_node( "El Sombrero" ); -ok( defined $data{metadata}{os_x}[0], "os_x stored" ); -like( $data{metadata}{os_x}[0], qr/^\d+$/, "...as integer" ); -ok( defined $data{metadata}{os_y}[0], "os_y stored" ); -like( $data{metadata}{os_y}[0], qr/^\d+$/, "...as integer" ); -is( $data{metadata}{latitude}[0], 51.368, "latitude stored correctly" ); -is( $data{metadata}{longitude}[0], -0.097, "longitude stored correctly" ); - -eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - OpenGuides::Test->write_data( - guide => $guide, - node => "Locationless Page 1", - ); -}; -is( $@, "", - "commit doesn't warn when using BNG and node has no location data" ); -%data = $guide->wiki->retrieve_node( "Locationless Page 1" ); -ok( !defined $data{metadata}{latitude}[0], "...and latitude not stored" ); -ok( !defined $data{metadata}{longitude}[0], "...nor longitude" ); -ok( !defined $data{metadata}{os_x}[0], "...nor os_x" ); -ok( !defined $data{metadata}{os_y}[0], "...nor os_y" ); -ok( !defined $data{metadata}{osie_x}[0], "...nor osie_x" ); -ok( !defined $data{metadata}{osie_y}[0], "...nor osie_y" ); - -# Now check Irish National Grid. -$config->geo_handler( 2 ); -$guide = OpenGuides->new( config => $config ); -is( $guide->locator->x_field, "osie_x", "correct x field" ); -is( $guide->locator->y_field, "osie_y", "correct y field" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "I Made This Place Up", - osie_x => 100000, - osie_y => 200000, - ); -%data = $guide->wiki->retrieve_node( "I Made This Place Up" ); -is( $data{metadata}{osie_x}[0], 100000, "osie_x stored correctly" ); -is( $data{metadata}{osie_y}[0], 200000, "osie_y stored correctly" ); -ok( defined $data{metadata}{latitude}[0], "latitude stored" ); -ok( defined $data{metadata}{longitude}[0], "longitude stored" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Brambles Coffee Shop", - latitude => 54.6434, - longitude => -5.6731, - ); -%data = $guide->wiki->retrieve_node( "Brambles Coffee Shop" ); -ok( defined $data{metadata}{osie_x}[0], "osie_x stored" ); -like( $data{metadata}{osie_x}[0], qr/^\d+$/, "...as integer" ); -ok( defined $data{metadata}{osie_y}[0], "osie_y stored" ); -like( $data{metadata}{osie_y}[0], qr/^\d+$/, "...as integer" ); -is( $data{metadata}{latitude}[0], 54.6434, "latitude stored correctly" ); -is( $data{metadata}{longitude}[0], -5.6731, "longitude stored correctly" ); - -eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - OpenGuides::Test->write_data( - guide => $guide, - node => "Locationless Page 2", - ); -}; -is( $@, "", - "commit doesn't warn when using ING and node has no location data" ); -%data = $guide->wiki->retrieve_node( "Locationless Page 2" ); -ok( !defined $data{metadata}{latitude}[0], "...and latitude not stored" ); -ok( !defined $data{metadata}{longitude}[0], "...nor longitude" ); -ok( !defined $data{metadata}{os_x}[0], "...nor os_x" ); -ok( !defined $data{metadata}{os_y}[0], "...nor os_y" ); -ok( !defined $data{metadata}{osie_x}[0], "...nor osie_x" ); -ok( !defined $data{metadata}{osie_y}[0], "...nor osie_y" ); - -# Finally check UTM. -$config->geo_handler( 3 ); -$config->ellipsoid( "Airy" ); -$guide = OpenGuides->new( config => $config ); -is( $guide->locator->x_field, "easting", "correct x field" ); -is( $guide->locator->y_field, "northing", "correct y field" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "London Aquarium", - latitude => 51.502, - longitude => -0.118, - ); -%data = $guide->wiki->retrieve_node( "London Aquarium" ); -ok( defined $data{metadata}{easting}[0], "easting stored" ); -like( $data{metadata}{easting}[0], qr/^\d+$/, "...as integer" ); -ok( defined $data{metadata}{northing}[0], "northing stored" ); -like( $data{metadata}{northing}[0], qr/^\d+$/, "...as integer" ); -is( $data{metadata}{latitude}[0], 51.502, "latitude stored correctly" ); -is( $data{metadata}{longitude}[0], -0.118, "longitude stored correctly" ); - -eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - OpenGuides::Test->write_data( - guide => $guide, - node => "Locationless Page 3", - ); -}; -is( $@, "", - "commit doesn't warn when using UTM and node has no location data" ); -%data = $guide->wiki->retrieve_node( "Locationless Page 3" ); -ok( !defined $data{metadata}{latitude}[0], "...and latitude not stored" ); -ok( !defined $data{metadata}{longitude}[0], "...nor longitude" ); -ok( !defined $data{metadata}{os_x}[0], "...nor os_x" ); -ok( !defined $data{metadata}{os_y}[0], "...nor os_y" ); -ok( !defined $data{metadata}{osie_x}[0], "...nor osie_x" ); -ok( !defined $data{metadata}{osie_y}[0], "...nor osie_y" );
Deleted: trunk/t/26_geo_data_search_form.t =================================================================== --- trunk/t/26_geo_data_search_form.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/26_geo_data_search_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,124 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; -} - -plan tests => 12; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->use_plucene( 1 ); - -# British National Grid guides should have os_x/os_y/os_dist search fields. -my $guide = OpenGuides->new( config => $config ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Banana Leaf", - os_x => 532125, - os_y => 165504, - ); - -# Display the node, check that the distance search form defaults to OS co-ords -# (stops places being "found" 70m away from themselves due to rounding). -my $output = $guide->display_node( - id => "Banana Leaf", - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "select", { name => "os_dist" }, - "distance select defaults to os_dist with BNG" ); -# Use a regex; Test::HTML::Content can't do this yet I think (read docs, check) -like( $output, qr|select\sname="os_dist".*metres.*kilometres.*/select|is, - "...and to offering distances in metres/kilometres" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "os_x", value => "532125" }, - "...includes input 'os_x' with correct value"); -Test::HTML::Content::tag_ok( $output, "input", - { name => "os_y", value => "165504" }, - "...includes input 'os_y' with correct value"); - - -# Irish National Grid guides should have osie_x/osie_y/osie_dist. -$config->geo_handler( 2 ); -$guide = OpenGuides->new( config => $config ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "I Made This Place Up", - osie_x => 100000, - osie_y => 200000, - ); - -# Display node, check distance search form. -$output = $guide->display_node( - id => "I Made This Place Up", - return_output => 1, - ); - -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "select", { name => "osie_dist" }, - "distance select defaults to osie_dist with ING"); -like( $output, qr|select\sname="osie_dist".*metres.*kilometres.*/select|is, - "...and to offering distances in metres/kilometres" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "osie_x", value => "100000" }, - "...includes input 'osie_x' with correct value"); -Test::HTML::Content::tag_ok( $output, "input", - { name => "osie_y", value => "200000" }, - "...includes input 'osie_y' with correct value"); - - -# UTM guides should have latitude/longitude/latlong_dist. -$config->geo_handler( 3 ); -$config->ellipsoid( "Airy" ); -$guide = OpenGuides->new( config => $config ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "London Aquarium", - latitude => 51.502, - longitude => -0.118, - ); - -# Display node, check distance search form. -# UTM guides currently use latitude/longitude for searching. -$output = $guide->display_node( - id => "London Aquarium", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "select", { name => "latlong_dist" }, - "dist select defaults to latlong_dist with UTM" ); -like( $output, qr|select\sname="latlong_dist".*metres.*kilometres.*/select|is, - "...and to offering distances in metres/kilometres" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "latitude", value => "51.502" }, - "...includes input 'latitude' with correct value"); -Test::HTML::Content::tag_ok( $output, "input", - { name => "longitude", value => "-0.118" }, - "...includes input 'longitude' with correct value");
Deleted: trunk/t/27_geo_data_edit_form.t =================================================================== --- trunk/t/27_geo_data_edit_form.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/27_geo_data_edit_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,152 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; -} - -plan tests => 18; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->use_plucene( 1 ); - -# British National Grid guides should have os_x/os_y fields. -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; -# Write some data. -OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - os_x => 523465, - os_y => 177490, - categories => "Pubs", - ); -my %data = $guide->wiki->retrieve_node( "Crabtree Tavern" ); -# Set up the coord_field vars. -my %metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $wiki, - config => $config, - metadata => $data{metadata}, -); -my $output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "edit_form.tt", - vars => %metadata_vars, - ); -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" }, - "BNG defaults to 'os_x' input box..." ); -Test::HTML::Content::tag_ok( $output, "input", { name => "os_x", - value => 523465 }, - "...with correct value..." ); -Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" }, - "...and 'os_y' input box" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "os_y", - value => 177490 }, - "...with correct value..." ); -# Use a regex; Test::HTML::Content can't do this yet I think (read docs, check) -like( $output, qr|OS\sX\scoordinate:|s, - "...'OS X coordinate:' label included" ); -like( $output, qr|OS\sY\scoordinate:|s, - "...'OS Y coordinate:' label included" ); - -# Irish National Grid guides should have osie_x/osie_y fields. -$config->geo_handler( 2 ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; -# Write some data. -OpenGuides::Test->write_data( - guide => $guide, - node => "I Made This Place Up", - osie_x => 100000, - osie_y => 200000, - ); -%data = $guide->wiki->retrieve_node( "I Made This Place Up" ); -# Set up the coord_field vars. -%metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $wiki, - config => $config, - metadata => $data{metadata}, -); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "edit_form.tt", - vars => %metadata_vars, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" }, - "ING defaults to 'osie_x' input box..." ); -Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x", - value => 100000 }, - "...with correct value..." ); -Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" }, - "...and 'osie_y' input box" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y", - value => 200000 }, - "...with correct value..." ); -like( $output, qr|Irish\sNational\sGrid\sX\scoordinate:|s, - "...'Irish National Grid X coordinate:' label included" ); -like( $output, qr|Irish\sNational\sGrid\sY\scoordinate:|s, - "...'Irish National Grid Y coordinate:' label included" ); - -# UTM guides should have lat/long fields. -$config->geo_handler( 3 ); -$config->ellipsoid( "Airy" ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; -# Write some data. -OpenGuides::Test->write_data( - guide => $guide, - node => "London Aquarium", - latitude => 51.502, - longitude => -0.118, - ); -%data = $guide->wiki->retrieve_node( "London Aquarium" ); -# Set up the coord_field vars. -%metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $wiki, - config => $config, - metadata => $data{metadata}, -); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "edit_form.tt", - vars => %metadata_vars, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, - "UTM defaults to 'latitude' input box..." ); -Test::HTML::Content::tag_ok( $output, "input", { name => "latitude", - value => 51.502 }, - "...with correct value..." ); -Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, - "...and 'longitude' input box" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "longitude", - value => -0.118 }, - "...with correct value..." ); -like( $output, qr|Latitude (Airy decimal):|s, - "...'Latitude (Airy decimal):' label included" ); -like( $output, qr|Longitude (Airy decimal):|s, - "...'Longitude (Airy decimal):' label included" );
Deleted: trunk/t/28_wgs84_coords.t =================================================================== --- trunk/t/28_wgs84_coords.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/28_wgs84_coords.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,81 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 6; - -# Clear out the database from any previous runs. - - OpenGuides::Test::refresh_db(); - -# Now we can start testing -my $config = OpenGuides::Test->make_basic_config; -$config->force_wgs84 (1); - -my $guide = OpenGuides->new( config => $config ); - -my ($longitude, $latitude) = (10, 12); - -my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( - longitude => $longitude, - latitude => $latitude, - config => $config); - -is( $wgs_long, $longitude, - "get_wgs84_coords returns the original longitude when force_wgs84 is on"); -is( $wgs_lat, $latitude, - "get_wgs84_coords returns the original latitude when force_wgs84 is on"); - - -# Now claim to be in the UK -eval{ require Geo::HelmertTransform; }; -my $have_helmert = $@ ? 0 : 1; -SKIP : { - skip "Geo::HelmertTransform not installed - can't do transforms", 4 - unless $have_helmert; - - $config->force_wgs84(0); - $config->geo_handler(1); - - # Set our location to be somewhere known - ($longitude,$latitude) = (-1.258200,51.754349); - my ($wgs84_lon,$wgs84_lat) = (-1.259687,51.754813); - - ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( - longitude => $longitude, - latitude => $latitude, - config => $config); - - # Round to 5 dp - my $fivedp = 1 * 1000 * 100; - $wgs_long = int($wgs_long * $fivedp)/$fivedp; - $wgs_lat = int($wgs_lat * $fivedp)/$fivedp; - $wgs84_lon = int($wgs84_lon * $fivedp)/$fivedp; - $wgs84_lat = int($wgs84_lat * $fivedp)/$fivedp; - - is( $wgs_long, $wgs84_lon, - "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); - is( $wgs_lat, $wgs84_lat, - "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); - - # Call it again, check we get the same result - ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords( - longitude => $longitude, - latitude => $latitude, - config => $config); - $wgs_long = int($wgs_long * $fivedp)/$fivedp; - $wgs_lat = int($wgs_lat * $fivedp)/$fivedp; - is( $wgs_long, $wgs84_lon, - "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); - is( $wgs_lat, $wgs84_lat, - "get_wgs84_coords does Airy1830 -> WGS84 convertion properly"); -}
Copied: trunk/t/300_search_raw.t (from rev 1381, trunk/t/30_search_raw.t) =================================================================== --- trunk/t/300_search_raw.t (rev 0) +++ trunk/t/300_search_raw.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,81 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 16; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $search = OpenGuides::Search->new( config => $config ); + +my %results; + +%results = $search->run( vars => { format => "raw" } ); +is_deeply( %results, { }, + "raw search returns empty hash if no criteria supplied" ); +%results = $search->run( vars => { search => "banananana", format => "raw" } ); +is_deeply( %results, { }, + "raw search returns empty hash if no hits on search string" ); + +# Pop some data in and search again. +OpenGuides::Test->write_data( guide => $guide, + node => "Red Lion", + content => "A nice pub in Anyville.", + summary => "Nice pub.", + os_x => 500000, + os_y => 150000, + ); +OpenGuides::Test->write_data( guide => $guide, + node => "Blacksmiths Arms", + content => "Not a very nice pub.", + summary => "Rubbish pub.", + os_x => 500100, + os_y => 150000, + ); +OpenGuides::Test->write_data( guide => $guide, + node => "Carpenters Arms", + content => "Not a bad pub.", + summary => "Average pub.", + os_x => 450000, + os_y => 140000, + ); + +%results = $search->run( vars => { search => "arms", format => "raw" } ); +is_deeply( [ sort keys %results ], [ "Blacksmiths Arms", "Carpenters Arms" ], + "raw search on single word finds the right nodes" ); +my %ba = %{$results{"Blacksmiths Arms"}}; +is( $ba{name}, "Blacksmiths Arms", "result hash has correct name" ); +is( $ba{summary}, "Rubbish pub.", "...and correct summary" ); +ok( $ba{wgs84_long}, "...WGS-84 latitude returned" ); +ok( $ba{wgs84_lat}, "...WGS-84 longitude returned" ); +ok( $ba{score}, "...score returned" ); +ok( !$ba{distance}, "...no distance returned" ); + +# Now try a distance search. +%results = $search->run( + vars => { + os_dist => 1000, + os_x => 500200, + os_y => 150000, + format => "raw", + } ); +is_deeply( [ sort keys %results ], [ "Blacksmiths Arms", "Red Lion" ], + "raw distance search finds the right nodes" ); +my %rl = %{$results{"Red Lion"}}; +is( $rl{name}, "Red Lion", "result hash has correct name" ); +is( $rl{summary}, "Nice pub.", "...and correct summary" ); +ok( $rl{wgs84_lat}, "...WGS-84 latitude returned" ); +ok( $rl{wgs84_long}, "...WGS-84 longitude returned" ); +ok( !$rl{score}, "...no score returned" ); +is( $rl{distance}, 200, "...correct distance returned" );
Copied: trunk/t/301_search.t (from rev 1381, trunk/t/31_search.t) =================================================================== --- trunk/t/301_search.t (rev 0) +++ trunk/t/301_search.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,153 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 18; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); + +# Plucene is the recommended searcher now. +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene( 0 ) }; + +my $search = OpenGuides::Search->new( config => $config ); +isa_ok( $search, "OpenGuides::Search" ); + +my $output = $search->run( return_output => 1 ); +unlike( $output, qr/no items matched/i, + "doesn't output 'no items matched' if no terms supplied" ); +unlike( $output, qr/action=edit/, + "doesn't offer edit link" ); + +my %tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "banana" }, + ); +is( $tt_vars{first_num}, 0, "first_num set to 0 when no hits" ); +is( scalar @{ $tt_vars{results} }, 0, "...and results array empty" ); + +$output = $search->run( + return_output => 1, + vars => { search => "banana" } + ); +like( $output, qr/no items matched/i, + "outputs 'no items matched' if term not found" ); +unlike( $output, qr/matches found, showing/i, + "doesn't output 'matches found, showing' if term not found" ); + +# Pop some data in and search again. +my $wiki = $search->{wiki}; # white boxiness +$wiki->write_node( "Banana", "banana" ); +$wiki->write_node( "Monkey", "banana brains" ); +$wiki->write_node( "Monkey Brains", "BRANES" ); +$wiki->write_node( "Want Pie Now", "weebl" ); +$wiki->write_node( "Punctuation", "*" ); +$wiki->write_node( "Choice", "Eenie meenie minie mo"); + +# Test with two hits first - simpler. +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "banana" }, + ); +my @found = map { $_->{name} } @{ $tt_vars{results} || [] }; +is( scalar @found, 2, "search finds single word twice" ); +is_deeply( [ sort @found ], [ "Banana", "Monkey" ], + "...in the right places" ); +print "# Found in $_\n" foreach @found; + +# Make sure that $output matches too - we're testing the template here. +$output = $search->run( + return_output => 1, + vars => { search => "banana" }, + ); +like( $output, qr/<a href="http:\/\/example.com\/wiki.cgi\?Banana">/, + "...and link is included in template output" ); + +# One hit in body only should show result list. +$output = $search->run( + return_output => 1, + vars => { search => "weebl" }, + ); +unlike( $output, qr/Status: 302/, + "no redirect if match only in body"); + +# One hit in title should redirect to that page. +$output = $search->run( + return_output => 1, + vars => { search => "want pie now" }, + ); +like( $output, qr/Status: 302/, + "prints redirect on single hit and match in title" ); +# Old versions of CGI.pm mistakenly print location: instead of Location: +like( $output, + qr/[lL]ocation: http://example.com/wiki.cgi?Want_Pie_Now/, + "...and node name munged correctly in URL" ); + +# Test the AND search +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "monkey banana" }, + ); +@found = map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Monkey" ], "AND search returns right results" ); + +# Test the OR search +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "brains, pie" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Monkey", "Monkey Brains", "Want Pie Now" ], + "OR search returns right results" ); +print "# Found in $_\n" foreach @found; + +SKIP: { + skip "NOT search not done yet", 1; +# Test the NOT search +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "banana -monkey" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Banana" ], "NOT search returns right results" ); +} # end of SKIP + +# Test the phrase search +$output = $search->run( + return_output => 1, + vars => { search => '"monkey brains"' }, + ); +like( $output, + qr/[lL]ocation: http://example.com/wiki.cgi?Monkey_Brains/, + "phrase search returns right results and redirects to page" + ); + +##### +##### Test numbering when we have more than a page of results. +##### + +foreach my $i ( 1 .. 30 ) { + $wiki->write_node( "Node $i", "wombat" ) or die "Can't write Node $i"; +} +$output = $search->run( + return_output => 1, + vars => { + search => "wombat", + next => 20, + }, + ); +like( $output, qr/ol start="21"/, + "second page of results starts with right numbering" );
Copied: trunk/t/302_search_simple_metadata.t (from rev 1381, trunk/t/32_search_simple_metadata.t) =================================================================== --- trunk/t/302_search_simple_metadata.t (rev 0) +++ trunk/t/302_search_simple_metadata.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,129 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 10; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + } +); + +# Plucene is the recommended searcher now. +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene( 0 ) }; + +my $search = OpenGuides::Search->new( config => $config ); + +# Add some data. We write it twice to avoid hitting the redirect. +my $wiki = $search->{wiki}; # white boxiness +$wiki->write_node( "Calthorpe Arms", "Serves beer.", undef, + { category => "Pubs", locale => "Holborn" } ); +$wiki->write_node( "Penderel's Oak", "Serves beer.", undef, + { category => "Pubs", locale => "Holborn" } ); +$wiki->write_node( "British Museum", "Huge museum, lots of artifacts.", undef, + { category => ["Museums", "Major Attractions"] + , locale => ["Holborn", "Bloomsbury"] } ); + +# Check that a search on its category works. +my %tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "Pubs" }, + ); +my @found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], + "simple search looks in category" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "pubs" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], + "...and is case-insensitive" ); + +# Check that a search on its locale works. +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "Holborn" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ], + "simple search looks in locale" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "holborn" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ], + "...and is case-insensitive" ); + +# Test AND search in various combinations. +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "Holborn Pubs" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], + "AND search works between category and locale" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "Holborn Penderel" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Penderel's Oak" ], + "AND search works between title and locale" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "Pubs Penderel" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Penderel's Oak" ], + "AND search works between title and category" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "Holborn beer" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], + "...and between body and locale" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "Pubs beer" }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], + "...and between body and category" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => '"major attractions"' }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "British Museum", ], + "Multi word category name" );
Copied: trunk/t/303_search_advanced_search.t (from rev 1381, trunk/t/33_search_advanced_search.t) =================================================================== --- trunk/t/303_search_advanced_search.t (rev 0) +++ trunk/t/303_search_advanced_search.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,186 @@ +use strict; +use Wiki::Toolkit::Plugin::Locator::Grid; # use directly to help debug +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +plan tests => 9; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + use_plucene => 1, + geo_handler => 1, + } +); +my $search = OpenGuides::Search->new( config => $config ); +my $guide = OpenGuides->new( config => $config ); + +# Write some data. +OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + os_x => 523465, + os_y => 177490, + categories => "Pubs", + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Blue Anchor", + os_x => 522909, + os_y => 178232, + categories => "Pubs", + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Star Tavern", + os_x => 528107, + os_y => 179347, + categories => "Pubs", + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Hammersmith Bridge", + os_x => 522983, + os_y => 178118, + ); + +# Sanity check. +print "# Distances should be:\n"; +my $locator = Wiki::Toolkit::Plugin::Locator::Grid->new(x => "os_x", y => "os_y"); +my $wiki = $guide->wiki; +$wiki->register_plugin( plugin => $locator ); +foreach my $node ( "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge"){ + print "# $node: " . $locator->distance( from_x => 523450, + from_y => 177650, + to_node => $node ) . "\n"; +} + +# Check that a lat/long distance search finds them. +my %tt_vars = $search->run( + return_tt_vars => 1, + vars => { + latitude => 51.484320, + longitude => -0.223484, + latlong_dist => 1000, + }, + ); +my @ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; +my @found = sort @ordered; +is_deeply( @found, + [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], + "distance search finds the right things" ); +is_deeply( @ordered, + [ "Crabtree Tavern", "Hammersmith Bridge", "Blue Anchor" ], + "...and returns them in the right order" ); +my $output = $search->run( + return_output => 1, + vars => { + latitude => 51.484320, + longitude => -0.223484, + latlong_dist => 1000, + }, + ); +unlike( $output, qr|(score:\s+)|, "...no spurious 'scores' printed" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { + latitude => 51.484320, + longitude => -0.223484, + latlong_dist => 1000, + search => " ", + }, + ); +@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; +@found = sort @ordered; +is_deeply( @found, + [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], + "...still works if whitespace-only search text supplied" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { + os_x => 523450, + os_y => 177650, + os_dist => 1000, + search => " ", + }, + ); +@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; +@found = sort @ordered; +is_deeply( @found, + [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], + "...works with OS co-ords" ); + +%tt_vars = eval { + $search->run( + return_tt_vars => 1, + vars => { + os_x => 523450, + os_y => 177650, + os_dist => 1000, + search => " ", + latitude => " ", + longitude => " ", + }, + ); +}; +is( $@, "", "...works with OS co-ords and whitespace-only lat/long" ); +@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; +@found = sort @ordered; +is_deeply( @found, + [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], + "...returns the right stuff" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { + latitude => 51.484320, + longitude => -0.223484, + latlong_dist => 1000, + search => "pubs", + }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Blue Anchor", "Crabtree Tavern", ], + "distance search in combination with text search works" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { + os_x => 523450, + os_y => 177650, + os_dist => 1000, + search => "pubs", + }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Blue Anchor", "Crabtree Tavern", ], + "...works with OS co-ords too" );
Copied: trunk/t/303_search_advanced_search_utm.t (from rev 1381, trunk/t/33_search_advanced_search_utm.t) =================================================================== --- trunk/t/303_search_advanced_search_utm.t (rev 0) +++ trunk/t/303_search_advanced_search_utm.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,127 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +plan tests => 4; + +# Clear out the database from any previous runs. + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + use_plucene => 1, + geo_handler => 3, + ellipsoid => "Airy", + } +); +my $search = OpenGuides::Search->new( config => $config ); +my $guide = OpenGuides->new( config => $config ); + +# Write some data. +OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + latitude => 51.482385, + longitude => -0.221743, + categories => "Pubs", + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Blue Anchor", + latitude => 51.489176, + longitude => -0.229488, + categories => "Pubs", + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Star Tavern", + latitude => 51.498043, + longitude => -0.154247, + categories => "Pubs", + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Hammersmith Bridge", + latitude => 51.488135, + longitude => -0.228463, + ); + +# Sanity check. +print "# Distances should be round about:\n"; +my $locator = $guide->locator; +foreach my $node ( "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge"){ + print "# $node: " . $locator->distance( from_x => 692756, + from_y => 5706917, + to_node => $node ) . "\n"; +} + +# Check that a lat/long distance search finds them. +my %tt_vars = $search->run( + return_tt_vars => 1, + vars => { + latitude => 51.484320, + longitude => -0.223484, + latlong_dist => 1000, + }, + ); +my @ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; +my @found = sort @ordered; +is_deeply( @found, + [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], + "distance search finds the right things" ); +is_deeply( @ordered, + [ "Crabtree Tavern", "Hammersmith Bridge", "Blue Anchor" ], + "...and returns them in the right order" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { + latitude => 51.484320, + longitude => -0.223484, + latlong_dist => 1000, + search => " ", + }, + ); +@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; +@found = sort @ordered; +is_deeply( @found, + [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], + "...still works if whitespace-only search text supplied" ); + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { + latitude => 51.484320, + longitude => -0.223484, + latlong_dist => 1000, + search => "pubs", + }, + ); +@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @found, [ "Blue Anchor", "Crabtree Tavern", ], + "distance search in combination with text search works" );
Copied: trunk/t/304_search_paging.t (from rev 1381, trunk/t/34_search_paging.t) =================================================================== --- trunk/t/304_search_paging.t (rev 0) +++ trunk/t/304_search_paging.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,139 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +plan tests => 18; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + + +my $config = OpenGuides::Test->make_basic_config; +$config->use_plucene( 1 ); +my $search = OpenGuides::Search->new( config => $config ); +my $guide = OpenGuides->new( config => $config ); + +# Test with OS co-ords. + $config->geo_handler( 1 ); + + foreach my $i ( 1 .. 50 ) { + OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern $i", + os_x => 523465, + os_y => 177490, + categories => "Pubs", + ); + } + + my $output = $search->run( + return_output => 1, + vars => { + os_dist => 1500, + os_x => 523500, + os_y => 177500, + next => 21, + }, + ); + like( $output, qr/search.cgi?.*os_x=523500.*Next.*results/s, + "os_x retained in next page link" ); + like( $output, qr/search.cgi?.*os_y=177500.*Next.*results/s, + "os_y retained in next page link" ); + like( $output, qr/search.cgi?.*os_dist=1500.*Next.*results/s, + "os_dist retained in next page link" ); + like( $output, qr/search.cgi?.*os_x=523500.*Previous.*results/s, + "os_x retained in previous page link" ); + like( $output, qr/search.cgi?.*os_y=177500.*Previous.*results/s, + "os_y retained in previous page link" ); + like( $output, qr/search.cgi?.*os_dist=1500.*Previous.*results/s, + "os_dist retained in previous page link" ); + +# Test with OSIE co-ords. + + # We must create a new search object after changing the geo_handler + # in order to force it to create a fresh locator. + $config->geo_handler( 2 ); + $search = OpenGuides::Search->new( config => $config ); + + foreach my $i ( 1 .. 50 ) { + OpenGuides::Test->write_data( + guide => $guide, + node => "I Made This Place Up $i", + osie_x => 100005, + osie_y => 200005, + ); + } + + $output = $search->run( + return_output => 1, + vars => { + osie_dist => 1500, + osie_x => 100000, + osie_y => 200000, + next => 21, + }, + ); + like( $output, qr/search.cgi?.*osie_x=100000.*Next.*results/s, + "osie_x retained in next page link" ); + like( $output, qr/search.cgi?.*osie_y=200000.*Next.*results/s, + "osie_y retained in next page link" ); + like( $output, qr/search.cgi?.*osie_dist=1500.*Next.*results/s, + "osie_dist retained in next page link" ); + like( $output, qr/search.cgi?.*osie_x=100000.*Previous.*results/s, + "osie_x retained in previous page link" ); + like( $output, qr/search.cgi?.*osie_y=200000.*Previous.*results/s, + "osie_y retained in previous page link" ); + like( $output, qr/search.cgi?.*osie_dist=1500.*Previous.*results/s, + "osie_dist retained in previous page link" ); + +# Test with UTM. + + # We must create a new search object after changing the geo_handler + # in order to force it to create a fresh locator. + $config->geo_handler( 3 ); + $search = OpenGuides::Search->new( config => $config ); + + foreach my $i ( 1 .. 50 ) { + OpenGuides::Test->write_data( + guide => $guide, + node => "London Aquarium $i", + latitude => 51.502, + longitude => -0.118, + ); + } + + $output = $search->run( + return_output => 1, + vars => { + latlong_dist => 1500, + latitude => 51.5, + longitude => -0.12, + next => 21, + }, + ); + like( $output, qr/search.cgi?.*latitude=51.5.*Next.*results/s, + "latitude retained in next page link" ); + like( $output, qr/search.cgi?.*longitude=-0.12.*Next.*results/s, + "longitude retained in next page link" ); + like( $output, qr/search.cgi?.*latlong_dist=1500.*Next.*results/s, + "latlong_dist retained in next page link" ); + like( $output, qr/search.cgi?.*latitude=51.5.*Previous.*results/s, + "latitude retained in previous page link" ); + like( $output, qr/search.cgi?.*longitude=-0.12.*Previous.*results/s, + "longitude retained in previous page link" ); + like( $output, qr/search.cgi?.*latlong_dist=1500.*Previous.*results/s, + "latlong_dist retained in previous page link" );
Copied: trunk/t/305_search_two_searches.t (from rev 1381, trunk/t/35_search_two_searches.t) =================================================================== --- trunk/t/305_search_two_searches.t (rev 0) +++ trunk/t/305_search_two_searches.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,122 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +plan tests => 10; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + geo_handler => 1, + } +); + +# Plucene is the recommended searcher now. +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene( 0 ) }; + +my $search = OpenGuides::Search->new( config => $config ); + +# Write some data. +my $wiki = $search->{wiki}; +$wiki->write_node( "Wandsworth Common", "A common.", undef, + { category => "Parks" } ) + or die "Can't write node"; +$wiki->write_node( "Hammersmith", "A page about Hammersmith." ) + or die "Can't write node"; + +# Check that the search forgets input search term between invocations. +$search->run( + return_output => 1, + vars => { search => "parks" }, + ); +ok( $search->{search_string}, "search_string set" ); +$search->run( + return_output => 1, + ); +ok( !$search->{search_string}, "...and forgotten" ); + +# Sanity check. +my (@results, %tt_vars); +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "parks" }, + ); +@results = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @results, [ "Wandsworth Common" ], + "first search returns expected results" ); +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "hammersmith" }, + ); +@results = sort map { $_->{name} } @{ $tt_vars{results} || [] }; +is_deeply( @results, [ "Hammersmith" ], + "so does second" ); + +# Check that the search forgets input geodata between invocations. +# First with British National Grid. +$search->run( + return_output => 1, + vars => { os_x => 500000, os_y => 100000, os_dist => 1000 }, + ); +ok( $search->{x}, "x-coord set" ); +$search->run( + return_output => 1, + vars => { search => "foo" }, + ); +ok( !$search->{x}, "...and forgotten" ); + +# Now with Irish National Grid. +$config->geo_handler( 2 ); +$search = OpenGuides::Search->new( config => $config ); +$search->run( + return_output => 1, + vars => { osie_x => 100000, osie_y => 200000, osie_dist => 100 }, + ); +ok( $search->{x}, "x-coord set" ); +$search->run( + return_output => 1, + vars => { search => "foo" }, + ); +ok( !$search->{x}, "...and forgotten" ); + +# Now with UTM. +$config->geo_handler( 3 ); +$config->ellipsoid( "Airy" ); +$search = OpenGuides::Search->new( config => $config ); +$search->run( + return_output => 1, + vars => { latitude => 10, longitude => 0, latlong_dist => 1000 }, + ); +ok( $search->{x}, "x-coord set" ); +$search->run( + return_output => 1, + vars => { search => "foo" }, + ); +ok( !$search->{x}, "...and forgotten" ); + +
Copied: trunk/t/306_search_order.t (from rev 1381, trunk/t/36_search_order.t) =================================================================== --- trunk/t/306_search_order.t (rev 0) +++ trunk/t/306_search_order.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,139 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +plan tests => 9; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + use_plucene => 1 + } +); + +my $search = OpenGuides::Search->new( config => $config ); +isa_ok( $search, "OpenGuides::Search" ); + +# Write some data. +my $wiki = $search->{wiki}; +$wiki->write_node( "Parks", "A page about parks." ) + or die "Can't write node"; +$wiki->write_node( "Wandsworth Common", "A common.", undef, + { category => "Parks" } ) + or die "Can't write node"; +$wiki->write_node( "Kake", "I like walking in parks." ) + or die "Can't write node"; + +my %tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "parks" }, + ); +foreach my $result ( @{ $tt_vars{results} || [] } ) { + print "# $result->{name} scores $result->{score}\n"; +} +my %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; +ok( $scores{Kake} < $scores{'Wandsworth Common'}, + "content match scores less than category match" ); +ok( $scores{'Wandsworth Common'} < $scores{Parks}, + "title match scores more than category match" ); + +# Now test locales. +$wiki->write_node( "Hammersmith", "A page about Hammersmith." ) + or die "Can't write node"; +$wiki->write_node( "The Gate", "A restaurant.", undef, + { locale => "Hammersmith" } ) + or die "Can't write node"; +$wiki->write_node( "Kake Pugh", "I live in Hammersmith." ) + or die "Can't write node"; + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "hammersmith" }, + ); +foreach my $result ( @{ $tt_vars{results} || [] } ) { + print "# $result->{name} scores $result->{score}\n"; +} +%scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; +ok( $scores{'Kake Pugh'} < $scores{'The Gate'}, + "content match scores less than locale match" ); +ok( $scores{'The Gate'} < $scores{Hammersmith}, + "locale match scores less than title match" ); + +# Check that two words in the title beats one in the title and +# one in the content. +$wiki->write_node( "Putney Tandoori", "Indian food" ) + or die "Couldn't write node"; +$wiki->write_node( "Putney", "There is a tandoori restaurant here" ) + or die "Couldn't write node"; + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "putney tandoori" }, + ); +foreach my $result ( @{ $tt_vars{results} || [] } ) { + print "# $result->{name} scores $result->{score}\n"; +} +%scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; +ok( $scores{Putney} < $scores{'Putney Tandoori'}, + "two words in title beats one in title and one in content" ); + +SKIP: { + skip "Word proximity not yet taken into account", 1; +# Check that in an AND match words closer together get higher priority. +$wiki->write_node( "Spitalfields Market", + "Mango juice from the Indian stall" ) + or die "Can't write node"; +$wiki->write_node( "Borough Market", "dried mango and real apple juice" ) + or die "Can't write node"; + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "mango juice" }, + ); +foreach my $result ( @{ $tt_vars{results} || [] } ) { + print "# $result->{name} scores $result->{score}\n"; +} +%scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; +ok( $scores{'Borough Market'} < $scores{'Spitalfields Market'}, + "words closer together gives higher score" ); +} # end of SKIP + +# Check that the number of occurrences of the search term is significant. + +$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"; +$wiki->write_node( "The Pub", "A pub.", undef, { category => "Pubs" } ) or die "Can't write node"; + +%tt_vars = $search->run( + return_tt_vars => 1, + vars => { search => "pub" } + ); +foreach my $result ( @{ $tt_vars{results} || [] } ) { + print "# $result->{name} scores $result->{score}\n"; +} +is( $tt_vars{results}[0]{name}, "Pub Crawls", + "node with two mentions of search term comes top" ); +ok( $tt_vars{results}[0]{score} > $tt_vars{results}[1]{score}, + "...with a score strictly greater than node with one mention" );
Copied: trunk/t/307_search_summaries.t (from rev 1381, trunk/t/37_search_summaries.t) =================================================================== --- trunk/t/307_search_summaries.t (rev 0) +++ trunk/t/307_search_summaries.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,48 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 2; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + } +); + +# Plucene is the recommended searcher now. +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene( 0 ) }; + +my $search = OpenGuides::Search->new( config => $config ); +isa_ok( $search, "OpenGuides::Search" ); +my $wiki = $search->wiki; +$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"; + +my $output = $search->run( + return_output => 1, + vars => { search => "pub" } + ); +SKIP: { + skip "TODO: summaries", 1; + like( $output, qr|<b>pub</b>|i, + "outputs at least one bolded occurence of 'pub'" ); +} # end of SKIP
Copied: trunk/t/308_search_params.t (from rev 1381, trunk/t/38_search_params.t) =================================================================== --- trunk/t/308_search_params.t (rev 0) +++ trunk/t/308_search_params.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,165 @@ +use strict; +use CGI; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +plan tests => 19; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + use_plucene => 1, + geo_handler => 1, # British National Grid + } +); + +# Check the British National Grid case. +my $q = CGI->new( "" ); +$q->param( -name => "os_x", -value => 500000 ); +$q->param( -name => "os_y", -value => 200000 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +my %vars = $q->Vars(); +my $search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +is( $search->{distance_in_metres}, 500, + "os_dist picked up when OS co-ords given and using British grid" ); +is( $search->{x}, 500000, "...x set from os_x" ); +is( $search->{y}, 200000, "...y set from os_y" ); + +$q = CGI->new( "" ); +$q->param( -name => "osie_x", -value => 500000 ); +$q->param( -name => "osie_y", -value => 200000 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +ok( !defined $search->{distance_in_metres}, + "OSIE co-ords ignored when using British grid" ); + +$q = CGI->new( "" ); +$q->param( -name => "latitude", -value => 51 ); +$q->param( -name => "longitude", -value => 1 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +is( $search->{distance_in_metres}, 700, + "latlong_dist picked up when lat/long given and using British grid" ); +ok( defined $search->{x}, "...x set" ); +ok( defined $search->{y}, "...y set" ); + + +# Check the Irish National Grid case. +$config->geo_handler( 2 ); + +$q = CGI->new( "" ); +$q->param( -name => "osie_x", -value => 500000 ); +$q->param( -name => "osie_y", -value => 200000 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +is( $search->{distance_in_metres}, 600, + "osie_dist picked up when OS co-ords given and using Irish grid" ); +is( $search->{x}, 500000, "...x set from osie_x" ); +is( $search->{y}, 200000, "...y set from osie_y" ); + +$q = CGI->new( "" ); +$q->param( -name => "os_x", -value => 500000 ); +$q->param( -name => "os_y", -value => 200000 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +ok( !defined $search->{distance_in_metres}, + "OS co-ords ignored when using Irish grid" ); + +$q = CGI->new( "" ); +$q->param( -name => "latitude", -value => 55 ); +$q->param( -name => "longitude", -value => -5 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +is( $search->{distance_in_metres}, 700, + "latlong_dist picked up when lat/long given and using Irish grid" ); +ok( defined $search->{x}, "...x set" ); +ok( defined $search->{y}, "...y set" ); + + +# Check the UTM case. +$config->geo_handler( 3 ); +$config->ellipsoid( "Airy" ); + +$q = CGI->new( "" ); +$q->param( -name => "os_x", -value => 500000 ); +$q->param( -name => "os_y", -value => 200000 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +ok( !defined $search->{distance_in_metres}, + "OS co-ords ignored when using UTM" ); + +$q = CGI->new( "" ); +$q->param( -name => "osie_x", -value => 500000 ); +$q->param( -name => "osie_y", -value => 200000 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +ok( !defined $search->{distance_in_metres}, + "OSIE co-ords ignored when using UTM" ); + +$q = CGI->new( "" ); +$q->param( -name => "latitude", -value => 51 ); +$q->param( -name => "longitude", -value => 1 ); +$q->param( -name => "os_dist", -value => 500 ); +$q->param( -name => "osie_dist", -value => 600 ); +$q->param( -name => "latlong_dist", -value => 700 ); +%vars = $q->Vars(); +$search = OpenGuides::Search->new( config => $config ); +$search->run( vars => %vars, return_output => 1 ); +is( $search->{distance_in_metres}, 700, + "latlong_dist picked up when lat/long given and using UTM" ); +ok( defined $search->{x}, "...x set" ); +ok( defined $search->{y}, "...y set" );
Copied: trunk/t/309_search_form.t (from rev 1381, trunk/t/39_search_form.t) =================================================================== --- trunk/t/309_search_form.t (rev 0) +++ trunk/t/309_search_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,105 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; +} + +plan tests => 27; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->use_plucene( 1 ); + +# British National Grid guides should have os and latlong search fields. +my $search = OpenGuides::Search->new( config => $config ); +my $output = $search->run( return_output => 1 ); +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "input", { name => "os_dist" }, + "search page includes os_dist input with BNG" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" }, + "...and os_x" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" }, + "...and os_y" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, + "...and latlong_dist" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, + "...and latitude" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, + "...and longitude" ); +Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" }, + "...but not osie_dist" ); +Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" }, + "...nor osie_x" ); +Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" }, + "...nor osie_y" ); + +# Irish National Grid guides should have osie and latlong. +$config->geo_handler( 2 ); +$search = OpenGuides::Search->new( config => $config ); +$output = $search->run( return_output => 1 ); +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "input", { name => "osie_dist" }, + "search page includes os_dist input with ING" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" }, + "...and osie_x" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" }, + "...and osie_y" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, + "...and latlong_dist" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, + "...and latitude" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, + "...and longitude" ); +Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" }, + "...but not os_dist" ); +Test::HTML::Content::no_tag( $output, "input", { name => "os_x" }, + "...nor os_x" ); +Test::HTML::Content::no_tag( $output, "input", { name => "os_y" }, + "...nor os_y" ); + +# UTM guides should have latitude/longitude/latlong_dist only. +$config->geo_handler( 3 ); +$config->ellipsoid( "Airy" ); +$search = OpenGuides::Search->new( config => $config ); +$output = $search->run( return_output => 1 ); +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, + "includes latlong_dist with UTM" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, + "...and latitude" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, + "...and longitude" ); +Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" }, + "...but not os_dist" ); +Test::HTML::Content::no_tag( $output, "input", { name => "os_x" }, + "...nor os_x" ); +Test::HTML::Content::no_tag( $output, "input", { name => "os_y" }, + "...nor os_y" ); +Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" }, + "...but not osie_x" ); +Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" }, + "...nor osie_y" ); +Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" }, + "...nor osie_dist" );
Deleted: trunk/t/30_search_raw.t =================================================================== --- trunk/t/30_search_raw.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/30_search_raw.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,81 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 16; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $search = OpenGuides::Search->new( config => $config ); - -my %results; - -%results = $search->run( vars => { format => "raw" } ); -is_deeply( %results, { }, - "raw search returns empty hash if no criteria supplied" ); -%results = $search->run( vars => { search => "banananana", format => "raw" } ); -is_deeply( %results, { }, - "raw search returns empty hash if no hits on search string" ); - -# Pop some data in and search again. -OpenGuides::Test->write_data( guide => $guide, - node => "Red Lion", - content => "A nice pub in Anyville.", - summary => "Nice pub.", - os_x => 500000, - os_y => 150000, - ); -OpenGuides::Test->write_data( guide => $guide, - node => "Blacksmiths Arms", - content => "Not a very nice pub.", - summary => "Rubbish pub.", - os_x => 500100, - os_y => 150000, - ); -OpenGuides::Test->write_data( guide => $guide, - node => "Carpenters Arms", - content => "Not a bad pub.", - summary => "Average pub.", - os_x => 450000, - os_y => 140000, - ); - -%results = $search->run( vars => { search => "arms", format => "raw" } ); -is_deeply( [ sort keys %results ], [ "Blacksmiths Arms", "Carpenters Arms" ], - "raw search on single word finds the right nodes" ); -my %ba = %{$results{"Blacksmiths Arms"}}; -is( $ba{name}, "Blacksmiths Arms", "result hash has correct name" ); -is( $ba{summary}, "Rubbish pub.", "...and correct summary" ); -ok( $ba{wgs84_long}, "...WGS-84 latitude returned" ); -ok( $ba{wgs84_lat}, "...WGS-84 longitude returned" ); -ok( $ba{score}, "...score returned" ); -ok( !$ba{distance}, "...no distance returned" ); - -# Now try a distance search. -%results = $search->run( - vars => { - os_dist => 1000, - os_x => 500200, - os_y => 150000, - format => "raw", - } ); -is_deeply( [ sort keys %results ], [ "Blacksmiths Arms", "Red Lion" ], - "raw distance search finds the right nodes" ); -my %rl = %{$results{"Red Lion"}}; -is( $rl{name}, "Red Lion", "result hash has correct name" ); -is( $rl{summary}, "Nice pub.", "...and correct summary" ); -ok( $rl{wgs84_lat}, "...WGS-84 latitude returned" ); -ok( $rl{wgs84_long}, "...WGS-84 longitude returned" ); -ok( !$rl{score}, "...no score returned" ); -is( $rl{distance}, 200, "...correct distance returned" );
Deleted: trunk/t/31_search.t =================================================================== --- trunk/t/31_search.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/31_search.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,153 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 18; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); - -# Plucene is the recommended searcher now. -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene( 0 ) }; - -my $search = OpenGuides::Search->new( config => $config ); -isa_ok( $search, "OpenGuides::Search" ); - -my $output = $search->run( return_output => 1 ); -unlike( $output, qr/no items matched/i, - "doesn't output 'no items matched' if no terms supplied" ); -unlike( $output, qr/action=edit/, - "doesn't offer edit link" ); - -my %tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "banana" }, - ); -is( $tt_vars{first_num}, 0, "first_num set to 0 when no hits" ); -is( scalar @{ $tt_vars{results} }, 0, "...and results array empty" ); - -$output = $search->run( - return_output => 1, - vars => { search => "banana" } - ); -like( $output, qr/no items matched/i, - "outputs 'no items matched' if term not found" ); -unlike( $output, qr/matches found, showing/i, - "doesn't output 'matches found, showing' if term not found" ); - -# Pop some data in and search again. -my $wiki = $search->{wiki}; # white boxiness -$wiki->write_node( "Banana", "banana" ); -$wiki->write_node( "Monkey", "banana brains" ); -$wiki->write_node( "Monkey Brains", "BRANES" ); -$wiki->write_node( "Want Pie Now", "weebl" ); -$wiki->write_node( "Punctuation", "*" ); -$wiki->write_node( "Choice", "Eenie meenie minie mo"); - -# Test with two hits first - simpler. -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "banana" }, - ); -my @found = map { $_->{name} } @{ $tt_vars{results} || [] }; -is( scalar @found, 2, "search finds single word twice" ); -is_deeply( [ sort @found ], [ "Banana", "Monkey" ], - "...in the right places" ); -print "# Found in $_\n" foreach @found; - -# Make sure that $output matches too - we're testing the template here. -$output = $search->run( - return_output => 1, - vars => { search => "banana" }, - ); -like( $output, qr/<a href="http:\/\/example.com\/wiki.cgi\?Banana">/, - "...and link is included in template output" ); - -# One hit in body only should show result list. -$output = $search->run( - return_output => 1, - vars => { search => "weebl" }, - ); -unlike( $output, qr/Status: 302/, - "no redirect if match only in body"); - -# One hit in title should redirect to that page. -$output = $search->run( - return_output => 1, - vars => { search => "want pie now" }, - ); -like( $output, qr/Status: 302/, - "prints redirect on single hit and match in title" ); -# Old versions of CGI.pm mistakenly print location: instead of Location: -like( $output, - qr/[lL]ocation: http://example.com/wiki.cgi?Want_Pie_Now/, - "...and node name munged correctly in URL" ); - -# Test the AND search -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "monkey banana" }, - ); -@found = map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Monkey" ], "AND search returns right results" ); - -# Test the OR search -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "brains, pie" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Monkey", "Monkey Brains", "Want Pie Now" ], - "OR search returns right results" ); -print "# Found in $_\n" foreach @found; - -SKIP: { - skip "NOT search not done yet", 1; -# Test the NOT search -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "banana -monkey" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Banana" ], "NOT search returns right results" ); -} # end of SKIP - -# Test the phrase search -$output = $search->run( - return_output => 1, - vars => { search => '"monkey brains"' }, - ); -like( $output, - qr/[lL]ocation: http://example.com/wiki.cgi?Monkey_Brains/, - "phrase search returns right results and redirects to page" - ); - -##### -##### Test numbering when we have more than a page of results. -##### - -foreach my $i ( 1 .. 30 ) { - $wiki->write_node( "Node $i", "wombat" ) or die "Can't write Node $i"; -} -$output = $search->run( - return_output => 1, - vars => { - search => "wombat", - next => 20, - }, - ); -like( $output, qr/ol start="21"/, - "second page of results starts with right numbering" );
Deleted: trunk/t/32_search_simple_metadata.t =================================================================== --- trunk/t/32_search_simple_metadata.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/32_search_simple_metadata.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,129 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 10; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - } -); - -# Plucene is the recommended searcher now. -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene( 0 ) }; - -my $search = OpenGuides::Search->new( config => $config ); - -# Add some data. We write it twice to avoid hitting the redirect. -my $wiki = $search->{wiki}; # white boxiness -$wiki->write_node( "Calthorpe Arms", "Serves beer.", undef, - { category => "Pubs", locale => "Holborn" } ); -$wiki->write_node( "Penderel's Oak", "Serves beer.", undef, - { category => "Pubs", locale => "Holborn" } ); -$wiki->write_node( "British Museum", "Huge museum, lots of artifacts.", undef, - { category => ["Museums", "Major Attractions"] - , locale => ["Holborn", "Bloomsbury"] } ); - -# Check that a search on its category works. -my %tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "Pubs" }, - ); -my @found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], - "simple search looks in category" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "pubs" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], - "...and is case-insensitive" ); - -# Check that a search on its locale works. -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "Holborn" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ], - "simple search looks in locale" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "holborn" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "British Museum", "Calthorpe Arms", "Penderel's Oak" ], - "...and is case-insensitive" ); - -# Test AND search in various combinations. -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "Holborn Pubs" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], - "AND search works between category and locale" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "Holborn Penderel" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Penderel's Oak" ], - "AND search works between title and locale" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "Pubs Penderel" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Penderel's Oak" ], - "AND search works between title and category" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "Holborn beer" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], - "...and between body and locale" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "Pubs beer" }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Calthorpe Arms", "Penderel's Oak" ], - "...and between body and category" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => '"major attractions"' }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "British Museum", ], - "Multi word category name" );
Deleted: trunk/t/33_search_advanced_search.t =================================================================== --- trunk/t/33_search_advanced_search.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/33_search_advanced_search.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,186 +0,0 @@ -use strict; -use Wiki::Toolkit::Plugin::Locator::Grid; # use directly to help debug -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -plan tests => 9; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - use_plucene => 1, - geo_handler => 1, - } -); -my $search = OpenGuides::Search->new( config => $config ); -my $guide = OpenGuides->new( config => $config ); - -# Write some data. -OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - os_x => 523465, - os_y => 177490, - categories => "Pubs", - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Blue Anchor", - os_x => 522909, - os_y => 178232, - categories => "Pubs", - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Star Tavern", - os_x => 528107, - os_y => 179347, - categories => "Pubs", - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Hammersmith Bridge", - os_x => 522983, - os_y => 178118, - ); - -# Sanity check. -print "# Distances should be:\n"; -my $locator = Wiki::Toolkit::Plugin::Locator::Grid->new(x => "os_x", y => "os_y"); -my $wiki = $guide->wiki; -$wiki->register_plugin( plugin => $locator ); -foreach my $node ( "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge"){ - print "# $node: " . $locator->distance( from_x => 523450, - from_y => 177650, - to_node => $node ) . "\n"; -} - -# Check that a lat/long distance search finds them. -my %tt_vars = $search->run( - return_tt_vars => 1, - vars => { - latitude => 51.484320, - longitude => -0.223484, - latlong_dist => 1000, - }, - ); -my @ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; -my @found = sort @ordered; -is_deeply( @found, - [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], - "distance search finds the right things" ); -is_deeply( @ordered, - [ "Crabtree Tavern", "Hammersmith Bridge", "Blue Anchor" ], - "...and returns them in the right order" ); -my $output = $search->run( - return_output => 1, - vars => { - latitude => 51.484320, - longitude => -0.223484, - latlong_dist => 1000, - }, - ); -unlike( $output, qr|(score:\s+)|, "...no spurious 'scores' printed" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { - latitude => 51.484320, - longitude => -0.223484, - latlong_dist => 1000, - search => " ", - }, - ); -@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; -@found = sort @ordered; -is_deeply( @found, - [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], - "...still works if whitespace-only search text supplied" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { - os_x => 523450, - os_y => 177650, - os_dist => 1000, - search => " ", - }, - ); -@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; -@found = sort @ordered; -is_deeply( @found, - [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], - "...works with OS co-ords" ); - -%tt_vars = eval { - $search->run( - return_tt_vars => 1, - vars => { - os_x => 523450, - os_y => 177650, - os_dist => 1000, - search => " ", - latitude => " ", - longitude => " ", - }, - ); -}; -is( $@, "", "...works with OS co-ords and whitespace-only lat/long" ); -@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; -@found = sort @ordered; -is_deeply( @found, - [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], - "...returns the right stuff" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { - latitude => 51.484320, - longitude => -0.223484, - latlong_dist => 1000, - search => "pubs", - }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Blue Anchor", "Crabtree Tavern", ], - "distance search in combination with text search works" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { - os_x => 523450, - os_y => 177650, - os_dist => 1000, - search => "pubs", - }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Blue Anchor", "Crabtree Tavern", ], - "...works with OS co-ords too" );
Deleted: trunk/t/33_search_advanced_search_utm.t =================================================================== --- trunk/t/33_search_advanced_search_utm.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/33_search_advanced_search_utm.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,127 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -plan tests => 4; - -# Clear out the database from any previous runs. - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - use_plucene => 1, - geo_handler => 3, - ellipsoid => "Airy", - } -); -my $search = OpenGuides::Search->new( config => $config ); -my $guide = OpenGuides->new( config => $config ); - -# Write some data. -OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - latitude => 51.482385, - longitude => -0.221743, - categories => "Pubs", - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Blue Anchor", - latitude => 51.489176, - longitude => -0.229488, - categories => "Pubs", - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Star Tavern", - latitude => 51.498043, - longitude => -0.154247, - categories => "Pubs", - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Hammersmith Bridge", - latitude => 51.488135, - longitude => -0.228463, - ); - -# Sanity check. -print "# Distances should be round about:\n"; -my $locator = $guide->locator; -foreach my $node ( "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge"){ - print "# $node: " . $locator->distance( from_x => 692756, - from_y => 5706917, - to_node => $node ) . "\n"; -} - -# Check that a lat/long distance search finds them. -my %tt_vars = $search->run( - return_tt_vars => 1, - vars => { - latitude => 51.484320, - longitude => -0.223484, - latlong_dist => 1000, - }, - ); -my @ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; -my @found = sort @ordered; -is_deeply( @found, - [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], - "distance search finds the right things" ); -is_deeply( @ordered, - [ "Crabtree Tavern", "Hammersmith Bridge", "Blue Anchor" ], - "...and returns them in the right order" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { - latitude => 51.484320, - longitude => -0.223484, - latlong_dist => 1000, - search => " ", - }, - ); -@ordered = map { $_->{name} } @{ $tt_vars{results} || [] }; -@found = sort @ordered; -is_deeply( @found, - [ "Blue Anchor", "Crabtree Tavern", "Hammersmith Bridge" ], - "...still works if whitespace-only search text supplied" ); - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { - latitude => 51.484320, - longitude => -0.223484, - latlong_dist => 1000, - search => "pubs", - }, - ); -@found = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @found, [ "Blue Anchor", "Crabtree Tavern", ], - "distance search in combination with text search works" );
Deleted: trunk/t/34_search_paging.t =================================================================== --- trunk/t/34_search_paging.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/34_search_paging.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,139 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -plan tests => 18; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - - -my $config = OpenGuides::Test->make_basic_config; -$config->use_plucene( 1 ); -my $search = OpenGuides::Search->new( config => $config ); -my $guide = OpenGuides->new( config => $config ); - -# Test with OS co-ords. - $config->geo_handler( 1 ); - - foreach my $i ( 1 .. 50 ) { - OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern $i", - os_x => 523465, - os_y => 177490, - categories => "Pubs", - ); - } - - my $output = $search->run( - return_output => 1, - vars => { - os_dist => 1500, - os_x => 523500, - os_y => 177500, - next => 21, - }, - ); - like( $output, qr/search.cgi?.*os_x=523500.*Next.*results/s, - "os_x retained in next page link" ); - like( $output, qr/search.cgi?.*os_y=177500.*Next.*results/s, - "os_y retained in next page link" ); - like( $output, qr/search.cgi?.*os_dist=1500.*Next.*results/s, - "os_dist retained in next page link" ); - like( $output, qr/search.cgi?.*os_x=523500.*Previous.*results/s, - "os_x retained in previous page link" ); - like( $output, qr/search.cgi?.*os_y=177500.*Previous.*results/s, - "os_y retained in previous page link" ); - like( $output, qr/search.cgi?.*os_dist=1500.*Previous.*results/s, - "os_dist retained in previous page link" ); - -# Test with OSIE co-ords. - - # We must create a new search object after changing the geo_handler - # in order to force it to create a fresh locator. - $config->geo_handler( 2 ); - $search = OpenGuides::Search->new( config => $config ); - - foreach my $i ( 1 .. 50 ) { - OpenGuides::Test->write_data( - guide => $guide, - node => "I Made This Place Up $i", - osie_x => 100005, - osie_y => 200005, - ); - } - - $output = $search->run( - return_output => 1, - vars => { - osie_dist => 1500, - osie_x => 100000, - osie_y => 200000, - next => 21, - }, - ); - like( $output, qr/search.cgi?.*osie_x=100000.*Next.*results/s, - "osie_x retained in next page link" ); - like( $output, qr/search.cgi?.*osie_y=200000.*Next.*results/s, - "osie_y retained in next page link" ); - like( $output, qr/search.cgi?.*osie_dist=1500.*Next.*results/s, - "osie_dist retained in next page link" ); - like( $output, qr/search.cgi?.*osie_x=100000.*Previous.*results/s, - "osie_x retained in previous page link" ); - like( $output, qr/search.cgi?.*osie_y=200000.*Previous.*results/s, - "osie_y retained in previous page link" ); - like( $output, qr/search.cgi?.*osie_dist=1500.*Previous.*results/s, - "osie_dist retained in previous page link" ); - -# Test with UTM. - - # We must create a new search object after changing the geo_handler - # in order to force it to create a fresh locator. - $config->geo_handler( 3 ); - $search = OpenGuides::Search->new( config => $config ); - - foreach my $i ( 1 .. 50 ) { - OpenGuides::Test->write_data( - guide => $guide, - node => "London Aquarium $i", - latitude => 51.502, - longitude => -0.118, - ); - } - - $output = $search->run( - return_output => 1, - vars => { - latlong_dist => 1500, - latitude => 51.5, - longitude => -0.12, - next => 21, - }, - ); - like( $output, qr/search.cgi?.*latitude=51.5.*Next.*results/s, - "latitude retained in next page link" ); - like( $output, qr/search.cgi?.*longitude=-0.12.*Next.*results/s, - "longitude retained in next page link" ); - like( $output, qr/search.cgi?.*latlong_dist=1500.*Next.*results/s, - "latlong_dist retained in next page link" ); - like( $output, qr/search.cgi?.*latitude=51.5.*Previous.*results/s, - "latitude retained in previous page link" ); - like( $output, qr/search.cgi?.*longitude=-0.12.*Previous.*results/s, - "longitude retained in previous page link" ); - like( $output, qr/search.cgi?.*latlong_dist=1500.*Previous.*results/s, - "latlong_dist retained in previous page link" );
Deleted: trunk/t/35_search_two_searches.t =================================================================== --- trunk/t/35_search_two_searches.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/35_search_two_searches.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,122 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -plan tests => 10; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - geo_handler => 1, - } -); - -# Plucene is the recommended searcher now. -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene( 0 ) }; - -my $search = OpenGuides::Search->new( config => $config ); - -# Write some data. -my $wiki = $search->{wiki}; -$wiki->write_node( "Wandsworth Common", "A common.", undef, - { category => "Parks" } ) - or die "Can't write node"; -$wiki->write_node( "Hammersmith", "A page about Hammersmith." ) - or die "Can't write node"; - -# Check that the search forgets input search term between invocations. -$search->run( - return_output => 1, - vars => { search => "parks" }, - ); -ok( $search->{search_string}, "search_string set" ); -$search->run( - return_output => 1, - ); -ok( !$search->{search_string}, "...and forgotten" ); - -# Sanity check. -my (@results, %tt_vars); -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "parks" }, - ); -@results = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @results, [ "Wandsworth Common" ], - "first search returns expected results" ); -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "hammersmith" }, - ); -@results = sort map { $_->{name} } @{ $tt_vars{results} || [] }; -is_deeply( @results, [ "Hammersmith" ], - "so does second" ); - -# Check that the search forgets input geodata between invocations. -# First with British National Grid. -$search->run( - return_output => 1, - vars => { os_x => 500000, os_y => 100000, os_dist => 1000 }, - ); -ok( $search->{x}, "x-coord set" ); -$search->run( - return_output => 1, - vars => { search => "foo" }, - ); -ok( !$search->{x}, "...and forgotten" ); - -# Now with Irish National Grid. -$config->geo_handler( 2 ); -$search = OpenGuides::Search->new( config => $config ); -$search->run( - return_output => 1, - vars => { osie_x => 100000, osie_y => 200000, osie_dist => 100 }, - ); -ok( $search->{x}, "x-coord set" ); -$search->run( - return_output => 1, - vars => { search => "foo" }, - ); -ok( !$search->{x}, "...and forgotten" ); - -# Now with UTM. -$config->geo_handler( 3 ); -$config->ellipsoid( "Airy" ); -$search = OpenGuides::Search->new( config => $config ); -$search->run( - return_output => 1, - vars => { latitude => 10, longitude => 0, latlong_dist => 1000 }, - ); -ok( $search->{x}, "x-coord set" ); -$search->run( - return_output => 1, - vars => { search => "foo" }, - ); -ok( !$search->{x}, "...and forgotten" ); - -
Deleted: trunk/t/36_search_order.t =================================================================== --- trunk/t/36_search_order.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/36_search_order.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,139 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -plan tests => 9; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - use_plucene => 1 - } -); - -my $search = OpenGuides::Search->new( config => $config ); -isa_ok( $search, "OpenGuides::Search" ); - -# Write some data. -my $wiki = $search->{wiki}; -$wiki->write_node( "Parks", "A page about parks." ) - or die "Can't write node"; -$wiki->write_node( "Wandsworth Common", "A common.", undef, - { category => "Parks" } ) - or die "Can't write node"; -$wiki->write_node( "Kake", "I like walking in parks." ) - or die "Can't write node"; - -my %tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "parks" }, - ); -foreach my $result ( @{ $tt_vars{results} || [] } ) { - print "# $result->{name} scores $result->{score}\n"; -} -my %scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; -ok( $scores{Kake} < $scores{'Wandsworth Common'}, - "content match scores less than category match" ); -ok( $scores{'Wandsworth Common'} < $scores{Parks}, - "title match scores more than category match" ); - -# Now test locales. -$wiki->write_node( "Hammersmith", "A page about Hammersmith." ) - or die "Can't write node"; -$wiki->write_node( "The Gate", "A restaurant.", undef, - { locale => "Hammersmith" } ) - or die "Can't write node"; -$wiki->write_node( "Kake Pugh", "I live in Hammersmith." ) - or die "Can't write node"; - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "hammersmith" }, - ); -foreach my $result ( @{ $tt_vars{results} || [] } ) { - print "# $result->{name} scores $result->{score}\n"; -} -%scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; -ok( $scores{'Kake Pugh'} < $scores{'The Gate'}, - "content match scores less than locale match" ); -ok( $scores{'The Gate'} < $scores{Hammersmith}, - "locale match scores less than title match" ); - -# Check that two words in the title beats one in the title and -# one in the content. -$wiki->write_node( "Putney Tandoori", "Indian food" ) - or die "Couldn't write node"; -$wiki->write_node( "Putney", "There is a tandoori restaurant here" ) - or die "Couldn't write node"; - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "putney tandoori" }, - ); -foreach my $result ( @{ $tt_vars{results} || [] } ) { - print "# $result->{name} scores $result->{score}\n"; -} -%scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; -ok( $scores{Putney} < $scores{'Putney Tandoori'}, - "two words in title beats one in title and one in content" ); - -SKIP: { - skip "Word proximity not yet taken into account", 1; -# Check that in an AND match words closer together get higher priority. -$wiki->write_node( "Spitalfields Market", - "Mango juice from the Indian stall" ) - or die "Can't write node"; -$wiki->write_node( "Borough Market", "dried mango and real apple juice" ) - or die "Can't write node"; - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "mango juice" }, - ); -foreach my $result ( @{ $tt_vars{results} || [] } ) { - print "# $result->{name} scores $result->{score}\n"; -} -%scores = map { $_->{name} => $_->{score} } @{$tt_vars{results} || []}; -ok( $scores{'Borough Market'} < $scores{'Spitalfields Market'}, - "words closer together gives higher score" ); -} # end of SKIP - -# Check that the number of occurrences of the search term is significant. - -$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"; -$wiki->write_node( "The Pub", "A pub.", undef, { category => "Pubs" } ) or die "Can't write node"; - -%tt_vars = $search->run( - return_tt_vars => 1, - vars => { search => "pub" } - ); -foreach my $result ( @{ $tt_vars{results} || [] } ) { - print "# $result->{name} scores $result->{score}\n"; -} -is( $tt_vars{results}[0]{name}, "Pub Crawls", - "node with two mentions of search term comes top" ); -ok( $tt_vars{results}[0]{score} > $tt_vars{results}[1]{score}, - "...with a score strictly greater than node with one mention" );
Deleted: trunk/t/37_search_summaries.t =================================================================== --- trunk/t/37_search_summaries.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/37_search_summaries.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,48 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 2; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - } -); - -# Plucene is the recommended searcher now. -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene( 0 ) }; - -my $search = OpenGuides::Search->new( config => $config ); -isa_ok( $search, "OpenGuides::Search" ); -my $wiki = $search->wiki; -$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"; - -my $output = $search->run( - return_output => 1, - vars => { search => "pub" } - ); -SKIP: { - skip "TODO: summaries", 1; - like( $output, qr|<b>pub</b>|i, - "outputs at least one bolded occurence of 'pub'" ); -} # end of SKIP
Deleted: trunk/t/38_search_params.t =================================================================== --- trunk/t/38_search_params.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/38_search_params.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,165 +0,0 @@ -use strict; -use CGI; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -plan tests => 19; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - use_plucene => 1, - geo_handler => 1, # British National Grid - } -); - -# Check the British National Grid case. -my $q = CGI->new( "" ); -$q->param( -name => "os_x", -value => 500000 ); -$q->param( -name => "os_y", -value => 200000 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -my %vars = $q->Vars(); -my $search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -is( $search->{distance_in_metres}, 500, - "os_dist picked up when OS co-ords given and using British grid" ); -is( $search->{x}, 500000, "...x set from os_x" ); -is( $search->{y}, 200000, "...y set from os_y" ); - -$q = CGI->new( "" ); -$q->param( -name => "osie_x", -value => 500000 ); -$q->param( -name => "osie_y", -value => 200000 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -ok( !defined $search->{distance_in_metres}, - "OSIE co-ords ignored when using British grid" ); - -$q = CGI->new( "" ); -$q->param( -name => "latitude", -value => 51 ); -$q->param( -name => "longitude", -value => 1 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -is( $search->{distance_in_metres}, 700, - "latlong_dist picked up when lat/long given and using British grid" ); -ok( defined $search->{x}, "...x set" ); -ok( defined $search->{y}, "...y set" ); - - -# Check the Irish National Grid case. -$config->geo_handler( 2 ); - -$q = CGI->new( "" ); -$q->param( -name => "osie_x", -value => 500000 ); -$q->param( -name => "osie_y", -value => 200000 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -is( $search->{distance_in_metres}, 600, - "osie_dist picked up when OS co-ords given and using Irish grid" ); -is( $search->{x}, 500000, "...x set from osie_x" ); -is( $search->{y}, 200000, "...y set from osie_y" ); - -$q = CGI->new( "" ); -$q->param( -name => "os_x", -value => 500000 ); -$q->param( -name => "os_y", -value => 200000 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -ok( !defined $search->{distance_in_metres}, - "OS co-ords ignored when using Irish grid" ); - -$q = CGI->new( "" ); -$q->param( -name => "latitude", -value => 55 ); -$q->param( -name => "longitude", -value => -5 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -is( $search->{distance_in_metres}, 700, - "latlong_dist picked up when lat/long given and using Irish grid" ); -ok( defined $search->{x}, "...x set" ); -ok( defined $search->{y}, "...y set" ); - - -# Check the UTM case. -$config->geo_handler( 3 ); -$config->ellipsoid( "Airy" ); - -$q = CGI->new( "" ); -$q->param( -name => "os_x", -value => 500000 ); -$q->param( -name => "os_y", -value => 200000 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -ok( !defined $search->{distance_in_metres}, - "OS co-ords ignored when using UTM" ); - -$q = CGI->new( "" ); -$q->param( -name => "osie_x", -value => 500000 ); -$q->param( -name => "osie_y", -value => 200000 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -ok( !defined $search->{distance_in_metres}, - "OSIE co-ords ignored when using UTM" ); - -$q = CGI->new( "" ); -$q->param( -name => "latitude", -value => 51 ); -$q->param( -name => "longitude", -value => 1 ); -$q->param( -name => "os_dist", -value => 500 ); -$q->param( -name => "osie_dist", -value => 600 ); -$q->param( -name => "latlong_dist", -value => 700 ); -%vars = $q->Vars(); -$search = OpenGuides::Search->new( config => $config ); -$search->run( vars => %vars, return_output => 1 ); -is( $search->{distance_in_metres}, 700, - "latlong_dist picked up when lat/long given and using UTM" ); -ok( defined $search->{x}, "...x set" ); -ok( defined $search->{y}, "...y set" );
Deleted: trunk/t/39_search_form.t =================================================================== --- trunk/t/39_search_form.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/39_search_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,105 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; -} - -plan tests => 27; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->use_plucene( 1 ); - -# British National Grid guides should have os and latlong search fields. -my $search = OpenGuides::Search->new( config => $config ); -my $output = $search->run( return_output => 1 ); -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "input", { name => "os_dist" }, - "search page includes os_dist input with BNG" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "os_x" }, - "...and os_x" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "os_y" }, - "...and os_y" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, - "...and latlong_dist" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, - "...and latitude" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, - "...and longitude" ); -Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" }, - "...but not osie_dist" ); -Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" }, - "...nor osie_x" ); -Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" }, - "...nor osie_y" ); - -# Irish National Grid guides should have osie and latlong. -$config->geo_handler( 2 ); -$search = OpenGuides::Search->new( config => $config ); -$output = $search->run( return_output => 1 ); -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "input", { name => "osie_dist" }, - "search page includes os_dist input with ING" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "osie_x" }, - "...and osie_x" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "osie_y" }, - "...and osie_y" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, - "...and latlong_dist" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, - "...and latitude" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, - "...and longitude" ); -Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" }, - "...but not os_dist" ); -Test::HTML::Content::no_tag( $output, "input", { name => "os_x" }, - "...nor os_x" ); -Test::HTML::Content::no_tag( $output, "input", { name => "os_y" }, - "...nor os_y" ); - -# UTM guides should have latitude/longitude/latlong_dist only. -$config->geo_handler( 3 ); -$config->ellipsoid( "Airy" ); -$search = OpenGuides::Search->new( config => $config ); -$output = $search->run( return_output => 1 ); -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "input", { name => "latlong_dist" }, - "includes latlong_dist with UTM" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, - "...and latitude" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, - "...and longitude" ); -Test::HTML::Content::no_tag( $output, "input", { name => "os_dist" }, - "...but not os_dist" ); -Test::HTML::Content::no_tag( $output, "input", { name => "os_x" }, - "...nor os_x" ); -Test::HTML::Content::no_tag( $output, "input", { name => "os_y" }, - "...nor os_y" ); -Test::HTML::Content::no_tag( $output, "input", { name => "osie_x" }, - "...but not osie_x" ); -Test::HTML::Content::no_tag( $output, "input", { name => "osie_y" }, - "...nor osie_y" ); -Test::HTML::Content::no_tag( $output, "input", { name => "osie_dist" }, - "...nor osie_dist" );
Copied: trunk/t/400_search_as_feed.t (from rev 1381, trunk/t/40_search_as_feed.t) =================================================================== --- trunk/t/400_search_as_feed.t (rev 0) +++ trunk/t/400_search_as_feed.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,60 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Search; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 7; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); + +# Plucene is the recommended searcher now. +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene( 0 ) }; + +my $search = OpenGuides::Search->new( config => $config ); +isa_ok( $search, "OpenGuides::Search" ); + +# Pop some test data in +my $wiki = $search->{wiki}; # white boxiness +$wiki->write_node( "Banana", "banana" ); +$wiki->write_node( "Monkey", "banana brains" ); +$wiki->write_node( "Monkey Brains", "BRANES" ); +$wiki->write_node( "Want Pie Now", "weebl" ); +$wiki->write_node( "Punctuation", "*" ); +$wiki->write_node( "Choice", "Eenie meenie minie mo"); + +# RSS search, should give 2 hits +my $output = $search->run( + return_output => 1, + vars => { search => "banana", format => "rss" }, + ); + +like($output, qr/<rdf:RDF/, "Really was RSS"); +like($output, qr/<items>/, "Really was RSS"); + +my @found = ($output =~ /(<rdf:li)/g); +is( scalar @found, 2, "found right entries in feed" ); + + +# Atom search, should give 1 hit +$output = $search->run( + return_output => 1, + vars => { search => "weebl", format => "atom" }, + ); +like($output, qr/<feed/, "Really was Atom"); +like($output, qr/<entry>/, "Really was Atom"); + +@found = ($output =~ /(<entry>)/g); +is( scalar @found, 1, "found right entries in feed" );
Copied: trunk/t/401_deletion.t (from rev 1381, trunk/t/41_deletion.t) =================================================================== --- trunk/t/401_deletion.t (rev 0) +++ trunk/t/401_deletion.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,52 @@ +use strict; +use OpenGuides; +use OpenGuides::Template; +use OpenGuides::Test; +use OpenGuides::CGI; +use Test::More tests => 3; + +my $config = OpenGuides::Test->make_basic_config; +$config->site_name( "Test Site" ); +$config->script_url( "/" ); + +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +my $output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "node.tt", +); +unlike( $output, qr/action=delete/, + "doesn't offer page deletion link by default" ); +$config->enable_page_deletion( "y" ); + # set is_admin to 1 +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; + +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "node.tt", +); +like( $output, qr/action=delete/, + "...but does when enable_page_deletion is set to 'y' and is_admin is 1" ); +$config->enable_page_deletion( 1 ); +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "node.tt", +); +like( $output, qr/action=delete/, + "...and when enable_page_deletion is set to '1' and is_admin is 1" );
Copied: trunk/t/402_edit_conflict.t (from rev 1381, trunk/t/42_edit_conflict.t) =================================================================== --- trunk/t/402_edit_conflict.t (rev 0) +++ trunk/t/402_edit_conflict.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,99 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; +} + +plan tests => 16; +# clear out database + OpenGuides::Test::refresh_db(); + +# Make a guide that works on latitude/longitude, and allows node images. +my $config = OpenGuides::Test->make_basic_config; +$config->geo_handler( 3 ); +$config->ellipsoid( "WGS-84" ); +$config->enable_node_image( 1 ); +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + + + +# Write some data. +OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + content => "A pub.", + locales => "W6", + categories => "Pubs\r\nPub Food", + latitude => 51.5, + longitude => -0.05, + ); + +# Make sure the normal edit form doesn't think there's a conflict. +my $output = $guide->display_edit_form( + id => "Crabtree Tavern", + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::no_tag( $output, "div", { class => "warning_text" }, + "Normal edit form doesn't contain warning_text" ); + +# Now try to commit some edits without giving the checksum. +$output = OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + content => "Still a pub.", + locales => "Hammersmith", + categories => "Beer Garden", + latitude => 41.5, + longitude => -0.04, + omit_checksum => 1, + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "div", { class => "warning_text" }, + "Edit conflict form contains warning_text" ); + +like( $output, qr/A pub./s, "...and old content" ); +like( $output, qr/Still a pub./s, "...and new content" ); +like( $output, qr/W6/s, "...and old locales" ); +like( $output, qr/Hammersmith/s, "...and new locales" ); +like( $output, qr/Pubs/s, "...and old categories" ); +like( $output, qr/Pub Food/s, "...both of them" ); +like( $output, qr/Beer Garden/s, "...and new categories" ); + +# Bug #173 (edit conflict form doesn't let you edit everything). +Test::HTML::Content::tag_ok( $output, "input", { name => "node_image" }, + "...and 'node_image' input box too" ); + +# Bug #48 (Edit conflict page erroneously converts lat/lon to os_x, os_y). +Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, + "UTM guide has 'latitude' input box in edit " + . "conflict" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "latitude", + value => 51.5 }, + "...with correct value" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, + "...and 'longitude' input box too" ); +Test::HTML::Content::tag_ok( $output, "input", { name => "longitude", + value => -0.05 }, + "...with correct value" ); +like( $output, qr/41.5/, "...new latitude is there too" ); +like( $output, qr/-0.04/, "...and new longitude" );
Copied: trunk/t/403_preview_edits.t (from rev 1381, trunk/t/43_preview_edits.t) =================================================================== --- trunk/t/403_preview_edits.t (rev 0) +++ trunk/t/403_preview_edits.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,63 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; +} + +plan tests => 6; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +my $q = OpenGuides::Test->make_cgi_object( + content => "I am some content.", + summary => "I am a summary.", + node_image => "http://example.com/image.png", + node_image_copyright => "PhotoKake", + node_image_licence => "http://example.com/licence", + node_image_url => "http://example.com/info", +); + +# Get a checksum for a "blank" node. +my %node_data = $wiki->retrieve_node( "Clapham Junction Station" ); +$q->param( -name => "checksum", -value => $node_data{checksum} ); + +my $output = $guide->preview_edit( + id => "Clapham Junction Station", + cgi_obj => $q, + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +my $warned; +eval { + local $SIG{__WARN__} = sub { $warned = 1; }; + Test::HTML::Content::text_ok( $output, "I am a summary.", + "Summary shows up in preview." ); +}; +ok( !$warned, "...and HTML seems to be valid" ); +Test::HTML::Content::tag_ok( $output, "img", + { src => "http://example.com/image.png" }, + "Image URL shows up too" ); +like( $output, qr|©\s+PhotoKake|, "...so does image copyright holder" ); +Test::HTML::Content::link_ok( $output, "http://example.com/licence", + "...and we link to the licence" ); +Test::HTML::Content::link_ok( $output, "http://example.com/info", + "...and we link to the info page" );
Copied: trunk/t/404_node_image.t (from rev 1381, trunk/t/44_node_image.t) =================================================================== --- trunk/t/404_node_image.t (rev 0) +++ trunk/t/404_node_image.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,205 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed."; +} + +plan tests => 30; + +my ( $config, $guide, $wiki ); + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Make sure node image fields don't show up in edit form if config says +# they shouldn't. +$config = OpenGuides::Test->make_basic_config; +$config->enable_node_image( 0 ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; + +my $output = $guide->display_edit_form( + id => "Red Lion", + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::no_tag( $output, "input", { name => "node_image" }, + "node_image field not in edit form if config says it shouldn't be" ); +Test::HTML::Content::no_tag( $output, "input", + { name => "node_image_licence" }, + "...ditto node_image_licence" ); +Test::HTML::Content::no_tag( $output, "input", + { name => "node_image_copyright" }, + "...ditto node_image_copyright" ); +Test::HTML::Content::no_tag( $output, "input", + { name => "node_image_url" }, + "...ditto node_image_url" ); + +# And make sure they do if it says they should. +$config->enable_node_image( 1 ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; + +$output = $guide->display_edit_form( + id => "Red Lion", + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "input", { name => "node_image" }, + "node_image field appears in edit form if config says it should" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_licence" }, + "...ditto node_image_licence" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_copyright" }, + "...ditto node_image_copyright" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_url" }, + "...ditto node_image_url" ); + +# Write all four fields to database, and make sure they're there. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + node_image => "http://example.com/foo.jpg", + node_image_licence => "http://example.com/bar/", + node_image_copyright => "Kake L Pugh", + node_image_url => "http://example.com/~kake/", + ); + +my %node_data = $wiki->retrieve_node( "Red Lion" ); +is( $node_data{metadata}{node_image}[0], "http://example.com/foo.jpg", + "node_image saved to database on node write" ); +is( $node_data{metadata}{node_image_licence}[0], "http://example.com/bar/", + "...node_image_licence too" ); +is( $node_data{metadata}{node_image_copyright}[0], "Kake L Pugh", + "...node_image_copyright too" ); +is( $node_data{metadata}{node_image_url}[0], "http://example.com/~kake/", + "...node_image_url too" ); + +# Make sure their content shows up in the edit form. +$output = $guide->display_edit_form( + id => "Red Lion", + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image", + value => "http://example.com/foo.jpg" }, + "node_image field has correct value in edit form", + ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_licence", + value => "http://example.com/bar/" }, + "...ditto node_image_licence" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_copyright", + value => "Kake L Pugh" }, + "...ditto node_image_copyright" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_url", + value => "http://example.com/~kake/" }, + "...ditto node_image_url" ); + +# Make sure they're displayed when a page is viewed. +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "img", + { src => "http://example.com/foo.jpg" }, + "node_image displayed on page" ); +Test::HTML::Content::tag_ok( $output, "a", + { href => "http://example.com/bar/" }, + "...ditto node_image_licence" ); +Test::HTML::Content::text_ok( $output, qr/Kake L Pugh/, + "...ditto node_image_copyright" ); +Test::HTML::Content::tag_ok( $output, "a", + { href => "http://example.com/~kake/" }, + "...ditto node_image_url" ); + +# Now try to commit some edits without giving the checksum. +$output = OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + node_image => "http://eg.com/foo.jpg", + node_image_licence + => "http://eg.com/bar/", + node_image_copyright => "NotKakeNo", + node_image_url + => "http://eg.com/~kake/", + omit_checksum => 1, + return_output => 1, + ); + +# Strip Content-Type header to stop Test::HTML::Content getting confused. +$output =~ s/^Content-Type.*[\r\n]+//m; + +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image", + value => "http://example.com/foo.jpg" }, + "Edit conflict form has input box with old " + . "node_image value in" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_licence", + value => "http://example.com/bar/" }, + "...and one with old node_image_licence value" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_copyright", + value => "Kake L Pugh" }, + "...and one with old node_image_copyright value" ); +Test::HTML::Content::tag_ok( $output, "input", + { name => "node_image_url", + value => "http://example.com/~kake/" }, + "...and one with old node_image_url value" ); +Test::HTML::Content::text_ok( $output, "http://eg.com/foo.jpg", + "...new node_image value appears too" ); +Test::HTML::Content::text_ok( $output, "http://eg.com/bar/", + "...as does new node_image_licence value" ); +Test::HTML::Content::text_ok( $output, "NotKakeNo", + "...as does new node_image_copyright value" ); +Test::HTML::Content::text_ok( $output, "http://eg.com/~kake/", + "...as does new node_image_url value" ); + +# Write node with node_image field consisting only of whitespace, make +# sure it gets stripped. +OpenGuides::Test->write_data( + guide => $guide, + node => "Angel and Greyhound", + node_image => " ", + ); +%node_data = $wiki->retrieve_node( "Angel and Greyhound" ); +ok( !$node_data{metadata}{node_image}, + "node_image of whitespace only isn't saved to database" ); + +$output = $guide->display_node( + id => "Angel and Greyhound", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::no_tag( $output, "img" => { id => "node_image" }, + "...or displayed on page" );
Copied: trunk/t/405_home_recent_changes.t (from rev 1381, trunk/t/45_home_recent_changes.t) =================================================================== --- trunk/t/405_home_recent_changes.t (rev 0) +++ trunk/t/405_home_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,96 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 15; + +my ( $config, $guide, $wiki ); + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Write some data to show up in recent changes. +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + content => "A pub.", + username => "Kake", + comment => "I edited it.", + ); + +# First test that recent changes show up on the front page by default. +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); + +my $output = $guide->display_node( + id => $config->home_name, + return_output => 1, + ); +like( $output, qr/Red Lion/, + "recent changes show up on home page by default" ); +like( $output, qr/I edited it./, "...including comments" ); +like( $output, qr/Kake/, "...and usernames" ); +like( $output, qr/Edit this page/, "...edit this page link is there too" ); + +# And that they show up when we explicitly ask for them. +$config = OpenGuides::Test->make_basic_config; +$config->recent_changes_on_home_page( 1 ); +$guide = OpenGuides->new( config => $config ); + +$output = $guide->display_node( + id => $config->home_name, + return_output => 1, + ); +like( $output, qr/Red Lion/, + "recent changes show up on home page when we ask for them" ); +like( $output, qr/I edited it./, "...including comments" ); +like( $output, qr/Kake/, "...and usernames" ); +like( $output, qr/Edit this page/, "...edit this page link is there too" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + content => "A nice pub.", + username => "Earle", + comment => "I also edited it. For fun, here are two links: [[A Page]], and the same link [[A Page|again]].", + ); + +# Reload page. +$output = $guide->display_node( + id => $config->home_name, + return_output => 1, + ); + +like( $output, qr{<a href="\?A Page">A Page</a>}, "...simple wiki links appear in Recent Changes" ); +like( $output, qr{<a href="\?A Page">again</a>}, "...titled wiki links appear in Recent Changes" ); + + +# And that they don't show up if we don't want them. Turn off the navbar +# too, since we want to make sure the edit page link shows up regardless (it +# normally appears in the recent changes box). +$config = OpenGuides::Test->make_basic_config; +$config->recent_changes_on_home_page( 0 ); +$config->navbar_on_home_page( 0 ); +$guide = OpenGuides->new( config => $config ); + +$output = $guide->display_node( + id => $config->home_name, + return_output => 1, + ); +unlike( $output, qr/Red Lion/, + "recent changes don't show up on home page if we turn them off" ); +unlike( $output, qr/I edited it./, "...comments not shown either" ); +unlike( $output, qr/Kake/, "...nor usernames" ); +unlike( $output, qr/Ten most.*recent changes/, "...heading not shown either" ); +like( $output, qr/Edit this page/, "...edit this page link is there though" ); +
Copied: trunk/t/406_map_in_node_display.t (from rev 1381, trunk/t/46_map_in_node_display.t) =================================================================== --- trunk/t/406_map_in_node_display.t (rev 0) +++ trunk/t/406_map_in_node_display.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,150 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +plan tests => 10; + +my ( $config, $guide, $wiki, $cookie, $output ); + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Make a guide. +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; + +# Write a node with location data. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + os_x => 530000, + os_y => 180000, + ); + +# Maps shouldn't show up if there's no API key and we're not using Leaflet. +$config->show_gmap_in_node_display( 1 ); +$config->use_leaflet( 0 ); +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + display_google_maps => 1, + ); +$ENV{HTTP_COOKIE} = $cookie; + +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::no_tag( $output, "div", { id => "map" }, + "Map omitted from node if no API key and not using Leaflet" ); + +# And they should if there is a Google API key. +$config->gmaps_api_key( "This is not a real API key." ); +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "div", { id => "map" }, + "Map shown on node if we have a Google API key"); + +# But not if the user doesn't want them. +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + display_google_maps => 0, + ); +$ENV{HTTP_COOKIE} = $cookie; +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::no_tag( $output, "div", { id => "map" }, + "...but not if the user turned it off" ); + +# And not if the admin doesn't want them. +$config->show_gmap_in_node_display( 0 ); +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + display_google_maps => 1, + ); +$ENV{HTTP_COOKIE} = $cookie; +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::no_tag( $output, "div", { id => "map" }, + "...and not if the admin turned it off" ); + +# Now test with Leaflet. +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, display_google_maps => 1 ); +$ENV{HTTP_COOKIE} = $cookie; +$config->gmaps_api_key( "I still have a key but don't expect to use it" ); +$config->show_gmap_in_node_display( 1 ); +$config->use_leaflet( 1 ); + +# Shouldn't get any of the GMap stuff. +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +unlike( $output, qr|new GMap|, + "No invocation of GMap constructor when using Leaflet" ); +unlike ( $output, qr|new GPoint|, "...nor GPoint" ); +unlike ( $output, qr|new GIcon|, "...nor GIcon" ); + +# Map should show in node if we're using Leaflet and have no GMap API key. +$config->gmaps_api_key( "" ); +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "div", { id => "node_map_canvas" }, + "Map shown on node if using Leaflet"); + +# But not if the user doesn't want them. +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + display_google_maps => 0, + ); +$ENV{HTTP_COOKIE} = $cookie; +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::no_tag( $output, "div", { id => "map" }, + "...but not if the user turned it off" ); + +# And not if the admin doesn't want them. +$config->show_gmap_in_node_display( 0 ); +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + display_google_maps => 1, + ); +$ENV{HTTP_COOKIE} = $cookie; +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::no_tag( $output, "div", { id => "map" }, + "...and not if the admin turned it off" );
Copied: trunk/t/407_navbar_placement.t (from rev 1381, trunk/t/47_navbar_placement.t) =================================================================== --- trunk/t/407_navbar_placement.t (rev 0) +++ trunk/t/407_navbar_placement.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,121 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +plan tests => 12; + +# NB These tests don't actually test the placement - but they do test that +# we get at least one navbar where appropriate. Better tests would be better. + +my ( $config, $guide, $wiki, $cookie, $output ); + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Make a guide. +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); + +# Write a node. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + ); + +# Make sure navbar shows up on node display. +$output = display_node( "Red Lion" ); +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "navbar included on node display" ); + +$config->content_above_navbar_in_html( 0 ); +$output = display_node( "Red Lion" ); +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 0" ); + +$config->content_above_navbar_in_html( 1 ); +$output = display_node( "Red Lion" ); +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 1" ); + +# And on home node, if it's switched on. +$config = OpenGuides::Test->make_basic_config; # get a fresh config +$guide = OpenGuides->new( config => $config ); # make sure the guide sees it +$config->navbar_on_home_page( 1 ); +$output = display_node( $config->home_name ); +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "navbar included on home node when navbar_on_home_page switched on" ); + +$config->content_above_navbar_in_html( 0 ); +$output = display_node( $config->home_name ); +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 0" ); + +$config->content_above_navbar_in_html( 1 ); +$output = display_node( $config->home_name ); +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 1" ); + +# But not on home node, if it's switched off. +$config = OpenGuides::Test->make_basic_config; # get a fresh config +$guide = OpenGuides->new( config => $config ); # make sure the guide sees it +$config->navbar_on_home_page( 0 ); +$output = display_node( $config->home_name ); +Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, + "navbar excluded from home node when navbar_on_home_page switched off" ); + +$config->content_above_navbar_in_html( 0 ); +$output = display_node( $config->home_name ); +Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 0" ); + +$config->content_above_navbar_in_html( 1 ); +$output = display_node( $config->home_name ); +Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 1" ); + +# Make sure navbar appears on recent changes. +$config = OpenGuides::Test->make_basic_config; # get a fresh config +$guide = OpenGuides->new( config => $config ); # make sure the guide sees it +$output = $guide->display_recent_changes( + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "navbar appears on recent changes" ); + +$config->content_above_navbar_in_html( 0 ); +$output = $guide->display_recent_changes( + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 0" ); + +$config->content_above_navbar_in_html( 1 ); +$output = $guide->display_recent_changes( + return_output => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, + "...ditto if content_above_navbar_in_html set to 1" ); + +sub display_node { + return $guide->display_node( id => shift, + return_output => 1, + noheaders => 1, + ); +}
Copied: trunk/t/408_google_analytics.t (from rev 1381, trunk/t/48_google_analytics.t) =================================================================== --- trunk/t/408_google_analytics.t (rev 0) +++ trunk/t/408_google_analytics.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,72 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +plan tests => 9; + +my ( $config, $guide, $wiki, $cookie, $output ); + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Make a guide. +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); + +# Write a node. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + ); + +# Make sure analytics stuff only shows up if we want it to. +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +unlike( $output, qr/ga.js/, "Google analytics omitted by default" ); + +$config->google_analytics_key( "" ); +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +unlike( $output, qr/ga.js/, "...also if analytics key is blank" ); + +$config->google_analytics_key( 0 ); +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +unlike( $output, qr/ga.js/, "...also if analytics key is zero" ); + +$config->google_analytics_key( "ThisIsNotAKey" ); +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +like( $output, qr/ga.js/, "does show up if key is provided" ); +like( $output, qr/ThisIsNotAKey/, "...correct key" ); +# Make sure analytics stuff only shows up if we want it to on recent changes +# recent changes doesnt use CGI. which we dont need anymore but we should test in case we change our mind again. + +$config->google_analytics_key( "" ); +$output = $guide->display_recent_changes( return_output => 1 ); +unlike( $output, qr/ga.js/, "...also if analytics key is blank" ); + +$config->google_analytics_key( 0 ); +$output = $guide->display_recent_changes( return_output => 1 ); +unlike( $output, qr/ga.js/, "...also if analytics key is zero" ); + +$config->google_analytics_key( "ThisIsNotAKey" ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr/ga.js/, "does show up if key is provided" ); +like( $output, qr/ThisIsNotAKey/, "...correct key" );
Copied: trunk/t/409_custom_header.t (from rev 1381, trunk/t/49_custom_header.t) =================================================================== --- trunk/t/409_custom_header.t (rev 0) +++ trunk/t/409_custom_header.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,59 @@ +use strict; +use Cwd; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +plan tests => 2; + +my $config = OpenGuides::Test->make_basic_config; +$config->custom_template_path( cwd . "/t/templates/tmp/" ); +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Make sure the tmp directory exists +eval { + mkdir cwd . "/t/templates/tmp"; +}; + +# Make sure we don't die if there's no custom header template. +eval { + unlink cwd . "/t/templates/tmp/custom_header.tt"; +}; +eval { + $guide->display_node( id => $config->home_name, return_output => 1 ); +}; +ok( !$@, "node display OK if no custom header template" ); + +# Write a custom template to add stuff to header. +open( FILE, ">", cwd . "/t/templates/tmp/custom_header.tt" ) + or die $!; +print FILE <<EOF; +<meta name="foo" content="bar" /> +EOF +close FILE or die $!; + +# Check that the custom template was picked up. +my $output = $guide->display_node( + id => $config->home_name, + return_output => 1, + noheaders => 1, + ); +$output =~ s/^Content-Type.*[\r\n]+//m; +Test::HTML::Content::tag_ok( $output, "meta", { name => "foo" }, + "custom template included in header" );
Deleted: trunk/t/40_search_as_feed.t =================================================================== --- trunk/t/40_search_as_feed.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/40_search_as_feed.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,60 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Search; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 7; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); - -# Plucene is the recommended searcher now. -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene( 0 ) }; - -my $search = OpenGuides::Search->new( config => $config ); -isa_ok( $search, "OpenGuides::Search" ); - -# Pop some test data in -my $wiki = $search->{wiki}; # white boxiness -$wiki->write_node( "Banana", "banana" ); -$wiki->write_node( "Monkey", "banana brains" ); -$wiki->write_node( "Monkey Brains", "BRANES" ); -$wiki->write_node( "Want Pie Now", "weebl" ); -$wiki->write_node( "Punctuation", "*" ); -$wiki->write_node( "Choice", "Eenie meenie minie mo"); - -# RSS search, should give 2 hits -my $output = $search->run( - return_output => 1, - vars => { search => "banana", format => "rss" }, - ); - -like($output, qr/<rdf:RDF/, "Really was RSS"); -like($output, qr/<items>/, "Really was RSS"); - -my @found = ($output =~ /(<rdf:li)/g); -is( scalar @found, 2, "found right entries in feed" ); - - -# Atom search, should give 1 hit -$output = $search->run( - return_output => 1, - vars => { search => "weebl", format => "atom" }, - ); -like($output, qr/<feed/, "Really was Atom"); -like($output, qr/<entry>/, "Really was Atom"); - -@found = ($output =~ /(<entry>)/g); -is( scalar @found, 1, "found right entries in feed" );
Deleted: trunk/t/41_deletion.t =================================================================== --- trunk/t/41_deletion.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/41_deletion.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,52 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Template; -use OpenGuides::Test; -use OpenGuides::CGI; -use Test::More tests => 3; - -my $config = OpenGuides::Test->make_basic_config; -$config->site_name( "Test Site" ); -$config->script_url( "/" ); - -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -my $output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "node.tt", -); -unlike( $output, qr/action=delete/, - "doesn't offer page deletion link by default" ); -$config->enable_page_deletion( "y" ); - # set is_admin to 1 -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -$ENV{HTTP_COOKIE} = $cookie; - -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "node.tt", -); -like( $output, qr/action=delete/, - "...but does when enable_page_deletion is set to 'y' and is_admin is 1" ); -$config->enable_page_deletion( 1 ); -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "node.tt", -); -like( $output, qr/action=delete/, - "...and when enable_page_deletion is set to '1' and is_admin is 1" );
Deleted: trunk/t/42_edit_conflict.t =================================================================== --- trunk/t/42_edit_conflict.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/42_edit_conflict.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,99 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; -} - -plan tests => 16; -# clear out database - OpenGuides::Test::refresh_db(); - -# Make a guide that works on latitude/longitude, and allows node images. -my $config = OpenGuides::Test->make_basic_config; -$config->geo_handler( 3 ); -$config->ellipsoid( "WGS-84" ); -$config->enable_node_image( 1 ); -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - - - -# Write some data. -OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - content => "A pub.", - locales => "W6", - categories => "Pubs\r\nPub Food", - latitude => 51.5, - longitude => -0.05, - ); - -# Make sure the normal edit form doesn't think there's a conflict. -my $output = $guide->display_edit_form( - id => "Crabtree Tavern", - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::no_tag( $output, "div", { class => "warning_text" }, - "Normal edit form doesn't contain warning_text" ); - -# Now try to commit some edits without giving the checksum. -$output = OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - content => "Still a pub.", - locales => "Hammersmith", - categories => "Beer Garden", - latitude => 41.5, - longitude => -0.04, - omit_checksum => 1, - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "div", { class => "warning_text" }, - "Edit conflict form contains warning_text" ); - -like( $output, qr/A pub./s, "...and old content" ); -like( $output, qr/Still a pub./s, "...and new content" ); -like( $output, qr/W6/s, "...and old locales" ); -like( $output, qr/Hammersmith/s, "...and new locales" ); -like( $output, qr/Pubs/s, "...and old categories" ); -like( $output, qr/Pub Food/s, "...both of them" ); -like( $output, qr/Beer Garden/s, "...and new categories" ); - -# Bug #173 (edit conflict form doesn't let you edit everything). -Test::HTML::Content::tag_ok( $output, "input", { name => "node_image" }, - "...and 'node_image' input box too" ); - -# Bug #48 (Edit conflict page erroneously converts lat/lon to os_x, os_y). -Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, - "UTM guide has 'latitude' input box in edit " - . "conflict" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "latitude", - value => 51.5 }, - "...with correct value" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, - "...and 'longitude' input box too" ); -Test::HTML::Content::tag_ok( $output, "input", { name => "longitude", - value => -0.05 }, - "...with correct value" ); -like( $output, qr/41.5/, "...new latitude is there too" ); -like( $output, qr/-0.04/, "...and new longitude" );
Deleted: trunk/t/43_preview_edits.t =================================================================== --- trunk/t/43_preview_edits.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/43_preview_edits.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,63 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; -} - -plan tests => 6; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -my $q = OpenGuides::Test->make_cgi_object( - content => "I am some content.", - summary => "I am a summary.", - node_image => "http://example.com/image.png", - node_image_copyright => "PhotoKake", - node_image_licence => "http://example.com/licence", - node_image_url => "http://example.com/info", -); - -# Get a checksum for a "blank" node. -my %node_data = $wiki->retrieve_node( "Clapham Junction Station" ); -$q->param( -name => "checksum", -value => $node_data{checksum} ); - -my $output = $guide->preview_edit( - id => "Clapham Junction Station", - cgi_obj => $q, - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -my $warned; -eval { - local $SIG{__WARN__} = sub { $warned = 1; }; - Test::HTML::Content::text_ok( $output, "I am a summary.", - "Summary shows up in preview." ); -}; -ok( !$warned, "...and HTML seems to be valid" ); -Test::HTML::Content::tag_ok( $output, "img", - { src => "http://example.com/image.png" }, - "Image URL shows up too" ); -like( $output, qr|©\s+PhotoKake|, "...so does image copyright holder" ); -Test::HTML::Content::link_ok( $output, "http://example.com/licence", - "...and we link to the licence" ); -Test::HTML::Content::link_ok( $output, "http://example.com/info", - "...and we link to the info page" );
Deleted: trunk/t/44_node_image.t =================================================================== --- trunk/t/44_node_image.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/44_node_image.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,205 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed."; -} - -plan tests => 30; - -my ( $config, $guide, $wiki ); - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Make sure node image fields don't show up in edit form if config says -# they shouldn't. -$config = OpenGuides::Test->make_basic_config; -$config->enable_node_image( 0 ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; - -my $output = $guide->display_edit_form( - id => "Red Lion", - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::no_tag( $output, "input", { name => "node_image" }, - "node_image field not in edit form if config says it shouldn't be" ); -Test::HTML::Content::no_tag( $output, "input", - { name => "node_image_licence" }, - "...ditto node_image_licence" ); -Test::HTML::Content::no_tag( $output, "input", - { name => "node_image_copyright" }, - "...ditto node_image_copyright" ); -Test::HTML::Content::no_tag( $output, "input", - { name => "node_image_url" }, - "...ditto node_image_url" ); - -# And make sure they do if it says they should. -$config->enable_node_image( 1 ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; - -$output = $guide->display_edit_form( - id => "Red Lion", - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "input", { name => "node_image" }, - "node_image field appears in edit form if config says it should" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_licence" }, - "...ditto node_image_licence" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_copyright" }, - "...ditto node_image_copyright" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_url" }, - "...ditto node_image_url" ); - -# Write all four fields to database, and make sure they're there. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - node_image => "http://example.com/foo.jpg", - node_image_licence => "http://example.com/bar/", - node_image_copyright => "Kake L Pugh", - node_image_url => "http://example.com/~kake/", - ); - -my %node_data = $wiki->retrieve_node( "Red Lion" ); -is( $node_data{metadata}{node_image}[0], "http://example.com/foo.jpg", - "node_image saved to database on node write" ); -is( $node_data{metadata}{node_image_licence}[0], "http://example.com/bar/", - "...node_image_licence too" ); -is( $node_data{metadata}{node_image_copyright}[0], "Kake L Pugh", - "...node_image_copyright too" ); -is( $node_data{metadata}{node_image_url}[0], "http://example.com/~kake/", - "...node_image_url too" ); - -# Make sure their content shows up in the edit form. -$output = $guide->display_edit_form( - id => "Red Lion", - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image", - value => "http://example.com/foo.jpg" }, - "node_image field has correct value in edit form", - ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_licence", - value => "http://example.com/bar/" }, - "...ditto node_image_licence" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_copyright", - value => "Kake L Pugh" }, - "...ditto node_image_copyright" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_url", - value => "http://example.com/~kake/" }, - "...ditto node_image_url" ); - -# Make sure they're displayed when a page is viewed. -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "img", - { src => "http://example.com/foo.jpg" }, - "node_image displayed on page" ); -Test::HTML::Content::tag_ok( $output, "a", - { href => "http://example.com/bar/" }, - "...ditto node_image_licence" ); -Test::HTML::Content::text_ok( $output, qr/Kake L Pugh/, - "...ditto node_image_copyright" ); -Test::HTML::Content::tag_ok( $output, "a", - { href => "http://example.com/~kake/" }, - "...ditto node_image_url" ); - -# Now try to commit some edits without giving the checksum. -$output = OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - node_image => "http://eg.com/foo.jpg", - node_image_licence - => "http://eg.com/bar/", - node_image_copyright => "NotKakeNo", - node_image_url - => "http://eg.com/~kake/", - omit_checksum => 1, - return_output => 1, - ); - -# Strip Content-Type header to stop Test::HTML::Content getting confused. -$output =~ s/^Content-Type.*[\r\n]+//m; - -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image", - value => "http://example.com/foo.jpg" }, - "Edit conflict form has input box with old " - . "node_image value in" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_licence", - value => "http://example.com/bar/" }, - "...and one with old node_image_licence value" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_copyright", - value => "Kake L Pugh" }, - "...and one with old node_image_copyright value" ); -Test::HTML::Content::tag_ok( $output, "input", - { name => "node_image_url", - value => "http://example.com/~kake/" }, - "...and one with old node_image_url value" ); -Test::HTML::Content::text_ok( $output, "http://eg.com/foo.jpg", - "...new node_image value appears too" ); -Test::HTML::Content::text_ok( $output, "http://eg.com/bar/", - "...as does new node_image_licence value" ); -Test::HTML::Content::text_ok( $output, "NotKakeNo", - "...as does new node_image_copyright value" ); -Test::HTML::Content::text_ok( $output, "http://eg.com/~kake/", - "...as does new node_image_url value" ); - -# Write node with node_image field consisting only of whitespace, make -# sure it gets stripped. -OpenGuides::Test->write_data( - guide => $guide, - node => "Angel and Greyhound", - node_image => " ", - ); -%node_data = $wiki->retrieve_node( "Angel and Greyhound" ); -ok( !$node_data{metadata}{node_image}, - "node_image of whitespace only isn't saved to database" ); - -$output = $guide->display_node( - id => "Angel and Greyhound", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::no_tag( $output, "img" => { id => "node_image" }, - "...or displayed on page" );
Deleted: trunk/t/45_home_recent_changes.t =================================================================== --- trunk/t/45_home_recent_changes.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/45_home_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,96 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 15; - -my ( $config, $guide, $wiki ); - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Write some data to show up in recent changes. -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - content => "A pub.", - username => "Kake", - comment => "I edited it.", - ); - -# First test that recent changes show up on the front page by default. -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); - -my $output = $guide->display_node( - id => $config->home_name, - return_output => 1, - ); -like( $output, qr/Red Lion/, - "recent changes show up on home page by default" ); -like( $output, qr/I edited it./, "...including comments" ); -like( $output, qr/Kake/, "...and usernames" ); -like( $output, qr/Edit this page/, "...edit this page link is there too" ); - -# And that they show up when we explicitly ask for them. -$config = OpenGuides::Test->make_basic_config; -$config->recent_changes_on_home_page( 1 ); -$guide = OpenGuides->new( config => $config ); - -$output = $guide->display_node( - id => $config->home_name, - return_output => 1, - ); -like( $output, qr/Red Lion/, - "recent changes show up on home page when we ask for them" ); -like( $output, qr/I edited it./, "...including comments" ); -like( $output, qr/Kake/, "...and usernames" ); -like( $output, qr/Edit this page/, "...edit this page link is there too" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - content => "A nice pub.", - username => "Earle", - comment => "I also edited it. For fun, here are two links: [[A Page]], and the same link [[A Page|again]].", - ); - -# Reload page. -$output = $guide->display_node( - id => $config->home_name, - return_output => 1, - ); - -like( $output, qr{<a href="\?A Page">A Page</a>}, "...simple wiki links appear in Recent Changes" ); -like( $output, qr{<a href="\?A Page">again</a>}, "...titled wiki links appear in Recent Changes" ); - - -# And that they don't show up if we don't want them. Turn off the navbar -# too, since we want to make sure the edit page link shows up regardless (it -# normally appears in the recent changes box). -$config = OpenGuides::Test->make_basic_config; -$config->recent_changes_on_home_page( 0 ); -$config->navbar_on_home_page( 0 ); -$guide = OpenGuides->new( config => $config ); - -$output = $guide->display_node( - id => $config->home_name, - return_output => 1, - ); -unlike( $output, qr/Red Lion/, - "recent changes don't show up on home page if we turn them off" ); -unlike( $output, qr/I edited it./, "...comments not shown either" ); -unlike( $output, qr/Kake/, "...nor usernames" ); -unlike( $output, qr/Ten most.*recent changes/, "...heading not shown either" ); -like( $output, qr/Edit this page/, "...edit this page link is there though" ); -
Deleted: trunk/t/46_map_in_node_display.t =================================================================== --- trunk/t/46_map_in_node_display.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/46_map_in_node_display.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,150 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - plan skip_all => "DBD::SQLite not installed - no database to test with"; - exit 0; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; - exit 0; -} - -plan tests => 10; - -my ( $config, $guide, $wiki, $cookie, $output ); - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Make a guide. -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; - -# Write a node with location data. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - os_x => 530000, - os_y => 180000, - ); - -# Maps shouldn't show up if there's no API key and we're not using Leaflet. -$config->show_gmap_in_node_display( 1 ); -$config->use_leaflet( 0 ); -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - display_google_maps => 1, - ); -$ENV{HTTP_COOKIE} = $cookie; - -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::no_tag( $output, "div", { id => "map" }, - "Map omitted from node if no API key and not using Leaflet" ); - -# And they should if there is a Google API key. -$config->gmaps_api_key( "This is not a real API key." ); -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "div", { id => "map" }, - "Map shown on node if we have a Google API key"); - -# But not if the user doesn't want them. -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - display_google_maps => 0, - ); -$ENV{HTTP_COOKIE} = $cookie; -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::no_tag( $output, "div", { id => "map" }, - "...but not if the user turned it off" ); - -# And not if the admin doesn't want them. -$config->show_gmap_in_node_display( 0 ); -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - display_google_maps => 1, - ); -$ENV{HTTP_COOKIE} = $cookie; -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::no_tag( $output, "div", { id => "map" }, - "...and not if the admin turned it off" ); - -# Now test with Leaflet. -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, display_google_maps => 1 ); -$ENV{HTTP_COOKIE} = $cookie; -$config->gmaps_api_key( "I still have a key but don't expect to use it" ); -$config->show_gmap_in_node_display( 1 ); -$config->use_leaflet( 1 ); - -# Shouldn't get any of the GMap stuff. -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -unlike( $output, qr|new GMap|, - "No invocation of GMap constructor when using Leaflet" ); -unlike ( $output, qr|new GPoint|, "...nor GPoint" ); -unlike ( $output, qr|new GIcon|, "...nor GIcon" ); - -# Map should show in node if we're using Leaflet and have no GMap API key. -$config->gmaps_api_key( "" ); -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "div", { id => "node_map_canvas" }, - "Map shown on node if using Leaflet"); - -# But not if the user doesn't want them. -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - display_google_maps => 0, - ); -$ENV{HTTP_COOKIE} = $cookie; -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::no_tag( $output, "div", { id => "map" }, - "...but not if the user turned it off" ); - -# And not if the admin doesn't want them. -$config->show_gmap_in_node_display( 0 ); -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - display_google_maps => 1, - ); -$ENV{HTTP_COOKIE} = $cookie; -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::no_tag( $output, "div", { id => "map" }, - "...and not if the admin turned it off" );
Deleted: trunk/t/47_navbar_placement.t =================================================================== --- trunk/t/47_navbar_placement.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/47_navbar_placement.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,121 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - plan skip_all => "DBD::SQLite not installed - no database to test with"; - exit 0; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; - exit 0; -} - -plan tests => 12; - -# NB These tests don't actually test the placement - but they do test that -# we get at least one navbar where appropriate. Better tests would be better. - -my ( $config, $guide, $wiki, $cookie, $output ); - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Make a guide. -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); - -# Write a node. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - ); - -# Make sure navbar shows up on node display. -$output = display_node( "Red Lion" ); -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "navbar included on node display" ); - -$config->content_above_navbar_in_html( 0 ); -$output = display_node( "Red Lion" ); -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 0" ); - -$config->content_above_navbar_in_html( 1 ); -$output = display_node( "Red Lion" ); -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 1" ); - -# And on home node, if it's switched on. -$config = OpenGuides::Test->make_basic_config; # get a fresh config -$guide = OpenGuides->new( config => $config ); # make sure the guide sees it -$config->navbar_on_home_page( 1 ); -$output = display_node( $config->home_name ); -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "navbar included on home node when navbar_on_home_page switched on" ); - -$config->content_above_navbar_in_html( 0 ); -$output = display_node( $config->home_name ); -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 0" ); - -$config->content_above_navbar_in_html( 1 ); -$output = display_node( $config->home_name ); -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 1" ); - -# But not on home node, if it's switched off. -$config = OpenGuides::Test->make_basic_config; # get a fresh config -$guide = OpenGuides->new( config => $config ); # make sure the guide sees it -$config->navbar_on_home_page( 0 ); -$output = display_node( $config->home_name ); -Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, - "navbar excluded from home node when navbar_on_home_page switched off" ); - -$config->content_above_navbar_in_html( 0 ); -$output = display_node( $config->home_name ); -Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 0" ); - -$config->content_above_navbar_in_html( 1 ); -$output = display_node( $config->home_name ); -Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 1" ); - -# Make sure navbar appears on recent changes. -$config = OpenGuides::Test->make_basic_config; # get a fresh config -$guide = OpenGuides->new( config => $config ); # make sure the guide sees it -$output = $guide->display_recent_changes( - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "navbar appears on recent changes" ); - -$config->content_above_navbar_in_html( 0 ); -$output = $guide->display_recent_changes( - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 0" ); - -$config->content_above_navbar_in_html( 1 ); -$output = $guide->display_recent_changes( - return_output => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, - "...ditto if content_above_navbar_in_html set to 1" ); - -sub display_node { - return $guide->display_node( id => shift, - return_output => 1, - noheaders => 1, - ); -}
Deleted: trunk/t/48_google_analytics.t =================================================================== --- trunk/t/48_google_analytics.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/48_google_analytics.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,72 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - plan skip_all => "DBD::SQLite not installed - no database to test with"; - exit 0; -} - -plan tests => 9; - -my ( $config, $guide, $wiki, $cookie, $output ); - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Make a guide. -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); - -# Write a node. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - ); - -# Make sure analytics stuff only shows up if we want it to. -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -unlike( $output, qr/ga.js/, "Google analytics omitted by default" ); - -$config->google_analytics_key( "" ); -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -unlike( $output, qr/ga.js/, "...also if analytics key is blank" ); - -$config->google_analytics_key( 0 ); -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -unlike( $output, qr/ga.js/, "...also if analytics key is zero" ); - -$config->google_analytics_key( "ThisIsNotAKey" ); -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -like( $output, qr/ga.js/, "does show up if key is provided" ); -like( $output, qr/ThisIsNotAKey/, "...correct key" ); -# Make sure analytics stuff only shows up if we want it to on recent changes -# recent changes doesnt use CGI. which we dont need anymore but we should test in case we change our mind again. - -$config->google_analytics_key( "" ); -$output = $guide->display_recent_changes( return_output => 1 ); -unlike( $output, qr/ga.js/, "...also if analytics key is blank" ); - -$config->google_analytics_key( 0 ); -$output = $guide->display_recent_changes( return_output => 1 ); -unlike( $output, qr/ga.js/, "...also if analytics key is zero" ); - -$config->google_analytics_key( "ThisIsNotAKey" ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr/ga.js/, "does show up if key is provided" ); -like( $output, qr/ThisIsNotAKey/, "...correct key" );
Deleted: trunk/t/49_custom_header.t =================================================================== --- trunk/t/49_custom_header.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/49_custom_header.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,59 +0,0 @@ -use strict; -use Cwd; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; - exit 0; -} - -plan tests => 2; - -my $config = OpenGuides::Test->make_basic_config; -$config->custom_template_path( cwd . "/t/templates/tmp/" ); -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Make sure the tmp directory exists -eval { - mkdir cwd . "/t/templates/tmp"; -}; - -# Make sure we don't die if there's no custom header template. -eval { - unlink cwd . "/t/templates/tmp/custom_header.tt"; -}; -eval { - $guide->display_node( id => $config->home_name, return_output => 1 ); -}; -ok( !$@, "node display OK if no custom header template" ); - -# Write a custom template to add stuff to header. -open( FILE, ">", cwd . "/t/templates/tmp/custom_header.tt" ) - or die $!; -print FILE <<EOF; -<meta name="foo" content="bar" /> -EOF -close FILE or die $!; - -# Check that the custom template was picked up. -my $output = $guide->display_node( - id => $config->home_name, - return_output => 1, - noheaders => 1, - ); -$output =~ s/^Content-Type.*[\r\n]+//m; -Test::HTML::Content::tag_ok( $output, "meta", { name => "foo" }, - "custom template included in header" );
Copied: trunk/t/500_http_response_codes.t (from rev 1381, trunk/t/50_http_response_codes.t) =================================================================== --- trunk/t/500_http_response_codes.t (rev 0) +++ trunk/t/500_http_response_codes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,39 @@ +use strict; +use Cwd; +use OpenGuides; +use OpenGuides::Template; +use OpenGuides::Test; +use Test::More tests => 3; + +my $config = OpenGuides::Test->make_basic_config; +$config->template_path( cwd . "/t/templates" ); + +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +eval { + OpenGuides::Template->output( wiki => $wiki, + config => $config, + template => "15_test.tt" ); +}; +is( $@, "", "is happy doing output" ); + +my $output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "15_test.tt" +); + +unlike( $output, qr/^Status:/, + "HTTP status not printed when not explicitly specified "); + +# Now supply a http status + +$output = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "15_test.tt", + http_status => '404' +); +like( $output, qr/^Status: 404/, + "Correct HTTP status printed when specified" );
Copied: trunk/t/501_display_node.t (from rev 1381, trunk/t/51_display_node.t) =================================================================== --- trunk/t/501_display_node.t (rev 0) +++ trunk/t/501_display_node.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,137 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +my $have_sqlite = $@ ? 0 : 1; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 20; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + admin_pass => "password", + } +); +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene ( 0 ) }; + +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); +$wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } ); +my $output = eval { + $guide->display_node( id => "Test Page", return_output => 1 ); +}; +is( $@, "", "->display_node doesn't die" ); + +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" ); +$config->home_name( "My Home Page" ); +$output = $guide->display_node( return_output => 1 ); +like( $output, qr/My\s+Home\s+Page/, "...and defaults to the home node, and takes notice of what we want to call it" ); +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" ); +my %tt_vars = $guide->display_node( return_tt_vars => 1 ); +ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" ); + +$wiki->write_node( 'Redirect Test', '#REDIRECT Test Page', undef ); + +$output = $guide->display_node( id => 'Redirect Test', + return_output => 1, + intercept_redirect => 1 ); + +like( $output, qr{^\QLocation: http://example.com/wiki.cgi?id=Test_Page;oldid=Redirect_Test%7Dms, + '#REDIRECT redirects correctly' ); + +$output = $guide->display_node( id => 'Redirect Test', return_output => 1, redirect => 0 ); + +unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' ); + +# Write a node, then delete one each of its categories and locales. +OpenGuides::Test->write_data( + guide => $guide, + node => "Non-existent categories and locales", + categories => "Does Not Exist\r\nDoes Exist", + locales => "Does Not Exist\r\nDoes Exist", + return_output => 1, + ); +foreach my $id ( ( "Category Does Not Exist", "Locale Does Not Exist" ) ) { + $guide->delete_node( + id => $id, + password => "password", + return_output => 1, + ); +} + +# Check the display comes up right for the existent and nonexistent. +$output = $guide->display_node( id => 'Non-existent categories and locales', + return_output => 1 + ); + +unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"}, + "category name not linked if category does not exist" ); +like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, + "...but does when it does exist" ); +unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"}, + "locale name not linked if category does not exist" ); +like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, + "...but does when it does exist" ); + +# Check it works when the case is different too. +OpenGuides::Test->write_data( + guide => $guide, + node => "Existent categories and locales", + categories => "does exist", + locales => "does exist", + return_output => 1, + ); + +$output = $guide->display_node( id => "Existent categories and locales", + return_output => 1 + ); +like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, + "wrongly-cased categories are linked as they should be" ); +like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, + "wrongly-cased locales are linked as they should be" ); + +$output = $guide->display_node( id => "Does not exist", + return_output => 1 + ); +like( $output, qr{\QWe don't have a node called "Does not exist".}, + "not found message shows up" ); +unlike( $output, qr{\QRevision 0}, + "bogus revision number doesn't show up" ); +unlike( $output, qr{\QLast edited}, + "bogus last edited doesn't show up" ); +like ( $output, qr{404 Not Found}, "404 status for empty node" ); + +# Make sure categories with numbers in are sorted correctly. Guess which pub +# I was in when I decided to finally fix this bug. +OpenGuides::Test->write_data( + guide => $guide, + node => "Dog And Bull", + categories => "GBG\r\nGBG2008\r\nGBG2011\r\nGBG2012\r\nGBG2007\r\nGBG2010\r\nGBG2009", + return_output => 1, + ); + +%tt_vars = $guide->display_node( id => "Dog And Bull", return_tt_vars => 1 ); +is_deeply( $tt_vars{category}, + [ qw( GBG GBG2007 GBG2008 GBG2009 GBG2010 GBG2011 GBG2012 ) ], + "categories with numbers in sorted correctly" );
Copied: trunk/t/502_display_diffs.t (from rev 1381, trunk/t/52_display_diffs.t) =================================================================== --- trunk/t/502_display_diffs.t (rev 0) +++ trunk/t/502_display_diffs.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,52 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 5; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + + +$wiki->write_node( "I Like Pie", "Best pie is meat pie." ) + or die "Couldn't write node"; +my %data = $wiki->retrieve_node( "I Like Pie" ); +$wiki->write_node( "I Like Pie", "Best pie is apple pie.", + $data{checksum} ) + or die "Couldn't write node"; +%data = $wiki->retrieve_node( "I Like Pie" ); +$wiki->write_node( "I Like Pie", "Best pie is lentil pie.", + $data{checksum} ) + or die "Couldn't write node"; + +my $output = eval { + $guide->display_diffs( + id => "I Like Pie", + version => 3, + other_version => 2, + return_output => 1, + ); +}; +is( $@, "", "->display_diffs doesn't die" ); +like( $output, + qr/differences between version 2 and version 3/i, + "...version numbers included in output" ); +like( $output, qr|<span class="node_name">I Like Pie</span>|, + "...node name inlined in output" ); +unlike( $output, qr/contents are identical/i, + "...'contents are identical' not printed when contents differ" ); +like( $output, qr/<th.*Version\s+2.*Version\s+3.*apple.*lentil/s, + "...versions are right way round" );
Copied: trunk/t/503_show_index.t (from rev 1381, trunk/t/53_show_index.t) =================================================================== --- trunk/t/503_show_index.t (rev 0) +++ trunk/t/503_show_index.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,219 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +my $thc = $@ ? 0 : 1; + +plan tests => 44; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); + + +$wiki->write_node( "Test Page", "foo", undef, + { category => "Alpha", locale => "Assam", + latitude => 51.754349, longitude => -1.258200 } ) + or die "Couldn't write node"; +$wiki->write_node( "Test Page 2", "foo", undef, + { category => "Alpha", locale => "Assam" } ) + or die "Couldn't write node"; +$wiki->write_node( "Test Page 3", "foo", undef, + { category => "Beta", locale => "Bangalore", + latitude => 51.8, longitude => -0.8 } ) + or die "Couldn't write node"; + +# Make sure that old-style invocations redirect to new. +my $output = $guide->show_index( type => "category", value => "Alpha", + return_output => 1, intercept_redirect => 1 ); +like( $output, qr/Status: 301/, + "Old-style category index search prints a redirect" ); +like( $output, qr/cat=alpha/, "...and includes the correct param/value pair" ); + +$output = $guide->show_index( type => "locale", value => "Assam", + return_output => 1, intercept_redirect => 1, + format => "map" ); +like( $output, qr/Status: 301/, + "Old-style locale index search prints a redirect" ); +like( $output, qr/loc=assam/, "...and includes the correct param/value pair" ); +like( $output, qr/format=map/, "...format parameter included too" ); + +# Test the normal, HTML version +$output = eval { + $guide->show_index( + cat => "Alpha", + return_output => 1, + noheaders => 1, + ); +}; +is( $@, "", "->show_index doesn't die" ); +like( $output, qr|wiki.cgi?Test_Page|, "...and includes correct links" ); +unlike( $output, qr|wiki.cgi?Test_Page_3|, "...but not incorrect ones" ); +unlike( $output, qr|<title>\s*-|, "...sets <title> correctly" ); + +# Test links in the header. +like( $output, qr|<link rel="alternate[^>]*action=index;cat=alpha;format=rss|, + "RSS link correct in header" ); +like( $output, qr|<link rel="alternate[^>]*action=index;cat=alpha;format=atom|, + "Atom link correct in header" ); + +# Test links in the footer. +my $footer = $output; +$footer =~ s/^.*This list is available as//s; +$footer =~ s|</p>.*$||s; +like( $footer, qr|action=index;cat=alpha;format=rdf|, + "RDF link correct in footer" ); +like( $footer, qr|action=index;cat=alpha;format=rss|, + "RSS link correct in footer" ); +like( $footer, qr|action=index;cat=alpha;format=atom|, + "Atom link correct in footer" ); + +# When using leaflet, test link to map version in body. +SKIP: { + skip "Test::HTML::Content not available", 1 unless $thc; + $config->use_leaflet( 1 ); + Test::HTML::Content::link_ok( $output, + "http://example.com/wiki.cgi?action=index;cat=alpha;format=map", + "We have a link to the map version" ); +} + +# Test the RDF version +$output = $guide->show_index( + cat => "Alpha", + return_output => 1, + format => "rdf" + ); +like( $output, qr|Content-Type: application/rdf+xml|, + "RDF output gets content-type of application/rdf+xml" ); +like( $output, qr|<rdf:RDF|, "Really is rdf" ); +like( $output, qr|dc:titleCategory Alpha</dc:title>|, "Right rdf title" ); +my @entries = ($output =~ /(<rdf:li>)/g); +is( 2, scalar @entries, "Right number of nodes included in rdf" ); + +# Test the RSS version +$output = eval { + $guide->show_index( + cat => "Alpha", + return_output => 1, + format => "rss", + ); +}; +is( $@, "", "->show_index doesn't die when asked for rss" ); +like( $output, qr|Content-Type: application/rdf+xml|, + "RSS output gets content-type of application/rdf+xml" ); +like( $output, "/<rdf:RDF.*?http://purl.org/rss//s", "Really is rss" ); +like( $output, qr|<title>Test - Index of Category Alpha</title>|, + "Right rss title" ); +@entries = ($output =~ /(</item>)/g); +is( 2, scalar @entries, "Right number of nodes included in rss" ); + +# Test the Atom version +$output = eval { + $guide->show_index( + cat => "Alpha", + return_output => 1, + format => "atom", + ); +}; +is( $@, "", "->show_index doesn't die when asked for atom" ); +like( $output, qr|Content-Type: application/atom+xml|, + "Atom output gets content-type of application/atom+xml" ); +like( $output, qr|<feed|, "Really is atom" ); +like( $output, qr|<title>Test - Index of Category Alpha</title>|, + "Right atom title" ); +@entries = ($output =~ /(<entry>)/g); +is( 2, scalar @entries, "Right number of nodes included in atom" ); + + +# Test the map version +# They will need a Helmert Transform provider for this to work +$config->gmaps_api_key("yes I have one"); +$config->geo_handler(1); +$config->force_wgs84(0); + +my $has_helmert = 0; +eval { + use OpenGuides::Utils; + $has_helmert = OpenGuides::Utils->get_wgs84_coords(latitude=>1,longitude=>1,config=>$config); +}; + +SKIP: { + skip "No Helmert Transform provider installed, can't test geo stuff", 6 + unless $has_helmert; + + # This is testing the legacy stuff. + $config->use_leaflet( 0 ); + + $output = eval { + $guide->show_index( + return_output => 1, + loc => "assam", + format => "map", + ); + }; + is( $@, "", "Using GMaps: ->show_index doesn't die when asked for map" ); + like( $output, qr|Content-Type: text/html|, + "...map output gets content-type of text/html" ); + like( $output, qr|new GMap|, "...really is google map" ); + my @points = ($output =~ /point\d+ = (new GPoint(.*?, .*?))/g); + is( 1, scalar @points, "...right number of nodes included on map" ); + + # -1.259687,51.754813 + like( $points[0], qr|51.75481|, "...has latitude"); + like( $points[0], qr|-1.25968|, "...has longitude"); +} + +# But we don't want the GMaps stuff if we're using Leaflet. +$config->use_leaflet( 1 ); + +$output = eval { + $guide->show_index( + return_output => 1, + loc => "assam", + format => "map", + ); +}; + +is( $@, "", "Using Leaflet: ->show_index doesn't die when asked for map" ); +like( $output, qr|Content-Type: text/html|, + "...map output gets content-type of text/html" ); +unlike( $output, qr|new GMap|, "...no invocation of GMap constructor" ); +unlike ( $output, qr|new GPoint|, "...nor GPoint" ); + +# Test links in the header (only implemented for Leaflet). +like( $output, + qr|<link rel="alternate[^>]*action=index;loc=assam;format=rss|, + "RSS link correct in header" ); +like( $output, + qr|<link rel="alternate[^>]*action=index;loc=assam;format=atom|, + "Atom link correct in header" ); + +SKIP: { + skip "Test::HTML::Content not available", 1 unless $thc; + # Do this again to get a version without headers, so T::H::C doesn't whine. + $output = $guide->show_index( + return_output => 1, + loc => "assam", + format => "map", + noheaders => 1, + ); + Test::HTML::Content::link_ok( $output, + "http://example.com/wiki.cgi?action=index;loc=assam", + "We have a link to the non-map version" ); +}
Copied: trunk/t/504_redirect.t (from rev 1381, trunk/t/54_redirect.t) =================================================================== --- trunk/t/504_redirect.t (rev 0) +++ trunk/t/504_redirect.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,51 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 2; + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + } +); +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene ( 0 ) }; + + OpenGuides::Test::refresh_db(); + +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + + +$wiki->write_node( "Test Page", "#REDIRECT [[Test Page 2]]" ) + or die "Can't write node"; +$wiki->write_node( "Test Page 2", "foo" ) + or die "Can't write node"; +my $output = eval { + $guide->display_node( id => "Test Page", + return_output => 1, + intercept_redirect => 1 ); +}; +is( $@, "", "->display_node doesn't die when page is a redirect" ); + +# Old versions of CGI.pm mistakenly print location: instead of Location: +like( $output, + qr/[lL]ocation: http://example.com/wiki.cgi?id=Test_Page_2;oldid=Test_Page/, + "...and redirects to the right place" );
Copied: trunk/t/505_node_history.t (from rev 1381, trunk/t/55_node_history.t) =================================================================== --- trunk/t/505_node_history.t (rev 0) +++ trunk/t/505_node_history.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,48 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +my $thc = $@ ? 0 : 1; + +plan tests => 4; + +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "mywiki.cgi" ); +$config->script_url( "http://example.com/" ); +my $guide = OpenGuides->new( config => $config ); + +$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"; +my %data = $guide->wiki->retrieve_node( "South Croydon Station" ); +$guide->wiki->write_node( "South Croydon Station", "A sleepy mainline station in what is arguably the nicest part of Croydon.", $data{checksum}, { comment => "<myfaketag>" } ) or die "Can't write node"; + +my $output = $guide->display_node( + id => "South Croydon Station", + version => 1, + return_output => 1, + noheaders => 1, + ); +like( $output, qr'South_Croydon_Station', + "node param escaped properly in links in historic view" ); +unlike( $output, qr'South%20Croydon%20Station', + "...in all links" ); +SKIP: { + skip "Test::HTML::Content not available", 2 unless $thc; + Test::HTML::Content::tag_ok( + $output, "span", { class => "current_version_title_link" }, + "historical version has link to current version near title" ); + Test::HTML::Content::link_ok( $output, + "mywiki.cgi?South_Croydon_Station", + "...and the link is correct" ); +}
Copied: trunk/t/506_diffs_with_macros.t (from rev 1381, trunk/t/56_diffs_with_macros.t) =================================================================== --- trunk/t/506_diffs_with_macros.t (rev 0) +++ trunk/t/506_diffs_with_macros.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,191 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use File::Temp qw( tempfile ); +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 4; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); + +# Print some RSS to a temporary file, and use a 'file://' URL to save faff. +my ($fh, $filename) = tempfile( UNLINK => 1 ); +while ( my $line = <DATA> ) { + print $fh $line; +} +close $fh; +my $url = 'file://' . $filename; + +OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + content => '@RSS ' . $url, + ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Crabtree Tavern", + content => '@RSS ' . $url, + ); +my $output = eval { + $guide->display_diffs( + id => "Crabtree Tavern", + version => 1, + other_version => 2, + return_output => 1, + ); +}; +is( $@, "", + "->display_diffs doesn't die when called on a node with RSS feeds in" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Calthorpe Arms", + content => '@INDEX_LIST [[Category Foo]]', + ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Calthorpe Arms", + content => '@INDEX_LIST [[Category Foo]]', + ); +$output = eval { + $guide->display_diffs( + id => "Calthorpe Arms", + version => 1, + other_version => 2, + return_output => 1, + ); +}; +is( $@, "", + "...or on a node with INDEX_LIST in" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Penderel's Oak", + content => '@INDEX_LINK [[Category Foo]]', + ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Penderel's Oak", + content => '@INDEX_LINK [[Category Foo]]', + ); +$output = eval { + $guide->display_diffs( + id => "Penderel's Oak", + version => 1, + other_version => 2, + return_output => 1, + ); +}; +is( $@, "", + "...or on a node with INDEX_LINK in" ); +like( $output, qr|view all pages in category foo|i, + "...and index link is correct" ); + + +__DATA__ +<?xml version="1.0" encoding="UTF-8"?> + +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns="http://purl.org/rss/1.0/" + xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" + xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/" + xmlns:admin="http://webns.net/mvcb/" +> + +<channel rdf:about="http://london.openguides.org/kakemirror/?RecentChanges"> +<title>The Open Guide to London - Kake's Mirror</title> +<link>http://london.openguides.org/kakemirror/?RecentChanges</link> +<description></description> +dc:date2004-12-14T12:59:42</dc:date> +wiki:interwiki</wiki:interwiki> +<items> + rdf:Seq + <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers..." /> + <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers..." /> + <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=..." /> + <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=..." /> + <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=..." /> + </rdf:Seq> +</items> +</channel> + +<item rdf:about="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;version=9"> +<title>Buckingham Arms, SW1H 9EU</title> +<link>http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers...</link> +<description>extraneous : [bob]</description> +dc:date2004-12-12T13:25:27</dc:date> +dc:contributorbob</dc:contributor> +wiki:history</wiki:history> +wiki:importanceminor</wiki:importance> +wiki:version9</wiki:version> +wiki:statusupdated</wiki:status> +wiki:diff</wiki:diff> +</item> + +<item rdf:about="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;version=8"> +<title>Buckingham Arms, SW1H 9EU</title> +<link>http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers...</link> +<description> [Martin]</description> +dc:date2004-12-11T14:05:38</dc:date> +dc:contributorMartin</dc:contributor> +wiki:history</wiki:history> +wiki:importancemajor</wiki:importance> +wiki:version8</wiki:version> +wiki:statusupdated</wiki:status> +wiki:diff</wiki:diff> +</item> + +<item rdf:about="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=14"> +<title>Star Tavern, SW1X 8HT</title> +<link>http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=...</link> +<description>De-bobbed the bob bits. [Kake]</description> +dc:date2004-12-10T14:29:13</dc:date> +dc:contributorKake</dc:contributor> +wiki:history</wiki:history> +wiki:importanceminor</wiki:importance> +wiki:version14</wiki:version> +wiki:statusupdated</wiki:status> +wiki:diff</wiki:diff> +</item> + +<item rdf:about="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=13"> +<title>Star Tavern, SW1X 8HT</title> +<link>http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=...</link> +<description>More comments. [Kake]</description> +dc:date2004-12-10T14:27:41</dc:date> +dc:contributorKake</dc:contributor> +wiki:history</wiki:history> +wiki:importancemajor</wiki:importance> +wiki:version13</wiki:version> +wiki:statusupdated</wiki:status> +wiki:diff</wiki:diff> +</item> + +<item rdf:about="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=12"> +<title>Star Tavern, SW1X 8HT</title> +<link>http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=...</link> +<description>updated [bob]</description> +dc:date2004-12-10T14:18:51</dc:date> +dc:contributorbob</dc:contributor> +wiki:history</wiki:history> +wiki:importanceminor</wiki:importance> +wiki:version12</wiki:version> +wiki:statusupdated</wiki:status> +wiki:diff</wiki:diff> +</item> + +</rdf:RDF>
Copied: trunk/t/507_random_page.t (from rev 1381, trunk/t/57_random_page.t) =================================================================== --- trunk/t/507_random_page.t (rev 0) +++ trunk/t/507_random_page.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,157 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Test; +use OpenGuides; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 8; + +my ( $config, $guide, $wiki ); + +# Clear out database from previous runs, set up a guide. + OpenGuides::Test::refresh_db(); + +$config = OpenGuides::Test->make_basic_config; +$config->script_url( "http://www.example.com/" ); +$config->script_name( "wiki.cgi" ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; + +# Write some data. +my %nodes = map { $_ => "A pub." } ( "Red Lion", "Farmers Arms", "Angel" ); +foreach my $node ( keys %nodes ) { + OpenGuides::Test->write_data( + guide => $guide, + node => $node, + return_output => 1, + ); +} + +# See what we get when we ask for a random page. +my $output = $guide->display_random_page( return_output => 1 ); + +# Old versions of CGI.pm mistakenly print location: instead of Location: +like( $output, qr/[lL]ocation: http://www.example.com/wiki.cgi/, + "->display_random_page makes a redirect" ); + +my $node = get_node_from_output( $output ); +print "# Random node chosen: $node\n"; +ok( $nodes{$node}, "...to an existing node" ); + +# Clear the database and write some data including categories and locales. + OpenGuides::Test::refresh_db(); + +$config = OpenGuides::Test->make_basic_config; +$config->script_url( "http://www.example.com/" ); +$config->script_name( "wiki.cgi" ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; + +# Write data including some categories/locales. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + locales => "Hammersmith", + categories => "Pubs", + return_output => 1, + ); + +# Check we can turn off locales. +$config = OpenGuides::Test->make_basic_config; +$config->script_url( "http://www.example.com/" ); +$config->script_name( "wiki.cgi" ); +$config->random_page_omits_locales( 1 ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; +$output = $guide->display_random_page( return_output => 1 ); +$node = get_node_from_output( $output ); +print "# Random node chosen: $node\n"; +isnt( $node, "Locale Hammersmith", "locale nodes not picked up as random page " + . "(this test may sometimes pass when it shouldn't)" ); + +# Check we can turn off categories. +$config = OpenGuides::Test->make_basic_config; +$config->script_url( "http://www.example.com/" ); +$config->script_name( "wiki.cgi" ); +$config->random_page_omits_categories( 1 ); +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; +$output = $guide->display_random_page( return_output => 1 ); +$node = get_node_from_output( $output ); +print "# Random node chosen: $node\n"; +isnt( $node, "Category Pubs", "category nodes not picked up as random page " + . "(this test may sometimes pass when it shouldn't)" ); + +# Now make sure we can pick things up from specific categories/locales if asked + OpenGuides::Test::refresh_db(); + +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + locales => "Hammersmith", + categories => "Pubs", + return_output => 1, + ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Poppy Hana", + locales => "Bermondsey", + categories => "Restaurants", + return_output => 1, + ); +$output = $guide->display_random_page( category => "Pubs", + return_output => 1 ); +$node = get_node_from_output( $output ); +print "# Random node chosen: $node\n"; +is( $node, "Red Lion", "can ask for a random pub " + . "(this test may sometimes pass when it shouldn't)" ); + +$output = $guide->display_random_page( locale => "Bermondsey", + return_output => 1 ); +$node = get_node_from_output( $output ); +print "# Random node chosen: $node\n"; +is( $node, "Poppy Hana", "can ask for a random thing in Bermondsey " + . "(this test may sometimes pass when it shouldn't)" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Stanley Arms", + locales => "Bermondsey", + categories => "Pubs", + return_output => 1, + ); +$output = $guide->display_random_page( locale => "Bermondsey", + category => "Pubs", + return_output => 1 + ); +$node = get_node_from_output( $output ); +print "# Random node chosen: $node\n"; +is( $node, "Stanley Arms", "can ask for a random pub in Bermondsey " + . "(this test may sometimes pass when it shouldn't)" ); + + +$output = $guide->display_random_page( locale => "Islington", + category => "Cinemas", + return_output => 1 + ); +unlike( $output, qr/Status: 302/, + "don't get a redirect if we ask for category/locale with no pages in" ); + + +sub get_node_from_output { + my $node_param = shift; + $node_param =~ s/^.*?//s; + $node_param =~ s/\s+$//; + my $formatter = $guide->wiki->formatter; + my $node = $formatter->node_param_to_node_name( $node_param ); + return $node; +}
Copied: trunk/t/508_navbar_common_locales_categories.t (from rev 1381, trunk/t/58_navbar_common_locales_categories.t) =================================================================== --- trunk/t/508_navbar_common_locales_categories.t (rev 0) +++ trunk/t/508_navbar_common_locales_categories.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,72 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +sub get_recent_changes { + my ($guide) = @_; + + my $output = $guide->display_recent_changes( return_output => 1 ); + $output =~ s/^Content-Type.*[\r\n]+//m; + + return $output; +} + +sub get_preferences { + my $guide = shift; + return $guide->display_prefs_form( return_output => 1, noheaders => 1 ); +} + +my %pages = ( + recent_changes => &get_recent_changes, + preferences => &get_preferences, +); + +plan tests => 4 * keys %pages; + +my ( $config, $guide, $wiki, $output ); + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +while (my ($page, $get_content) = each %pages) { + + # Make a guide with common categories and locales enabled. + $config = OpenGuides::Test->make_basic_config; + $config->enable_common_categories( 1 ); + $config->enable_common_locales( 1 ); + $guide = OpenGuides->new( config => $config ); + + # Make sure common categories and locales show up. + $output = $get_content->($guide); + + Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_categories" }, + "common categories in $page navbar" ); + Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_locales" }, + "...common locales too" ); + + # Now make a guide with common categories and locales disabled. + $config = OpenGuides::Test->make_basic_config; + $guide = OpenGuides->new( config => $config ); + + # Make sure common categories/locales are omitted. + $output = $get_content->($guide); + + Test::HTML::Content::no_tag( $output, "div", { id => "navbar_categories" }, + "common categories in $page navbar" ); + Test::HTML::Content::no_tag( $output, "div", { id => "navbar_locales" }, + "...common locales too" ); +}
Copied: trunk/t/509_preferences.t (from rev 1381, trunk/t/59_preferences.t) =================================================================== --- trunk/t/509_preferences.t (rev 0) +++ trunk/t/509_preferences.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,150 @@ +use strict; +use JSON; +use OpenGuides; +use OpenGuides::JSON; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +plan tests => 17; + +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Make sure "return_to" TT var is set iff referrer domain is correct. +$config->script_url( "http://example.com/" ); +$config->script_name( "wiki.cgi" ); +my $good_return_to = "http://example.com/wiki.cgi?Test_Page"; +my $evil_return_to = "http://example.org/naughty-script"; + +$ENV{HTTP_REFERER} = $good_return_to; +my %tt_vars = $guide->display_prefs_form( return_tt_vars => 1 ); +is( $tt_vars{return_to_url}, $good_return_to, + "Return URL set when referrer matches script URL/name" ); +my $output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, + "input", { type => "hidden", name => "return_to_url" }, + "...corresponding hidden input is there in the form" ); +Test::HTML::Content::tag_ok( $output, + "input", { type => "hidden", name => "return_to_url", + value => $good_return_to }, + "...with correct value" ); + +$ENV{HTTP_REFERER} = $evil_return_to; +%tt_vars = $guide->display_prefs_form( return_tt_vars => 1 ); +ok( !$tt_vars{return_to_url}, + "Return URL not set when referrer doesn't match script URL/name" ); +$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); +Test::HTML::Content::no_tag( $output, + "input", { type => "hidden", name => "return_to_url" }, + "...and no corresponding hidden input in form" ); + +# If we have a google API key and node maps are enabled, we should see the +# checkbox for this pref. +$config->gmaps_api_key( "This is not a real API key." ); +$config->show_gmap_in_node_display( 1 ); + +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + display_google_maps => 1, + ); +$ENV{HTTP_COOKIE} = $cookie; +$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, + "input", { type => "checkbox", name => "display_google_maps" }, + "Node map preference checkbox shown when we have a GMaps API key." ); + +# But not if the node map is globally disabled +$config->show_gmap_in_node_display( 0 ); +$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); +Test::HTML::Content::no_tag( $output, + "input", { type => "checkbox", name => "display_google_maps" }, + "...but not when node maps are globally disabled." ); + +# Now test with Leaflet enabled and no Google API key. +$config->gmaps_api_key( "" ); +$config->show_gmap_in_node_display( 1 ); +$config->use_leaflet( 1 ); + +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + display_google_maps => 1, + ); +$ENV{HTTP_COOKIE} = $cookie; +$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, + "input", { type => "checkbox", name => "display_google_maps" }, + "Node map preference checkbox shown when we're using Leaflet." ); + +$config->show_gmap_in_node_display( 0 ); +$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); +Test::HTML::Content::no_tag( $output, + "input", { type => "checkbox", name => "display_google_maps" }, + "...but not when node maps are globally disabled." ); + +# Test JSON version of prefs page. +my $json_writer = OpenGuides::JSON->new( wiki => $wiki, + config => $config ); +delete $ENV{HTTP_COOKIE}; +$output = eval { + $json_writer->make_prefs_json(); +}; +ok( !$@, "->make_prefs_json() doesn't die when no cookie set." ); +if ( $@ ) { warn "# Error was: $@"; } +# Need to strip out the Content-Type: header or the decoder gets confused. +$output =~ s/^Content-Type:.*\n//s; +my $parsed = eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + decode_json( $output ); +}; +ok( !$@, "...and its output looks like JSON." ); +if ( $@ ) { warn "# Warning was: $@"; } +ok( $parsed->{username}, "...and a username is included in the output" ); +#use Data::Dumper; print Dumper $parsed; exit 0; + +$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( config => $config ); +$output = eval { + $json_writer->make_prefs_json(); +}; +ok( !$@, "->make_prefs_json() doesn't die when cookie set with all defaults."); +if ( $@ ) { warn "# Error was: $@"; } +$output =~ s/^Content-Type:.*\n//s; +$parsed = eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + decode_json( $output ); +}; +ok( !$@, "...and its output looks like JSON." ); +if ( $@ ) { warn "# Warning was: $@"; } +# We don't get a username set in this case. + +$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( config => $config, + username => "Kake" ); +$output = eval { + $json_writer->make_prefs_json(); +}; +ok( !$@, + "->make_prefs_json() doesn't die when cookie set with given username."); +if ( $@ ) { warn "# Error was: $@"; } +$output =~ s/^Content-Type:.*\n//s; +$parsed = eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + decode_json( $output ); +}; +ok( !$@, "...and its output looks like JSON." ); +if ( $@ ) { warn "# Warning was: $@"; } +is( $parsed->{username}, "Kake", + "...and the correct username is included in the output" );
Deleted: trunk/t/50_http_response_codes.t =================================================================== --- trunk/t/50_http_response_codes.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/50_http_response_codes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,39 +0,0 @@ -use strict; -use Cwd; -use OpenGuides; -use OpenGuides::Template; -use OpenGuides::Test; -use Test::More tests => 3; - -my $config = OpenGuides::Test->make_basic_config; -$config->template_path( cwd . "/t/templates" ); - -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -eval { - OpenGuides::Template->output( wiki => $wiki, - config => $config, - template => "15_test.tt" ); -}; -is( $@, "", "is happy doing output" ); - -my $output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt" -); - -unlike( $output, qr/^Status:/, - "HTTP status not printed when not explicitly specified "); - -# Now supply a http status - -$output = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "15_test.tt", - http_status => '404' -); -like( $output, qr/^Status: 404/, - "Correct HTTP status printed when specified" );
Deleted: trunk/t/51_display_node.t =================================================================== --- trunk/t/51_display_node.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/51_display_node.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,137 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -my $have_sqlite = $@ ? 0 : 1; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 20; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - admin_pass => "password", - } -); -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene ( 0 ) }; - -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); -$wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } ); -my $output = eval { - $guide->display_node( id => "Test Page", return_output => 1 ); -}; -is( $@, "", "->display_node doesn't die" ); - -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" ); -$config->home_name( "My Home Page" ); -$output = $guide->display_node( return_output => 1 ); -like( $output, qr/My\s+Home\s+Page/, "...and defaults to the home node, and takes notice of what we want to call it" ); -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" ); -my %tt_vars = $guide->display_node( return_tt_vars => 1 ); -ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" ); - -$wiki->write_node( 'Redirect Test', '#REDIRECT Test Page', undef ); - -$output = $guide->display_node( id => 'Redirect Test', - return_output => 1, - intercept_redirect => 1 ); - -like( $output, qr{^\QLocation: http://example.com/wiki.cgi?id=Test_Page;oldid=Redirect_Test%7Dms, - '#REDIRECT redirects correctly' ); - -$output = $guide->display_node( id => 'Redirect Test', return_output => 1, redirect => 0 ); - -unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' ); - -# Write a node, then delete one each of its categories and locales. -OpenGuides::Test->write_data( - guide => $guide, - node => "Non-existent categories and locales", - categories => "Does Not Exist\r\nDoes Exist", - locales => "Does Not Exist\r\nDoes Exist", - return_output => 1, - ); -foreach my $id ( ( "Category Does Not Exist", "Locale Does Not Exist" ) ) { - $guide->delete_node( - id => $id, - password => "password", - return_output => 1, - ); -} - -# Check the display comes up right for the existent and nonexistent. -$output = $guide->display_node( id => 'Non-existent categories and locales', - return_output => 1 - ); - -unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"}, - "category name not linked if category does not exist" ); -like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, - "...but does when it does exist" ); -unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"}, - "locale name not linked if category does not exist" ); -like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, - "...but does when it does exist" ); - -# Check it works when the case is different too. -OpenGuides::Test->write_data( - guide => $guide, - node => "Existent categories and locales", - categories => "does exist", - locales => "does exist", - return_output => 1, - ); - -$output = $guide->display_node( id => "Existent categories and locales", - return_output => 1 - ); -like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"}, - "wrongly-cased categories are linked as they should be" ); -like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"}, - "wrongly-cased locales are linked as they should be" ); - -$output = $guide->display_node( id => "Does not exist", - return_output => 1 - ); -like( $output, qr{\QWe don't have a node called "Does not exist".}, - "not found message shows up" ); -unlike( $output, qr{\QRevision 0}, - "bogus revision number doesn't show up" ); -unlike( $output, qr{\QLast edited}, - "bogus last edited doesn't show up" ); -like ( $output, qr{404 Not Found}, "404 status for empty node" ); - -# Make sure categories with numbers in are sorted correctly. Guess which pub -# I was in when I decided to finally fix this bug. -OpenGuides::Test->write_data( - guide => $guide, - node => "Dog And Bull", - categories => "GBG\r\nGBG2008\r\nGBG2011\r\nGBG2012\r\nGBG2007\r\nGBG2010\r\nGBG2009", - return_output => 1, - ); - -%tt_vars = $guide->display_node( id => "Dog And Bull", return_tt_vars => 1 ); -is_deeply( $tt_vars{category}, - [ qw( GBG GBG2007 GBG2008 GBG2009 GBG2010 GBG2011 GBG2012 ) ], - "categories with numbers in sorted correctly" );
Deleted: trunk/t/52_display_diffs.t =================================================================== --- trunk/t/52_display_diffs.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/52_display_diffs.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,52 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 5; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - - -$wiki->write_node( "I Like Pie", "Best pie is meat pie." ) - or die "Couldn't write node"; -my %data = $wiki->retrieve_node( "I Like Pie" ); -$wiki->write_node( "I Like Pie", "Best pie is apple pie.", - $data{checksum} ) - or die "Couldn't write node"; -%data = $wiki->retrieve_node( "I Like Pie" ); -$wiki->write_node( "I Like Pie", "Best pie is lentil pie.", - $data{checksum} ) - or die "Couldn't write node"; - -my $output = eval { - $guide->display_diffs( - id => "I Like Pie", - version => 3, - other_version => 2, - return_output => 1, - ); -}; -is( $@, "", "->display_diffs doesn't die" ); -like( $output, - qr/differences between version 2 and version 3/i, - "...version numbers included in output" ); -like( $output, qr|<span class="node_name">I Like Pie</span>|, - "...node name inlined in output" ); -unlike( $output, qr/contents are identical/i, - "...'contents are identical' not printed when contents differ" ); -like( $output, qr/<th.*Version\s+2.*Version\s+3.*apple.*lentil/s, - "...versions are right way round" );
Deleted: trunk/t/53_show_index.t =================================================================== --- trunk/t/53_show_index.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/53_show_index.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,219 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -my $thc = $@ ? 0 : 1; - -plan tests => 44; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); - - -$wiki->write_node( "Test Page", "foo", undef, - { category => "Alpha", locale => "Assam", - latitude => 51.754349, longitude => -1.258200 } ) - or die "Couldn't write node"; -$wiki->write_node( "Test Page 2", "foo", undef, - { category => "Alpha", locale => "Assam" } ) - or die "Couldn't write node"; -$wiki->write_node( "Test Page 3", "foo", undef, - { category => "Beta", locale => "Bangalore", - latitude => 51.8, longitude => -0.8 } ) - or die "Couldn't write node"; - -# Make sure that old-style invocations redirect to new. -my $output = $guide->show_index( type => "category", value => "Alpha", - return_output => 1, intercept_redirect => 1 ); -like( $output, qr/Status: 301/, - "Old-style category index search prints a redirect" ); -like( $output, qr/cat=alpha/, "...and includes the correct param/value pair" ); - -$output = $guide->show_index( type => "locale", value => "Assam", - return_output => 1, intercept_redirect => 1, - format => "map" ); -like( $output, qr/Status: 301/, - "Old-style locale index search prints a redirect" ); -like( $output, qr/loc=assam/, "...and includes the correct param/value pair" ); -like( $output, qr/format=map/, "...format parameter included too" ); - -# Test the normal, HTML version -$output = eval { - $guide->show_index( - cat => "Alpha", - return_output => 1, - noheaders => 1, - ); -}; -is( $@, "", "->show_index doesn't die" ); -like( $output, qr|wiki.cgi?Test_Page|, "...and includes correct links" ); -unlike( $output, qr|wiki.cgi?Test_Page_3|, "...but not incorrect ones" ); -unlike( $output, qr|<title>\s*-|, "...sets <title> correctly" ); - -# Test links in the header. -like( $output, qr|<link rel="alternate[^>]*action=index;cat=alpha;format=rss|, - "RSS link correct in header" ); -like( $output, qr|<link rel="alternate[^>]*action=index;cat=alpha;format=atom|, - "Atom link correct in header" ); - -# Test links in the footer. -my $footer = $output; -$footer =~ s/^.*This list is available as//s; -$footer =~ s|</p>.*$||s; -like( $footer, qr|action=index;cat=alpha;format=rdf|, - "RDF link correct in footer" ); -like( $footer, qr|action=index;cat=alpha;format=rss|, - "RSS link correct in footer" ); -like( $footer, qr|action=index;cat=alpha;format=atom|, - "Atom link correct in footer" ); - -# When using leaflet, test link to map version in body. -SKIP: { - skip "Test::HTML::Content not available", 1 unless $thc; - $config->use_leaflet( 1 ); - Test::HTML::Content::link_ok( $output, - "http://example.com/wiki.cgi?action=index;cat=alpha;format=map", - "We have a link to the map version" ); -} - -# Test the RDF version -$output = $guide->show_index( - cat => "Alpha", - return_output => 1, - format => "rdf" - ); -like( $output, qr|Content-Type: application/rdf+xml|, - "RDF output gets content-type of application/rdf+xml" ); -like( $output, qr|<rdf:RDF|, "Really is rdf" ); -like( $output, qr|dc:titleCategory Alpha</dc:title>|, "Right rdf title" ); -my @entries = ($output =~ /(<rdf:li>)/g); -is( 2, scalar @entries, "Right number of nodes included in rdf" ); - -# Test the RSS version -$output = eval { - $guide->show_index( - cat => "Alpha", - return_output => 1, - format => "rss", - ); -}; -is( $@, "", "->show_index doesn't die when asked for rss" ); -like( $output, qr|Content-Type: application/rdf+xml|, - "RSS output gets content-type of application/rdf+xml" ); -like( $output, "/<rdf:RDF.*?http://purl.org/rss//s", "Really is rss" ); -like( $output, qr|<title>Test - Index of Category Alpha</title>|, - "Right rss title" ); -@entries = ($output =~ /(</item>)/g); -is( 2, scalar @entries, "Right number of nodes included in rss" ); - -# Test the Atom version -$output = eval { - $guide->show_index( - cat => "Alpha", - return_output => 1, - format => "atom", - ); -}; -is( $@, "", "->show_index doesn't die when asked for atom" ); -like( $output, qr|Content-Type: application/atom+xml|, - "Atom output gets content-type of application/atom+xml" ); -like( $output, qr|<feed|, "Really is atom" ); -like( $output, qr|<title>Test - Index of Category Alpha</title>|, - "Right atom title" ); -@entries = ($output =~ /(<entry>)/g); -is( 2, scalar @entries, "Right number of nodes included in atom" ); - - -# Test the map version -# They will need a Helmert Transform provider for this to work -$config->gmaps_api_key("yes I have one"); -$config->geo_handler(1); -$config->force_wgs84(0); - -my $has_helmert = 0; -eval { - use OpenGuides::Utils; - $has_helmert = OpenGuides::Utils->get_wgs84_coords(latitude=>1,longitude=>1,config=>$config); -}; - -SKIP: { - skip "No Helmert Transform provider installed, can't test geo stuff", 6 - unless $has_helmert; - - # This is testing the legacy stuff. - $config->use_leaflet( 0 ); - - $output = eval { - $guide->show_index( - return_output => 1, - loc => "assam", - format => "map", - ); - }; - is( $@, "", "Using GMaps: ->show_index doesn't die when asked for map" ); - like( $output, qr|Content-Type: text/html|, - "...map output gets content-type of text/html" ); - like( $output, qr|new GMap|, "...really is google map" ); - my @points = ($output =~ /point\d+ = (new GPoint(.*?, .*?))/g); - is( 1, scalar @points, "...right number of nodes included on map" ); - - # -1.259687,51.754813 - like( $points[0], qr|51.75481|, "...has latitude"); - like( $points[0], qr|-1.25968|, "...has longitude"); -} - -# But we don't want the GMaps stuff if we're using Leaflet. -$config->use_leaflet( 1 ); - -$output = eval { - $guide->show_index( - return_output => 1, - loc => "assam", - format => "map", - ); -}; - -is( $@, "", "Using Leaflet: ->show_index doesn't die when asked for map" ); -like( $output, qr|Content-Type: text/html|, - "...map output gets content-type of text/html" ); -unlike( $output, qr|new GMap|, "...no invocation of GMap constructor" ); -unlike ( $output, qr|new GPoint|, "...nor GPoint" ); - -# Test links in the header (only implemented for Leaflet). -like( $output, - qr|<link rel="alternate[^>]*action=index;loc=assam;format=rss|, - "RSS link correct in header" ); -like( $output, - qr|<link rel="alternate[^>]*action=index;loc=assam;format=atom|, - "Atom link correct in header" ); - -SKIP: { - skip "Test::HTML::Content not available", 1 unless $thc; - # Do this again to get a version without headers, so T::H::C doesn't whine. - $output = $guide->show_index( - return_output => 1, - loc => "assam", - format => "map", - noheaders => 1, - ); - Test::HTML::Content::link_ok( $output, - "http://example.com/wiki.cgi?action=index;loc=assam", - "We have a link to the non-map version" ); -}
Deleted: trunk/t/54_redirect.t =================================================================== --- trunk/t/54_redirect.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/54_redirect.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,51 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 2; - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - } -); -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene ( 0 ) }; - - OpenGuides::Test::refresh_db(); - -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - - -$wiki->write_node( "Test Page", "#REDIRECT [[Test Page 2]]" ) - or die "Can't write node"; -$wiki->write_node( "Test Page 2", "foo" ) - or die "Can't write node"; -my $output = eval { - $guide->display_node( id => "Test Page", - return_output => 1, - intercept_redirect => 1 ); -}; -is( $@, "", "->display_node doesn't die when page is a redirect" ); - -# Old versions of CGI.pm mistakenly print location: instead of Location: -like( $output, - qr/[lL]ocation: http://example.com/wiki.cgi?id=Test_Page_2;oldid=Test_Page/, - "...and redirects to the right place" );
Deleted: trunk/t/55_node_history.t =================================================================== --- trunk/t/55_node_history.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/55_node_history.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,48 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -my $thc = $@ ? 0 : 1; - -plan tests => 4; - -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "mywiki.cgi" ); -$config->script_url( "http://example.com/" ); -my $guide = OpenGuides->new( config => $config ); - -$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"; -my %data = $guide->wiki->retrieve_node( "South Croydon Station" ); -$guide->wiki->write_node( "South Croydon Station", "A sleepy mainline station in what is arguably the nicest part of Croydon.", $data{checksum}, { comment => "<myfaketag>" } ) or die "Can't write node"; - -my $output = $guide->display_node( - id => "South Croydon Station", - version => 1, - return_output => 1, - noheaders => 1, - ); -like( $output, qr'South_Croydon_Station', - "node param escaped properly in links in historic view" ); -unlike( $output, qr'South%20Croydon%20Station', - "...in all links" ); -SKIP: { - skip "Test::HTML::Content not available", 2 unless $thc; - Test::HTML::Content::tag_ok( - $output, "span", { class => "current_version_title_link" }, - "historical version has link to current version near title" ); - Test::HTML::Content::link_ok( $output, - "mywiki.cgi?South_Croydon_Station", - "...and the link is correct" ); -}
Deleted: trunk/t/56_diffs_with_macros.t =================================================================== --- trunk/t/56_diffs_with_macros.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/56_diffs_with_macros.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,191 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use File::Temp qw( tempfile ); -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 4; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); - -# Print some RSS to a temporary file, and use a 'file://' URL to save faff. -my ($fh, $filename) = tempfile( UNLINK => 1 ); -while ( my $line = <DATA> ) { - print $fh $line; -} -close $fh; -my $url = 'file://' . $filename; - -OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - content => '@RSS ' . $url, - ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Crabtree Tavern", - content => '@RSS ' . $url, - ); -my $output = eval { - $guide->display_diffs( - id => "Crabtree Tavern", - version => 1, - other_version => 2, - return_output => 1, - ); -}; -is( $@, "", - "->display_diffs doesn't die when called on a node with RSS feeds in" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Calthorpe Arms", - content => '@INDEX_LIST [[Category Foo]]', - ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Calthorpe Arms", - content => '@INDEX_LIST [[Category Foo]]', - ); -$output = eval { - $guide->display_diffs( - id => "Calthorpe Arms", - version => 1, - other_version => 2, - return_output => 1, - ); -}; -is( $@, "", - "...or on a node with INDEX_LIST in" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Penderel's Oak", - content => '@INDEX_LINK [[Category Foo]]', - ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Penderel's Oak", - content => '@INDEX_LINK [[Category Foo]]', - ); -$output = eval { - $guide->display_diffs( - id => "Penderel's Oak", - version => 1, - other_version => 2, - return_output => 1, - ); -}; -is( $@, "", - "...or on a node with INDEX_LINK in" ); -like( $output, qr|view all pages in category foo|i, - "...and index link is correct" ); - - -__DATA__ -<?xml version="1.0" encoding="UTF-8"?> - -<rdf:RDF - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns="http://purl.org/rss/1.0/" - xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" - xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/" - xmlns:admin="http://webns.net/mvcb/" -> - -<channel rdf:about="http://london.openguides.org/kakemirror/?RecentChanges"> -<title>The Open Guide to London - Kake's Mirror</title> -<link>http://london.openguides.org/kakemirror/?RecentChanges</link> -<description></description> -dc:date2004-12-14T12:59:42</dc:date> -wiki:interwiki</wiki:interwiki> -<items> - rdf:Seq - <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers..." /> - <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers..." /> - <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=..." /> - <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=..." /> - <rdf:li rdf:resource="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=..." /> - </rdf:Seq> -</items> -</channel> - -<item rdf:about="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;version=9"> -<title>Buckingham Arms, SW1H 9EU</title> -<link>http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers...</link> -<description>extraneous : [bob]</description> -dc:date2004-12-12T13:25:27</dc:date> -dc:contributorbob</dc:contributor> -wiki:history</wiki:history> -wiki:importanceminor</wiki:importance> -wiki:version9</wiki:version> -wiki:statusupdated</wiki:status> -wiki:diff</wiki:diff> -</item> - -<item rdf:about="http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;version=8"> -<title>Buckingham Arms, SW1H 9EU</title> -<link>http://london.openguides.org/kakemirror/?id=Buckingham_Arms%2C_SW1H_9EU;vers...</link> -<description> [Martin]</description> -dc:date2004-12-11T14:05:38</dc:date> -dc:contributorMartin</dc:contributor> -wiki:history</wiki:history> -wiki:importancemajor</wiki:importance> -wiki:version8</wiki:version> -wiki:statusupdated</wiki:status> -wiki:diff</wiki:diff> -</item> - -<item rdf:about="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=14"> -<title>Star Tavern, SW1X 8HT</title> -<link>http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=...</link> -<description>De-bobbed the bob bits. [Kake]</description> -dc:date2004-12-10T14:29:13</dc:date> -dc:contributorKake</dc:contributor> -wiki:history</wiki:history> -wiki:importanceminor</wiki:importance> -wiki:version14</wiki:version> -wiki:statusupdated</wiki:status> -wiki:diff</wiki:diff> -</item> - -<item rdf:about="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=13"> -<title>Star Tavern, SW1X 8HT</title> -<link>http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=...</link> -<description>More comments. [Kake]</description> -dc:date2004-12-10T14:27:41</dc:date> -dc:contributorKake</dc:contributor> -wiki:history</wiki:history> -wiki:importancemajor</wiki:importance> -wiki:version13</wiki:version> -wiki:statusupdated</wiki:status> -wiki:diff</wiki:diff> -</item> - -<item rdf:about="http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=12"> -<title>Star Tavern, SW1X 8HT</title> -<link>http://london.openguides.org/kakemirror/?id=Star_Tavern%2C_SW1X_8HT;version=...</link> -<description>updated [bob]</description> -dc:date2004-12-10T14:18:51</dc:date> -dc:contributorbob</dc:contributor> -wiki:history</wiki:history> -wiki:importanceminor</wiki:importance> -wiki:version12</wiki:version> -wiki:statusupdated</wiki:status> -wiki:diff</wiki:diff> -</item> - -</rdf:RDF>
Deleted: trunk/t/57_random_page.t =================================================================== --- trunk/t/57_random_page.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/57_random_page.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,157 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Test; -use OpenGuides; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 8; - -my ( $config, $guide, $wiki ); - -# Clear out database from previous runs, set up a guide. - OpenGuides::Test::refresh_db(); - -$config = OpenGuides::Test->make_basic_config; -$config->script_url( "http://www.example.com/" ); -$config->script_name( "wiki.cgi" ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; - -# Write some data. -my %nodes = map { $_ => "A pub." } ( "Red Lion", "Farmers Arms", "Angel" ); -foreach my $node ( keys %nodes ) { - OpenGuides::Test->write_data( - guide => $guide, - node => $node, - return_output => 1, - ); -} - -# See what we get when we ask for a random page. -my $output = $guide->display_random_page( return_output => 1 ); - -# Old versions of CGI.pm mistakenly print location: instead of Location: -like( $output, qr/[lL]ocation: http://www.example.com/wiki.cgi/, - "->display_random_page makes a redirect" ); - -my $node = get_node_from_output( $output ); -print "# Random node chosen: $node\n"; -ok( $nodes{$node}, "...to an existing node" ); - -# Clear the database and write some data including categories and locales. - OpenGuides::Test::refresh_db(); - -$config = OpenGuides::Test->make_basic_config; -$config->script_url( "http://www.example.com/" ); -$config->script_name( "wiki.cgi" ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; - -# Write data including some categories/locales. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - locales => "Hammersmith", - categories => "Pubs", - return_output => 1, - ); - -# Check we can turn off locales. -$config = OpenGuides::Test->make_basic_config; -$config->script_url( "http://www.example.com/" ); -$config->script_name( "wiki.cgi" ); -$config->random_page_omits_locales( 1 ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; -$output = $guide->display_random_page( return_output => 1 ); -$node = get_node_from_output( $output ); -print "# Random node chosen: $node\n"; -isnt( $node, "Locale Hammersmith", "locale nodes not picked up as random page " - . "(this test may sometimes pass when it shouldn't)" ); - -# Check we can turn off categories. -$config = OpenGuides::Test->make_basic_config; -$config->script_url( "http://www.example.com/" ); -$config->script_name( "wiki.cgi" ); -$config->random_page_omits_categories( 1 ); -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; -$output = $guide->display_random_page( return_output => 1 ); -$node = get_node_from_output( $output ); -print "# Random node chosen: $node\n"; -isnt( $node, "Category Pubs", "category nodes not picked up as random page " - . "(this test may sometimes pass when it shouldn't)" ); - -# Now make sure we can pick things up from specific categories/locales if asked - OpenGuides::Test::refresh_db(); - -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - locales => "Hammersmith", - categories => "Pubs", - return_output => 1, - ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Poppy Hana", - locales => "Bermondsey", - categories => "Restaurants", - return_output => 1, - ); -$output = $guide->display_random_page( category => "Pubs", - return_output => 1 ); -$node = get_node_from_output( $output ); -print "# Random node chosen: $node\n"; -is( $node, "Red Lion", "can ask for a random pub " - . "(this test may sometimes pass when it shouldn't)" ); - -$output = $guide->display_random_page( locale => "Bermondsey", - return_output => 1 ); -$node = get_node_from_output( $output ); -print "# Random node chosen: $node\n"; -is( $node, "Poppy Hana", "can ask for a random thing in Bermondsey " - . "(this test may sometimes pass when it shouldn't)" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Stanley Arms", - locales => "Bermondsey", - categories => "Pubs", - return_output => 1, - ); -$output = $guide->display_random_page( locale => "Bermondsey", - category => "Pubs", - return_output => 1 - ); -$node = get_node_from_output( $output ); -print "# Random node chosen: $node\n"; -is( $node, "Stanley Arms", "can ask for a random pub in Bermondsey " - . "(this test may sometimes pass when it shouldn't)" ); - - -$output = $guide->display_random_page( locale => "Islington", - category => "Cinemas", - return_output => 1 - ); -unlike( $output, qr/Status: 302/, - "don't get a redirect if we ask for category/locale with no pages in" ); - - -sub get_node_from_output { - my $node_param = shift; - $node_param =~ s/^.*?//s; - $node_param =~ s/\s+$//; - my $formatter = $guide->wiki->formatter; - my $node = $formatter->node_param_to_node_name( $node_param ); - return $node; -}
Deleted: trunk/t/58_navbar_common_locales_categories.t =================================================================== --- trunk/t/58_navbar_common_locales_categories.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/58_navbar_common_locales_categories.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,72 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - plan skip_all => "DBD::SQLite not installed - no database to test with"; - exit 0; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; - exit 0; -} - -sub get_recent_changes { - my ($guide) = @_; - - my $output = $guide->display_recent_changes( return_output => 1 ); - $output =~ s/^Content-Type.*[\r\n]+//m; - - return $output; -} - -sub get_preferences { - my $guide = shift; - return $guide->display_prefs_form( return_output => 1, noheaders => 1 ); -} - -my %pages = ( - recent_changes => &get_recent_changes, - preferences => &get_preferences, -); - -plan tests => 4 * keys %pages; - -my ( $config, $guide, $wiki, $output ); - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -while (my ($page, $get_content) = each %pages) { - - # Make a guide with common categories and locales enabled. - $config = OpenGuides::Test->make_basic_config; - $config->enable_common_categories( 1 ); - $config->enable_common_locales( 1 ); - $guide = OpenGuides->new( config => $config ); - - # Make sure common categories and locales show up. - $output = $get_content->($guide); - - Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_categories" }, - "common categories in $page navbar" ); - Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_locales" }, - "...common locales too" ); - - # Now make a guide with common categories and locales disabled. - $config = OpenGuides::Test->make_basic_config; - $guide = OpenGuides->new( config => $config ); - - # Make sure common categories/locales are omitted. - $output = $get_content->($guide); - - Test::HTML::Content::no_tag( $output, "div", { id => "navbar_categories" }, - "common categories in $page navbar" ); - Test::HTML::Content::no_tag( $output, "div", { id => "navbar_locales" }, - "...common locales too" ); -}
Deleted: trunk/t/59_preferences.t =================================================================== --- trunk/t/59_preferences.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/59_preferences.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,150 +0,0 @@ -use strict; -use JSON; -use OpenGuides; -use OpenGuides::JSON; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; - exit 0; -} - -plan tests => 17; - -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Make sure "return_to" TT var is set iff referrer domain is correct. -$config->script_url( "http://example.com/" ); -$config->script_name( "wiki.cgi" ); -my $good_return_to = "http://example.com/wiki.cgi?Test_Page"; -my $evil_return_to = "http://example.org/naughty-script"; - -$ENV{HTTP_REFERER} = $good_return_to; -my %tt_vars = $guide->display_prefs_form( return_tt_vars => 1 ); -is( $tt_vars{return_to_url}, $good_return_to, - "Return URL set when referrer matches script URL/name" ); -my $output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); -Test::HTML::Content::tag_ok( $output, - "input", { type => "hidden", name => "return_to_url" }, - "...corresponding hidden input is there in the form" ); -Test::HTML::Content::tag_ok( $output, - "input", { type => "hidden", name => "return_to_url", - value => $good_return_to }, - "...with correct value" ); - -$ENV{HTTP_REFERER} = $evil_return_to; -%tt_vars = $guide->display_prefs_form( return_tt_vars => 1 ); -ok( !$tt_vars{return_to_url}, - "Return URL not set when referrer doesn't match script URL/name" ); -$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); -Test::HTML::Content::no_tag( $output, - "input", { type => "hidden", name => "return_to_url" }, - "...and no corresponding hidden input in form" ); - -# If we have a google API key and node maps are enabled, we should see the -# checkbox for this pref. -$config->gmaps_api_key( "This is not a real API key." ); -$config->show_gmap_in_node_display( 1 ); - -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - display_google_maps => 1, - ); -$ENV{HTTP_COOKIE} = $cookie; -$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); -Test::HTML::Content::tag_ok( $output, - "input", { type => "checkbox", name => "display_google_maps" }, - "Node map preference checkbox shown when we have a GMaps API key." ); - -# But not if the node map is globally disabled -$config->show_gmap_in_node_display( 0 ); -$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); -Test::HTML::Content::no_tag( $output, - "input", { type => "checkbox", name => "display_google_maps" }, - "...but not when node maps are globally disabled." ); - -# Now test with Leaflet enabled and no Google API key. -$config->gmaps_api_key( "" ); -$config->show_gmap_in_node_display( 1 ); -$config->use_leaflet( 1 ); - -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - display_google_maps => 1, - ); -$ENV{HTTP_COOKIE} = $cookie; -$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); -Test::HTML::Content::tag_ok( $output, - "input", { type => "checkbox", name => "display_google_maps" }, - "Node map preference checkbox shown when we're using Leaflet." ); - -$config->show_gmap_in_node_display( 0 ); -$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 ); -Test::HTML::Content::no_tag( $output, - "input", { type => "checkbox", name => "display_google_maps" }, - "...but not when node maps are globally disabled." ); - -# Test JSON version of prefs page. -my $json_writer = OpenGuides::JSON->new( wiki => $wiki, - config => $config ); -delete $ENV{HTTP_COOKIE}; -$output = eval { - $json_writer->make_prefs_json(); -}; -ok( !$@, "->make_prefs_json() doesn't die when no cookie set." ); -if ( $@ ) { warn "# Error was: $@"; } -# Need to strip out the Content-Type: header or the decoder gets confused. -$output =~ s/^Content-Type:.*\n//s; -my $parsed = eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - decode_json( $output ); -}; -ok( !$@, "...and its output looks like JSON." ); -if ( $@ ) { warn "# Warning was: $@"; } -ok( $parsed->{username}, "...and a username is included in the output" ); -#use Data::Dumper; print Dumper $parsed; exit 0; - -$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( config => $config ); -$output = eval { - $json_writer->make_prefs_json(); -}; -ok( !$@, "->make_prefs_json() doesn't die when cookie set with all defaults."); -if ( $@ ) { warn "# Error was: $@"; } -$output =~ s/^Content-Type:.*\n//s; -$parsed = eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - decode_json( $output ); -}; -ok( !$@, "...and its output looks like JSON." ); -if ( $@ ) { warn "# Warning was: $@"; } -# We don't get a username set in this case. - -$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( config => $config, - username => "Kake" ); -$output = eval { - $json_writer->make_prefs_json(); -}; -ok( !$@, - "->make_prefs_json() doesn't die when cookie set with given username."); -if ( $@ ) { warn "# Error was: $@"; } -$output =~ s/^Content-Type:.*\n//s; -$parsed = eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - decode_json( $output ); -}; -ok( !$@, "...and its output looks like JSON." ); -if ( $@ ) { warn "# Warning was: $@"; } -is( $parsed->{username}, "Kake", - "...and the correct username is included in the output" );
Copied: trunk/t/601_bug_textareas.t (from rev 1381, trunk/t/61_bug_textareas.t) =================================================================== --- trunk/t/601_bug_textareas.t (rev 0) +++ trunk/t/601_bug_textareas.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,35 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Template; +use OpenGuides::Test; +use OpenGuides::Utils; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 1; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + +my $out = OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "edit_form.tt", + vars => { + locales => [ + { name => "Barville" }, + { name => "Fooville" }, + ], + }, +); + +like( $out, qr/Barville\nFooville/, + "locales properly separated in textarea" );
Copied: trunk/t/602_bug_trailing_whitespace.t (from rev 1381, trunk/t/62_bug_trailing_whitespace.t) =================================================================== --- trunk/t/602_bug_trailing_whitespace.t (rev 0) +++ trunk/t/602_bug_trailing_whitespace.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,88 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Template; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 8; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); + + my $q = CGI->new( "" ); + $q->param( -name => "os_x", -value => " 123456 " ); + $q->param( -name => "os_y", -value => " 654321 " ); + $q->param( -name => "categories", -value => "" ); #avoid uninit val warning + $q->param( -name => "locales", -value => "" ); #avoid uninit val warning + + my %metadata_vars = OpenGuides::Template->extract_metadata_vars( + wiki => $guide->wiki, + config => $config, + cgi_obj => $q, + ); + + is( $metadata_vars{os_x}, "123456", + "leading and trailing spaces stripped from os_x when processed" ); + is( $metadata_vars{os_y}, "654321", "...and os_y" ); + + + + $config->geo_handler( 2 ); + $q = CGI->new( "" ); + $q->param( -name => "osie_x", -value => " 100000 " ); + $q->param( -name => "osie_y", -value => " 200000 " ); + $q->param( -name => "categories", -value => "" ); #avoid uninit val warning + $q->param( -name => "locales", -value => "" ); #avoid uninit val warning + + %metadata_vars = OpenGuides::Template->extract_metadata_vars( + wiki => $guide->wiki, + config => $config, + cgi_obj => $q, + ); + + is( $metadata_vars{osie_x}, "100000", + "leading and trailing spaces stripped from osie_x when processed" ); + is( $metadata_vars{osie_y}, "200000", "...and osie_y" ); + + $config->geo_handler( 3 ); + $q = CGI->new( "" ); + $q->param( -name => "latitude", -value => " 1.463113 " ); + $q->param( -name => "longitude", -value => " -0.215293 " ); + $q->param( -name => "categories", -value => "" ); #avoid uninit val warning + $q->param( -name => "locales", -value => "" ); #avoid uninit val warning + + %metadata_vars = OpenGuides::Template->extract_metadata_vars( + wiki => $guide->wiki, + config => $config, + cgi_obj => $q, + ); + + is( $metadata_vars{latitude}, "1.463113", + "leading and trailing spaces stripped from latitude when processed" ); + is( $metadata_vars{longitude}, "-0.215293", "...and longitude" ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "A Node", + categories => " Food \r\n Live Music ", + locales => " Hammersmith \r\n Fulham ", +); +my %node = $guide->wiki->retrieve_node( "A Node" ); +my %data = %{ $node{metadata} }; +my @cats = sort @{ $data{category} || [] }; +is_deeply( @cats, [ "Food", "Live Music" ], + "leading and trailing spaces stripped from all categories when stored" ); +my @locs = sort @{ $data{locale} || [] }; +is_deeply( @locs, [ "Fulham", "Hammersmith" ], "...and all locales" );
Copied: trunk/t/603_bug_map_link_no_address.t (from rev 1381, trunk/t/63_bug_map_link_no_address.t) =================================================================== --- trunk/t/603_bug_map_link_no_address.t (rev 0) +++ trunk/t/603_bug_map_link_no_address.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,28 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 1; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); + +$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"; + +my $output = $guide->display_node( + id => "South Croydon Station", + return_output => 1, + ); +like( $output, qr/Map of this place/, "map link included when no address" ); +
Copied: trunk/t/604_bug_node_history.t (from rev 1381, trunk/t/64_bug_node_history.t) =================================================================== --- trunk/t/604_bug_node_history.t (rev 0) +++ trunk/t/604_bug_node_history.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,44 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use Cwd; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 1; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_url => "http://wiki.example.com/", + script_name => "mywiki.cgi", + site_name => "Wiki::Toolkit Test Site", + template_path => cwd . "/templates", + } +); +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene ( 0 ) }; + +my $guide = OpenGuides->new( config => $config ); + +$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"; +my %data = $guide->wiki->retrieve_node( "South Croydon Station" ); +$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"; + +my $output = $guide->list_all_versions( + id => "South Croydon Station", + return_output => 1, + ); +unlike( $output, qr'<myfaketag>', "HTML escaped in comments" );
Copied: trunk/t/605_bug_metadata_escape.t (from rev 1381, trunk/t/65_bug_metadata_escape.t) =================================================================== --- trunk/t/605_bug_metadata_escape.t (rev 0) +++ trunk/t/605_bug_metadata_escape.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,42 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use Cwd; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 1; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_url => "http://wiki.example.com/", + script_name => "mywiki.cgi", + site_name => "Wiki::Toolkit Test Site", + template_path => cwd . "/templates", + } +); +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene ( 0 ) }; + +my $guide = OpenGuides->new( config => $config ); + +$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"; + +my $output = $guide->display_node( + id => "South Croydon Station", + return_output => 1, + ); +unlike( $output, qr'<hr><h1>hello mum</h1><hr>', + "HTML escaped in metadata on node display" );
Copied: trunk/t/606_bug_latlong_representation.t (from rev 1381, trunk/t/66_bug_latlong_representation.t) =================================================================== --- trunk/t/606_bug_latlong_representation.t (rev 0) +++ trunk/t/606_bug_latlong_representation.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,95 @@ +use strict; +use CGI; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::CGI; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + + +plan tests => 4; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + geo_handler => 3, # Test w/ UTM - nat grids use X/Y + ellipsoid => "Airy", + } +); + +# Plucene is the recommended searcher now. +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene( 0 ) }; + +my $guide = OpenGuides->new( config => $config ); + +# Set preferences to have lat/long displayed in deg/min/sec. +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "Kake", + include_geocache_link => 1, + preview_above_edit_box => 1, + latlong_traditional => 1, # this is the important bit + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, +); +$ENV{HTTP_COOKIE} = $cookie; + +OpenGuides::Test->write_data( + guide => $guide, + node => "Test Page", + latitude => 51.368, + longitude => -0.0973, + ); + +my %data = $guide->wiki->retrieve_node( "Test Page" ); +my $lat = $data{metadata}{latitude}[0]; +unlike( $lat, qr/d/, + "lat not stored in dms format even if prefs set to display that way" ); + +# Check the distance search form has unmunged lat/long. +my $output = $guide->display_node( + return_output => 1, + id => "Test Page", + ); +unlike( $output, qr/name="latitude"\svalue="[-0-9]*d/, + "latitude in non-dms format in distance search form" ); + +# Now write a node with no location data, and check that it doesn't +# claim to have any when we display it. +eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + OpenGuides::Test->write_data( + guide => $guide, + node => "Locationless Page", + ); +}; +is( $@, "", + "commit doesn't warn when prefs say dms format and node has no loc data" ); + +$output = $guide->display_node( + return_output => 1, + id => "Locationless Page", + ); +unlike( $output, qr/latitude:/i, + "node with no location data doesn't display a latitude" );
Copied: trunk/t/607_bug_first_version.t (from rev 1381, trunk/t/67_bug_first_version.t) =================================================================== --- trunk/t/607_bug_first_version.t (rev 0) +++ trunk/t/607_bug_first_version.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,38 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Template; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 3; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "A Node", +); + +# Test that we can list all versions of a node that only has one version. +eval { $guide->list_all_versions( id => "A Node", return_output => 1 ); }; +is( $@, "", "->list_all_versions doesn't croak when only one version" ); + +# Test that node with only one version doesn't display diff link. +my $output = $guide->display_node( id => "A Node", return_output => 1 ); +unlike( $output, qr|<a href=".*">diff</a>|, + "no diff link displayed on node with only one version" ); +unlike( $output, qr|<a href=".*">View current version.</a>|i, + "...nor view current version link" );
Copied: trunk/t/608_bug_website_displayed.t (from rev 1381, trunk/t/68_bug_website_displayed.t) =================================================================== --- trunk/t/608_bug_website_displayed.t (rev 0) +++ trunk/t/608_bug_website_displayed.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,79 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 7; + +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); + +$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { website => "http://example.com/" } ) or die "Couldn't write node"; +$guide->wiki->write_node( "North Croydon Station", "A busy main-line station in what is arguably the furthest North part of Croydon.", undef, { website => "http://longer.example.com/asdfasdf" } ) or die "Couldn't write node"; +$guide->wiki->write_node( "East Croydon Station", + "A busy main-line station that actually exists.", undef, + { website => "http://www.example.com/foo" } ) + or die "Couldn't write node"; +$guide->wiki->write_node( "West Croydon Station", + "Another main-line station that actually exists.", undef, + { website => "http://www.example.com/bar/" } ) + or die "Couldn't write node"; + +$config->website_link_max_chars( 20 ); +my %tt_vars = $guide->display_node( id => "South Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, + '<a href="http://example.com/">example.com</a>', + "Website correctly displayed when no need for truncation," ); + +%tt_vars = $guide->display_node( id => "East Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, + '<a href="http://www.example.com/foo">example.com/foo</a>', + "Website correctly truncated when there's a leading www" ); + +%tt_vars = $guide->display_node( id => "West Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, + '<a href="http://www.example.com/bar/">example.com/bar/</a>', + "Trailing slash not stripped unless it's immediately after domain name" ); + +%tt_vars = $guide->display_node( id => "North Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, + '<a href="http://longer.example.com/asdfasdf">longer.example.co...</a>', + "Website correctly truncated when much too long." ); + +# Make sure website isn't truncated unnecessarily, e.g. that we don't end up +# just replacing the final three characters with the ellipsis. Our full URL +# has 27 characters (not counting the http://). +$config->website_link_max_chars( 26 ); +%tt_vars = $guide->display_node( id => "North Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, + '<a href="http://longer.example.com/asdfasdf">longer.example.com/asdf...</a>', + "Website truncated correctly when 1 character longer than allowed." ); + +$config->website_link_max_chars( 27 ); +%tt_vars = $guide->display_node( id => "North Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, +'<a href="http://longer.example.com/asdfasdf">longer.example.com/asdfasdf</a>', + "Website not truncated when exact length allowed." ); + +$config->website_link_max_chars( 28 ); +%tt_vars = $guide->display_node( id => "North Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, +'<a href="http://longer.example.com/asdfasdf">longer.example.com/asdfasdf</a>', + "Website not truncated when 1 character shorter than allowed." );
Copied: trunk/t/609_bug_zero_geo.t (from rev 1381, trunk/t/69_bug_zero_geo.t) =================================================================== --- trunk/t/609_bug_zero_geo.t (rev 0) +++ trunk/t/609_bug_zero_geo.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,100 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use Cwd; +use OpenGuides; +use Test::More; +use OpenGuides::Test; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 6; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_url => "http://wiki.example.com/", + script_name => "mywiki.cgi", + site_name => "Wiki::Toolkit Test Site", + template_path => cwd . "/templates", + } +); +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { $config->use_plucene ( 0 ) }; + +$config->{geo_handler} = 1; + +my $guide = OpenGuides->new( config => $config ); + +my $q = OpenGuides::Test->make_cgi_object( + content => "Blah", + os_x => 0, + os_y => 0 +); + +my $output = $guide->commit_node( + id => "Test Node", + cgi_obj => $q, + return_output => 1 +); + +my %details = $guide->wiki->retrieve_node("Test Node"); + +is( @{$details{metadata}->{os_x}}[0], 0, "Zero os_x saved" ); +is( @{$details{metadata}->{os_y}}[0], 0, "Zero os_y saved" ); + +$config->{geo_handler} = 2; + +Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + +$guide = OpenGuides->new( config => $config ); + +$q = OpenGuides::Test->make_cgi_object( + content => "Blah", + osie_x => 0, + osie_y => 0 +); + +$output = $guide->commit_node( + id => "Test Node IE", + cgi_obj => $q, + return_output => 1 +); + +%details = $guide->wiki->retrieve_node("Test Node IE"); + +is( @{$details{metadata}->{osie_x}}[0], 0, "Zero osie_x saved" ); +is( @{$details{metadata}->{osie_y}}[0], 0, "Zero osie_y saved" ); +$config->{geo_handler} = 3; + +Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + +$guide = OpenGuides->new( config => $config ); + +$q = OpenGuides::Test->make_cgi_object( + content => "Blah", + latitude => 0, + longitude => 0 +); + +$output = $guide->commit_node( + id => "Test Node lat/long", + cgi_obj => $q, + return_output => 1 +); + +%details = $guide->wiki->retrieve_node("Test Node lat/long"); + +is( @{$details{metadata}->{latitude}}[0], 0, "Zero latitude saved" ); +is( @{$details{metadata}->{longitude}}[0], 0, "Zero longitude saved" ); +
Deleted: trunk/t/61_bug_textareas.t =================================================================== --- trunk/t/61_bug_textareas.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/61_bug_textareas.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,35 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Template; -use OpenGuides::Test; -use OpenGuides::Utils; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 1; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - -my $out = OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "edit_form.tt", - vars => { - locales => [ - { name => "Barville" }, - { name => "Fooville" }, - ], - }, -); - -like( $out, qr/Barville\nFooville/, - "locales properly separated in textarea" );
Deleted: trunk/t/62_bug_trailing_whitespace.t =================================================================== --- trunk/t/62_bug_trailing_whitespace.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/62_bug_trailing_whitespace.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,88 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Template; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 8; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); - - my $q = CGI->new( "" ); - $q->param( -name => "os_x", -value => " 123456 " ); - $q->param( -name => "os_y", -value => " 654321 " ); - $q->param( -name => "categories", -value => "" ); #avoid uninit val warning - $q->param( -name => "locales", -value => "" ); #avoid uninit val warning - - my %metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $guide->wiki, - config => $config, - cgi_obj => $q, - ); - - is( $metadata_vars{os_x}, "123456", - "leading and trailing spaces stripped from os_x when processed" ); - is( $metadata_vars{os_y}, "654321", "...and os_y" ); - - - - $config->geo_handler( 2 ); - $q = CGI->new( "" ); - $q->param( -name => "osie_x", -value => " 100000 " ); - $q->param( -name => "osie_y", -value => " 200000 " ); - $q->param( -name => "categories", -value => "" ); #avoid uninit val warning - $q->param( -name => "locales", -value => "" ); #avoid uninit val warning - - %metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $guide->wiki, - config => $config, - cgi_obj => $q, - ); - - is( $metadata_vars{osie_x}, "100000", - "leading and trailing spaces stripped from osie_x when processed" ); - is( $metadata_vars{osie_y}, "200000", "...and osie_y" ); - - $config->geo_handler( 3 ); - $q = CGI->new( "" ); - $q->param( -name => "latitude", -value => " 1.463113 " ); - $q->param( -name => "longitude", -value => " -0.215293 " ); - $q->param( -name => "categories", -value => "" ); #avoid uninit val warning - $q->param( -name => "locales", -value => "" ); #avoid uninit val warning - - %metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $guide->wiki, - config => $config, - cgi_obj => $q, - ); - - is( $metadata_vars{latitude}, "1.463113", - "leading and trailing spaces stripped from latitude when processed" ); - is( $metadata_vars{longitude}, "-0.215293", "...and longitude" ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "A Node", - categories => " Food \r\n Live Music ", - locales => " Hammersmith \r\n Fulham ", -); -my %node = $guide->wiki->retrieve_node( "A Node" ); -my %data = %{ $node{metadata} }; -my @cats = sort @{ $data{category} || [] }; -is_deeply( @cats, [ "Food", "Live Music" ], - "leading and trailing spaces stripped from all categories when stored" ); -my @locs = sort @{ $data{locale} || [] }; -is_deeply( @locs, [ "Fulham", "Hammersmith" ], "...and all locales" );
Deleted: trunk/t/63_bug_map_link_no_address.t =================================================================== --- trunk/t/63_bug_map_link_no_address.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/63_bug_map_link_no_address.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,28 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 1; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); - -$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"; - -my $output = $guide->display_node( - id => "South Croydon Station", - return_output => 1, - ); -like( $output, qr/Map of this place/, "map link included when no address" ); -
Deleted: trunk/t/64_bug_node_history.t =================================================================== --- trunk/t/64_bug_node_history.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/64_bug_node_history.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,44 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use Cwd; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 1; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_url => "http://wiki.example.com/", - script_name => "mywiki.cgi", - site_name => "Wiki::Toolkit Test Site", - template_path => cwd . "/templates", - } -); -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene ( 0 ) }; - -my $guide = OpenGuides->new( config => $config ); - -$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"; -my %data = $guide->wiki->retrieve_node( "South Croydon Station" ); -$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"; - -my $output = $guide->list_all_versions( - id => "South Croydon Station", - return_output => 1, - ); -unlike( $output, qr'<myfaketag>', "HTML escaped in comments" );
Deleted: trunk/t/65_bug_metadata_escape.t =================================================================== --- trunk/t/65_bug_metadata_escape.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/65_bug_metadata_escape.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,42 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use Cwd; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 1; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_url => "http://wiki.example.com/", - script_name => "mywiki.cgi", - site_name => "Wiki::Toolkit Test Site", - template_path => cwd . "/templates", - } -); -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene ( 0 ) }; - -my $guide = OpenGuides->new( config => $config ); - -$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"; - -my $output = $guide->display_node( - id => "South Croydon Station", - return_output => 1, - ); -unlike( $output, qr'<hr><h1>hello mum</h1><hr>', - "HTML escaped in metadata on node display" );
Deleted: trunk/t/66_bug_latlong_representation.t =================================================================== --- trunk/t/66_bug_latlong_representation.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/66_bug_latlong_representation.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,95 +0,0 @@ -use strict; -use CGI; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::CGI; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - - -plan tests => 4; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - geo_handler => 3, # Test w/ UTM - nat grids use X/Y - ellipsoid => "Airy", - } -); - -# Plucene is the recommended searcher now. -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene( 0 ) }; - -my $guide = OpenGuides->new( config => $config ); - -# Set preferences to have lat/long displayed in deg/min/sec. -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "Kake", - include_geocache_link => 1, - preview_above_edit_box => 1, - latlong_traditional => 1, # this is the important bit - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, -); -$ENV{HTTP_COOKIE} = $cookie; - -OpenGuides::Test->write_data( - guide => $guide, - node => "Test Page", - latitude => 51.368, - longitude => -0.0973, - ); - -my %data = $guide->wiki->retrieve_node( "Test Page" ); -my $lat = $data{metadata}{latitude}[0]; -unlike( $lat, qr/d/, - "lat not stored in dms format even if prefs set to display that way" ); - -# Check the distance search form has unmunged lat/long. -my $output = $guide->display_node( - return_output => 1, - id => "Test Page", - ); -unlike( $output, qr/name="latitude"\svalue="[-0-9]*d/, - "latitude in non-dms format in distance search form" ); - -# Now write a node with no location data, and check that it doesn't -# claim to have any when we display it. -eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - OpenGuides::Test->write_data( - guide => $guide, - node => "Locationless Page", - ); -}; -is( $@, "", - "commit doesn't warn when prefs say dms format and node has no loc data" ); - -$output = $guide->display_node( - return_output => 1, - id => "Locationless Page", - ); -unlike( $output, qr/latitude:/i, - "node with no location data doesn't display a latitude" );
Deleted: trunk/t/67_bug_first_version.t =================================================================== --- trunk/t/67_bug_first_version.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/67_bug_first_version.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,38 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Template; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 3; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "A Node", -); - -# Test that we can list all versions of a node that only has one version. -eval { $guide->list_all_versions( id => "A Node", return_output => 1 ); }; -is( $@, "", "->list_all_versions doesn't croak when only one version" ); - -# Test that node with only one version doesn't display diff link. -my $output = $guide->display_node( id => "A Node", return_output => 1 ); -unlike( $output, qr|<a href=".*">diff</a>|, - "no diff link displayed on node with only one version" ); -unlike( $output, qr|<a href=".*">View current version.</a>|i, - "...nor view current version link" );
Deleted: trunk/t/68_bug_website_displayed.t =================================================================== --- trunk/t/68_bug_website_displayed.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/68_bug_website_displayed.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,79 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 7; - -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); - -$guide->wiki->write_node( "South Croydon Station", "A sleepy main-line station in what is arguably the nicest part of Croydon.", undef, { website => "http://example.com/" } ) or die "Couldn't write node"; -$guide->wiki->write_node( "North Croydon Station", "A busy main-line station in what is arguably the furthest North part of Croydon.", undef, { website => "http://longer.example.com/asdfasdf" } ) or die "Couldn't write node"; -$guide->wiki->write_node( "East Croydon Station", - "A busy main-line station that actually exists.", undef, - { website => "http://www.example.com/foo" } ) - or die "Couldn't write node"; -$guide->wiki->write_node( "West Croydon Station", - "Another main-line station that actually exists.", undef, - { website => "http://www.example.com/bar/" } ) - or die "Couldn't write node"; - -$config->website_link_max_chars( 20 ); -my %tt_vars = $guide->display_node( id => "South Croydon Station", - return_tt_vars => 1 ); -is( $tt_vars{formatted_website_text}, - '<a href="http://example.com/">example.com</a>', - "Website correctly displayed when no need for truncation," ); - -%tt_vars = $guide->display_node( id => "East Croydon Station", - return_tt_vars => 1 ); -is( $tt_vars{formatted_website_text}, - '<a href="http://www.example.com/foo">example.com/foo</a>', - "Website correctly truncated when there's a leading www" ); - -%tt_vars = $guide->display_node( id => "West Croydon Station", - return_tt_vars => 1 ); -is( $tt_vars{formatted_website_text}, - '<a href="http://www.example.com/bar/">example.com/bar/</a>', - "Trailing slash not stripped unless it's immediately after domain name" ); - -%tt_vars = $guide->display_node( id => "North Croydon Station", - return_tt_vars => 1 ); -is( $tt_vars{formatted_website_text}, - '<a href="http://longer.example.com/asdfasdf">longer.example.co...</a>', - "Website correctly truncated when much too long." ); - -# Make sure website isn't truncated unnecessarily, e.g. that we don't end up -# just replacing the final three characters with the ellipsis. Our full URL -# has 27 characters (not counting the http://). -$config->website_link_max_chars( 26 ); -%tt_vars = $guide->display_node( id => "North Croydon Station", - return_tt_vars => 1 ); -is( $tt_vars{formatted_website_text}, - '<a href="http://longer.example.com/asdfasdf">longer.example.com/asdf...</a>', - "Website truncated correctly when 1 character longer than allowed." ); - -$config->website_link_max_chars( 27 ); -%tt_vars = $guide->display_node( id => "North Croydon Station", - return_tt_vars => 1 ); -is( $tt_vars{formatted_website_text}, -'<a href="http://longer.example.com/asdfasdf">longer.example.com/asdfasdf</a>', - "Website not truncated when exact length allowed." ); - -$config->website_link_max_chars( 28 ); -%tt_vars = $guide->display_node( id => "North Croydon Station", - return_tt_vars => 1 ); -is( $tt_vars{formatted_website_text}, -'<a href="http://longer.example.com/asdfasdf">longer.example.com/asdfasdf</a>', - "Website not truncated when 1 character shorter than allowed." );
Deleted: trunk/t/69_bug_zero_geo.t =================================================================== --- trunk/t/69_bug_zero_geo.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/69_bug_zero_geo.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,100 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use Cwd; -use OpenGuides; -use Test::More; -use OpenGuides::Test; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 6; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_url => "http://wiki.example.com/", - script_name => "mywiki.cgi", - site_name => "Wiki::Toolkit Test Site", - template_path => cwd . "/templates", - } -); -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { $config->use_plucene ( 0 ) }; - -$config->{geo_handler} = 1; - -my $guide = OpenGuides->new( config => $config ); - -my $q = OpenGuides::Test->make_cgi_object( - content => "Blah", - os_x => 0, - os_y => 0 -); - -my $output = $guide->commit_node( - id => "Test Node", - cgi_obj => $q, - return_output => 1 -); - -my %details = $guide->wiki->retrieve_node("Test Node"); - -is( @{$details{metadata}->{os_x}}[0], 0, "Zero os_x saved" ); -is( @{$details{metadata}->{os_y}}[0], 0, "Zero os_y saved" ); - -$config->{geo_handler} = 2; - -Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); -Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); - -$guide = OpenGuides->new( config => $config ); - -$q = OpenGuides::Test->make_cgi_object( - content => "Blah", - osie_x => 0, - osie_y => 0 -); - -$output = $guide->commit_node( - id => "Test Node IE", - cgi_obj => $q, - return_output => 1 -); - -%details = $guide->wiki->retrieve_node("Test Node IE"); - -is( @{$details{metadata}->{osie_x}}[0], 0, "Zero osie_x saved" ); -is( @{$details{metadata}->{osie_y}}[0], 0, "Zero osie_y saved" ); -$config->{geo_handler} = 3; - -Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } ); -Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); - -$guide = OpenGuides->new( config => $config ); - -$q = OpenGuides::Test->make_cgi_object( - content => "Blah", - latitude => 0, - longitude => 0 -); - -$output = $guide->commit_node( - id => "Test Node lat/long", - cgi_obj => $q, - return_output => 1 -); - -%details = $guide->wiki->retrieve_node("Test Node lat/long"); - -is( @{$details{metadata}->{latitude}}[0], 0, "Zero latitude saved" ); -is( @{$details{metadata}->{longitude}}[0], 0, "Zero longitude saved" ); -
Copied: trunk/t/700_admin_home.t (from rev 1381, trunk/t/70_admin_home.t) =================================================================== --- trunk/t/700_admin_home.t (rev 0) +++ trunk/t/700_admin_home.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,73 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 12; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); + + + +# Add 3 different pages, one of which with two versions +OpenGuides::Test->write_data( + guide => $guide, + node => "Test Page", + categories => "Alpha", + return_output => 1 ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Test Page 2", + categories => "Alpha", + return_output => 1 ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Locale Bar", + categories => "Locales", + return_output => 1 ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Locale Bar", + categories => "Locales", + return_output => 1 ); + + +# Test the tt vars +my %ttvars = eval { + $guide->display_admin_interface( return_tt_vars=> 1 ); +}; +is( $@, "", "->display_admin_interface doesn't die" ); + +is( scalar @{$ttvars{'nodes'}}, 2, "Right number of nodes" ); +is( scalar @{$ttvars{'locales'}}, 1, "Right number of locales" ); +is( scalar @{$ttvars{'categories'}}, 2, "Right number of categories" ); + +my @node_names = map { $_->{name}; } @{$ttvars{nodes}}; +is_deeply( [ sort @node_names ], [ "Test Page", "Test Page 2" ], + "Right nodes" ); +is( $ttvars{'locales'}->[0]->{name}, "Bar", "Right locale, right name" ); + +# Test the normal, HTML version +my $output = eval { + $guide->display_admin_interface( return_output=>1 ); +}; +is( $@, "", "->display_admin_interface doesn't die" ); + +like( $output, qr|Site Administration|, "Right page" ); +like( $output, qr|Test Page|, "Has nodes" ); +like( $output, qr|Bar|, "Has locales" );
Copied: trunk/t/701_missing_metadata.t (from rev 1381, trunk/t/71_missing_metadata.t) =================================================================== --- trunk/t/701_missing_metadata.t (rev 0) +++ trunk/t/701_missing_metadata.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,133 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 26; + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); + + + +# Add four different pages, one of which with two versions, one of which +# a redirect. The redirect should not show up on any "missing metadata" +# searches, regardless of the condition of the page it points to. +$wiki->write_node( "Test Page", "foo", undef, + { category => "Alpha", lat=>"" } ) + or die "Couldn't write node"; +$wiki->write_node( "Test Page 2", "foo2", undef, + { category => "Alpha", lat=>"22.22" } ) + or die "Couldn't write node"; +$wiki->write_node( "Test Page 3", "foo33", undef, + { category => "Alpha" } ) + or die "Couldn't write node"; +$wiki->write_node( "Category Foo", "foo", undef, + { category => "Categories", lat=>"-8.77" } ) + or die "Couldn't write category"; +$wiki->write_node( "Locale Bar", "foo", undef, + { category => "Locales", lat=>"8.22" } ) + or die "Couldn't write locale"; +my %data = $wiki->retrieve_node( "Locale Bar" ); +$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, + { category => "Locales", lat=>"8.88" } ) + or die "Couldn't write locale for the 2nd time"; +OpenGuides::Test->write_data( + guide => $guide, + node => "Redirect Test", + content => "#REDIRECT [[Test Page]]", + return_output => 1, + ); + +# Try without search parameters +my %ttvars = eval { + $guide->show_missing_metadata( return_tt_vars=> 1 ); +}; +my @nodes; +is( $@, "", "->show_missing_metadata doesn't die" ); + +is( scalar @{$ttvars{'nodes'}}, 0, "No nodes when no search params" ); +is( $ttvars{'done_search'}, 0, "Didn't search" ); + + +# Now try searching for those without lat +%ttvars = eval { + $guide->show_missing_metadata( + metadata_type => 'lat', + return_tt_vars => 1 + ); +}; + +@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; +is( scalar @nodes, 2, "Two without / with empty lat" ); +is( $ttvars{'done_search'}, 1, "Did search" ); +is( $nodes[0]->{'name'}, "Test Page", "Right nodes" ); +is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" ); + + +# Now try searching for those without lat=22.22 +%ttvars = eval { + $guide->show_missing_metadata( + metadata_type => 'lat', + metadata_value => '22.22', + return_tt_vars => 1 + ); +}; + +@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; +is( scalar @nodes, 4, "Four without that lat" ); +is( $ttvars{'done_search'}, 1, "Did search" ); +is( $nodes[0]->{'name'}, "Category Foo", "Right nodes" ); +is( $nodes[1]->{'name'}, "Locale Bar", "Right nodes" ); +is( $nodes[2]->{'name'}, "Test Page", "Right nodes" ); +is( $nodes[3]->{'name'}, "Test Page 3", "Right nodes" ); + + +# Try again, but exclude locale and category +%ttvars = eval { + $guide->show_missing_metadata( + metadata_type => 'lat', + metadata_value => '22.22', + exclude_locales => 1, + exclude_categories => 2, + return_tt_vars => 1 + ); +}; + +@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; +is( scalar @nodes, 2, "Two without that lat" ); +is( $ttvars{'done_search'}, 1, "Did search" ); +is( $nodes[0]->{'name'}, "Test Page", "Right nodes" ); +is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" ); + + +# Test the normal, HTML version +my $output = eval { + $guide->show_missing_metadata( return_output=>1 ); +}; +is( $@, "", "->show_missing_metadata doesn't die" ); + +like( $output, qr|Missing Metadata|, "Right page" ); +like( $output, qr|Metadata Type|, "Has prompts" ); +unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" ); + +$output = eval { + $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' ); +}; +is( $@, "", "->show_missing_metadata doesn't die" ); +like( $output, qr|<h3>Pages</h3>|, "searched" ); +like( $output, qr|Test Page|, "had node" );
Copied: trunk/t/702_node_moderation.t (from rev 1381, trunk/t/72_node_moderation.t) =================================================================== --- trunk/t/702_node_moderation.t (rev 0) +++ trunk/t/702_node_moderation.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,114 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 19; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); + + + +# Add a page +my $q = CGI->new; +$q->param( -name => "content", -value => "foo" ); +$q->param( -name => "categories", -value => "Alpha" ); +$q->param( -name => "locales", -value => "" ); +$q->param( -name => "phone", -value => "" ); +$q->param( -name => "fax", -value => "" ); +$q->param( -name => "website", -value => "" ); +$q->param( -name => "hours_text", -value => "" ); +$q->param( -name => "address", -value => "" ); +$q->param( -name => "postcode", -value => "" ); +$q->param( -name => "map_link", -value => "" ); +$q->param( -name => "os_x", -value => "" ); +$q->param( -name => "os_y", -value => "" ); +$q->param( -name => "username", -value => "bob" ); +$q->param( -name => "comment", -value => "foo" ); +$q->param( -name => "edit_type", -value => "Minor tidying" ); +$ENV{REMOTE_ADDR} = "127.0.0.1"; + +my $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check it's moderated +my %details = $wiki->retrieve_node("Wombats"); +is($details{'moderated'}, 1, "Moderated"); +is($wiki->node_required_moderation("Wombats"), 0, "No moderation"); + +# Turn on moderation +$wiki->set_node_moderation( + name => "Wombats", + required => 1, +); +is($wiki->node_required_moderation("Wombats"), 1, "Moderation"); + + +# Now add a new one, with new categories and locales +$q->param( -name => "categories", -value => "Alpha\r\nBeta" ); +$q->param( -name => "locales", -value => "Hello" ); +$q->param( -name => "edit_type", -value => "Normal edit" ); +$q->param( -name => "checksum", -value => $details{checksum} ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check that the current version is still 1 +%details = $wiki->retrieve_node("Wombats"); +is($details{'version'}, 1, "Still on v1"); +is($details{'moderated'}, 1, "v1 Moderated"); + +# Check that version 2 isn't moderated +my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2); +is($v2{'version'}, 2, "Is v2"); +is($v2{'moderated'}, 0, "Not moderated"); + +# Check that the new categories and locales aren't there +is(1, $wiki->node_exists("Category Alpha"), "Right Categories"); +is(0, $wiki->node_exists("Category Beta"), "Right Categories"); +is(0, $wiki->node_exists("Locale Hello"), "Right Locales"); + + +# Moderate +$guide->moderate_node( + id => "Wombats", + version => 2, + password => $guide->config->admin_pass +); + + +# Check that the current version is 2 +%details = $wiki->retrieve_node(name=>"Wombats"); +is($details{'version'}, 2, "Is v2"); +is($details{'moderated'}, 1, "Moderated"); + +# Check that version 2 is moderated +%v2 = $wiki->retrieve_node(name=>"Wombats",version=>2); +is($v2{'version'}, 2, "Is v2"); +is($v2{'moderated'}, 1, "Moderated"); + +# Check that the new categories and locales exist +is(1, $wiki->node_exists("Category Alpha"), "Right Categories"); +is(1, $wiki->node_exists("Category Beta"), "Right Categories"); +is(1, $wiki->node_exists("Locale Hello"), "Right Locales");
Copied: trunk/t/703_toggle_moderation.t (from rev 1381, trunk/t/73_toggle_moderation.t) =================================================================== --- trunk/t/703_toggle_moderation.t (rev 0) +++ trunk/t/703_toggle_moderation.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,121 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 14; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); + + + +# Add 3 different pages, one of which with two versions +$wiki->write_node( "Test Page", "foo", undef, + { category => "Alpha", lat=>"" } ) + or die "Couldn't write node"; +$wiki->write_node( "Test Page 2", "foo2", undef, + { category => "Alpha", lat=>"22.22" } ) + or die "Couldn't write node"; +$wiki->write_node( "Test Page 3", "foo33", undef, + { category => "Alpha" } ) + or die "Couldn't write node"; +$wiki->write_node( "Category Foo", "foo", undef, + { category => "Categories", lat=>"-8.77" } ) + or die "Couldn't write category"; +$wiki->write_node( "Locale Bar", "foo", undef, + { category => "Locales", lat=>"8.22" } ) + or die "Couldn't write locale"; +my %data = $wiki->retrieve_node( "Locale Bar" ); +$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, + { category => "Locales", lat=>"8.88" } ) + or die "Couldn't write locale for the 2nd time"; + + +# First up, try with no password +my $output = $guide->set_node_moderation( + id => "Test Page 3", + moderation_flag => 0, + return_output => 1 +); +like($output, qr|Change moderation status|, "Confirm page"); +like($output, qr|Confirm Moderation|, "Confirm page"); + + +# Now, try with the wrong password +$output = $guide->set_node_moderation( + id => "Test Page 3", + moderation_flag => 0, + password => "I_AM_WRONG", + return_output => 1 +); +like($output, qr|Incorrect Password|, "Wrong password"); +like($output, qr|Incorrect password for page moderation|, "Wrong password"); + + +# Check that "Test Page 3" doesn't have moderation set +my %node = $wiki->retrieve_node("Test Page 3"); +is($node{'node_requires_moderation'}, 0, "Doesn't have moderation on by default"); + +# Set the moderation flag on it to off +$guide->set_node_moderation( + id => "Test Page 3", + moderation_flag => 0, + password => $guide->config->admin_pass +); +%node = $wiki->retrieve_node("Test Page 3"); +is($node{'node_requires_moderation'}, 0, "Doesn't have moderation set when called with 0"); + +# Set it to on +$guide->set_node_moderation( + id => "Test Page 3", + moderation_flag => 1, + password => $guide->config->admin_pass +); +%node = $wiki->retrieve_node("Test Page 3"); +is($node{'node_requires_moderation'}, 1, "Turned on properly"); + +# Set it back to off +$guide->set_node_moderation( + id => "Test Page 3", + moderation_flag => 0, + password => $guide->config->admin_pass +); +%node = $wiki->retrieve_node("Test Page 3"); +is($node{'node_requires_moderation'}, 0, "Turned off properly"); + + +# Test we were sent to the right place +$output = $guide->set_node_moderation( + id => "Test Page 3", + moderation_flag => 0, + password => $guide->config->admin_pass, + return_output => 1 +); +like($output, qr|Location: http://example.com/wiki.cgi%5C?action=admin;moderation=changed%7C, "Right location"); +like($output, qr|Status: 302|, "Right status"); + +# And again, but this time with a made up node +$output = $guide->set_node_moderation( + id => "THIS PAGE DOES NOT EXIST", + moderation_flag => 0, + password => $guide->config->admin_pass, + return_output => 1 +); +like($output, qr|Location: http://example.com/wiki.cgi%5C?action=admin;moderation=unknown_node%7C, "Right location"); +like($output, qr|Status: 302|, "Right status");
Copied: trunk/t/704_ping_plugin.t (from rev 1381, trunk/t/74_ping_plugin.t) =================================================================== --- trunk/t/704_ping_plugin.t (rev 0) +++ trunk/t/704_ping_plugin.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,94 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 11; + +eval { require Wiki::Toolkit::Plugin::Ping; }; +my $have_ping = $@ ? 0 : 1; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_url => "http://wiki.example.com/", + script_name => "mywiki.cgi", + site_name => "Wiki::Toolkit Test Site", + default_city => "London", + default_country => "United Kingdom", + ping_services => "" + } +); +my $guide = OpenGuides->new( config => $config ); + +ok( $guide, "Created a guide with blank ping_services" ); + +# Check for the plugin +my @plugins = @{ $guide->wiki->{_registered_plugins} }; +is( scalar @plugins, 2, "...and it has two plugins" ); + + +# Now with the plugin +$config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_url => "http://wiki.example.com/", + script_name => "mywiki.cgi", + site_name => "Wiki::Toolkit Test Site", + default_city => "London", + default_country => "United Kingdom", + ping_services => "pingerati,geourl,FOOOO" + } +); + +SKIP: { + skip "Wiki::Toolkit::Plugin::Ping installed - no need to test graceful " + . "failure", 2 + if $have_ping; + eval { + # Suppress warnings; we expect them. + local $SIG{__WARN__} = sub { }; + $guide = OpenGuides->new( config => $config ); + }; + ok( !$@, "Guide creation doesn't die if we ask for ping_services but " + . "don't have Wiki::Toolkit::Plugin::Ping" ); + eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + $guide = OpenGuides->new( config => $config ); + }; + ok( $@, "...but it does warn" ); +} + +SKIP: { + skip "Wiki::Toolkit::Plugin::Ping not installed - can't test if it works", + 7 + unless $have_ping; + + $guide = OpenGuides->new( config => $config ); + ok($guide, "Made the guide OK"); + + @plugins = @{ $guide->wiki->{_registered_plugins} }; + is( scalar @plugins, 3, "Has plugin now" ); + ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin" ), "Right plugin" ); + ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin::Ping" ), "Right plugin" ); + + # Check it has the right services registered + my %services = $plugins[2]->services; + my @snames = sort keys %services; + is( scalar @snames, 2, "Has 2 services as expected" ); + is( $snames[0], "geourl", "Right service" ); + is( $snames[1], "pingerati", "Right service" ); +}
Copied: trunk/t/705_revert_user.t (from rev 1381, trunk/t/75_revert_user.t) =================================================================== --- trunk/t/705_revert_user.t (rev 0) +++ trunk/t/705_revert_user.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,208 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 23; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); + + +my %details; +my %vars; + + +# Add a page, user is bob +my $q = CGI->new; +$q->param( -name => "content", -value => "foo" ); +$q->param( -name => "categories", -value => "Alpha" ); +$q->param( -name => "locales", -value => "" ); +$q->param( -name => "phone", -value => "" ); +$q->param( -name => "fax", -value => "" ); +$q->param( -name => "website", -value => "" ); +$q->param( -name => "hours_text", -value => "" ); +$q->param( -name => "address", -value => "" ); +$q->param( -name => "postcode", -value => "" ); +$q->param( -name => "map_link", -value => "" ); +$q->param( -name => "os_x", -value => "" ); +$q->param( -name => "os_y", -value => "" ); +$q->param( -name => "username", -value => "bob" ); +$q->param( -name => "comment", -value => "foo" ); +$q->param( -name => "edit_type", -value => "Minor tidying" ); +$ENV{REMOTE_ADDR} = "127.0.0.1"; + +my $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +%details = $wiki->retrieve_node("Wombats"); +is( $details{version}, 1 ); +is( $details{metadata}->{username}->[0], "bob" ); + + +# Now add a new version, user is jim +$q->param( -name => "categories", -value => "Alpha\r\nBeta" ); +$q->param( -name => "locales", -value => "Hello" ); +$q->param( -name => "edit_type", -value => "Normal edit" ); +$q->param( -name => "checksum", -value => $details{checksum} ); +$q->param( -name => "username", -value => "jim" ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +%details = $wiki->retrieve_node("Wombats"); +is( $details{version}, 2 ); +is( $details{metadata}->{username}->[0], "jim" ); + + +# And again, another bob one +$q->param( -name => "checksum", -value => $details{checksum} ); +$q->param( -name => "username", -value => "bob" ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +%details = $wiki->retrieve_node("Wombats"); +is( $details{version}, 3 ); +is( $details{metadata}->{username}->[0], "bob" ); + +# Finally, a foo one +$q->param( -name => "checksum", -value => $details{checksum} ); +$q->param( -name => "username", -value => "foo" ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +%details = $wiki->retrieve_node("Wombats"); +is( $details{version}, 4 ); +is( $details{metadata}->{username}->[0], "foo" ); + + +# Check that there are 2 versions for bob +$q = CGI->new; +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + username => 'bob' +); +my @edits = @{$vars{'edits'}}; +is( scalar @edits, 2 ); + +# And one for foo +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + username => 'foo' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 1 ); + +# And one for jim +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + username => 'jim' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 1 ); + + +# Currently, we're on v4 +%details = $wiki->retrieve_node("Wombats"); +is( $details{'version'}, 4 ); + + +# Delete for foo - last one +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + password => $guide->config->admin_pass, + username => 'foo' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 0 ); + +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + username => 'foo' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 0 ); + + +# Now down to version 3 +%details = $wiki->retrieve_node("Wombats"); +is( $details{'version'}, 3 ); + + +# Now for jim - middle one (v2) +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + password => $guide->config->admin_pass, + username => 'jim' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 0 ); + +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + username => 'jim' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 0 ); + + +# Still on v3 +%details = $wiki->retrieve_node("Wombats"); +is( $details{'version'}, 3 ); + + +# Now for bob - first and last +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + password => $guide->config->admin_pass, + username => 'bob' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 0 ); + +%vars = $guide->revert_user_interface( + return_tt_vars => 1, + return_output => 0, + username => 'bob' +); +@edits = @{$vars{'edits'}}; +is( scalar @edits, 0 ); + + +# Page is gone +%details = $wiki->retrieve_node("Wombats"); +is( $details{'version'}, 0 );
Copied: trunk/t/706_detect_spam.t (from rev 1381, trunk/t/76_detect_spam.t) =================================================================== --- trunk/t/706_detect_spam.t (rev 0) +++ trunk/t/706_detect_spam.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,50 @@ +use strict; + +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 2; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Set up a guide which uses a spam detector module. +my $config = OpenGuides::Test->make_basic_config; +$config->spam_detector_module( "OpenGuides::Local::SpamDetector" ); +my $guide = OpenGuides->new( config => $config ); + +# Try to write something that isn't spam. +my $q = OpenGuides::Test->make_cgi_object( content => "puppies" ); +my $output = $guide->commit_node( + id => "Puppies", + cgi_obj => $q, + return_output => 1, + ); +ok( $guide->wiki->node_exists( "Puppies" ), "can write non-spam node" ); + +# Try to write something that is. +$q = OpenGuides::Test->make_cgi_object( content => "kittens" ); +$output = $guide->commit_node( + id => "Kittens", + cgi_obj => $q, + return_output => 1, + ); +ok( !$guide->wiki->node_exists( "Kittens" ), "can't write spammy node" ); + +package OpenGuides::Local::SpamDetector; + +sub looks_like_spam { + my ( $class, %args ) = @_; + if ( $args{content} =~ /kittens/i ) { + return 1; + } + return 0; +}
Copied: trunk/t/707_send_email.t (from rev 1381, trunk/t/77_send_email.t) =================================================================== --- trunk/t/707_send_email.t (rev 0) +++ trunk/t/707_send_email.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,45 @@ +use strict; +use OpenGuides::Config; +use OpenGuides::Utils; +use Test::More; + +plan tests => 6; + +my $config = OpenGuides::Config->new( + vars => { + contact_email => 'admin@example.com' + } +); + +my $output = OpenGuides::Utils->send_email( + config => $config, + return_output => 1, + to => [ 'user@example.com' ], + subject => 'Test subject', + body => 'Test body' +); + +like( $output, qr|^From: admin@example.com|m, "From address shown" ); +like( $output, qr|^To: user@example.com|m, "To address shown correctly" ); +like( $output, qr|^Subject: Test subject|m, "Subject shown correctly" ); +like( $output, qr|^Test body|m, "Body text appears at the start of a line" ); + +$output = OpenGuides::Utils->send_email( + config => $config, + return_output => 1, + admin => 1, + subject => 'Test subject', + body => 'Test body' +); + +like( $output, qr|^To: admin@example.com|m, "Admin address used ". + "appropriately" ); + +eval { $output = OpenGuides::Utils->send_email( + config => $config, + return_output => 1, + subject => 'Test subject', + body => 'Test body' +); }; + +like( $@, qr|No recipients specified|, "No recipients error caught" );
Copied: trunk/t/708_about.t (from rev 1381, trunk/t/78_about.t) =================================================================== --- trunk/t/708_about.t (rev 0) +++ trunk/t/708_about.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,32 @@ +use strict; +use warnings; + +use Test::More; +use OpenGuides; +use OpenGuides::Test; + +plan tests => 3; + +my $config = OpenGuides::Test->make_basic_config; +$config->site_name('My site'); +$config->contact_email('me@example.com'); +my $guide = OpenGuides->new(config => $config); + +my $output = $guide->display_about(return_output => 1); + +like( $output, qr|My site</a></h1>.*<h2>is powered by|ms, + "HTML about text is displayed, including the site name" ); + +$output = $guide->display_about(return_output => 1, + format => "opensearch" + ); + +like( $output, qr|OpenSearchDescription.*<Tags>My site</Tags>.*<Contact>me@example.com</Contact>|ms, + "OpenSearch about text is displayed, including the site name and contact"); + +$output = $guide->display_about(return_output => 1, + format => "rdf" + ); + +like( $output, qr|<Project rdf:ID="OpenGuides">|ms, + "RDF about text is displayed");
Copied: trunk/t/709_host_blacklist.t (from rev 1381, trunk/t/79_host_blacklist.t) =================================================================== --- trunk/t/709_host_blacklist.t (rev 0) +++ trunk/t/709_host_blacklist.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,50 @@ +use strict; + +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 1; + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Set up a guide which uses a spam detector module. +my $config = OpenGuides::Test->make_basic_config; +$config->host_checker_module( "OpenGuides::Local::HostBlacklist" ); +my $guide = OpenGuides->new( config => $config ); + +# Ensure CGI tells us what we expect to hear. +sub fake {'127.0.0.1'} + +use CGI; +{ + no warnings 'once'; + *CGI::remote_host = &fake; +} + +my $output = $guide->display_node( + id => "Nonesuch", + return_output => 1, + ); + +like($output, qr/Access denied/, 'host blacklist picks up IP'); + +package OpenGuides::Local::HostBlacklist; + +sub blacklisted_host { + my ( $class, $host ) = @_; + + if ( $host =~ /^127/ ) { + return 1; + } + + return 0; +}
Deleted: trunk/t/70_admin_home.t =================================================================== --- trunk/t/70_admin_home.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/70_admin_home.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,73 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 12; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); - - - -# Add 3 different pages, one of which with two versions -OpenGuides::Test->write_data( - guide => $guide, - node => "Test Page", - categories => "Alpha", - return_output => 1 ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Test Page 2", - categories => "Alpha", - return_output => 1 ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Locale Bar", - categories => "Locales", - return_output => 1 ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Locale Bar", - categories => "Locales", - return_output => 1 ); - - -# Test the tt vars -my %ttvars = eval { - $guide->display_admin_interface( return_tt_vars=> 1 ); -}; -is( $@, "", "->display_admin_interface doesn't die" ); - -is( scalar @{$ttvars{'nodes'}}, 2, "Right number of nodes" ); -is( scalar @{$ttvars{'locales'}}, 1, "Right number of locales" ); -is( scalar @{$ttvars{'categories'}}, 2, "Right number of categories" ); - -my @node_names = map { $_->{name}; } @{$ttvars{nodes}}; -is_deeply( [ sort @node_names ], [ "Test Page", "Test Page 2" ], - "Right nodes" ); -is( $ttvars{'locales'}->[0]->{name}, "Bar", "Right locale, right name" ); - -# Test the normal, HTML version -my $output = eval { - $guide->display_admin_interface( return_output=>1 ); -}; -is( $@, "", "->display_admin_interface doesn't die" ); - -like( $output, qr|Site Administration|, "Right page" ); -like( $output, qr|Test Page|, "Has nodes" ); -like( $output, qr|Bar|, "Has locales" );
Deleted: trunk/t/71_missing_metadata.t =================================================================== --- trunk/t/71_missing_metadata.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/71_missing_metadata.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,133 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 26; - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); - - - -# Add four different pages, one of which with two versions, one of which -# a redirect. The redirect should not show up on any "missing metadata" -# searches, regardless of the condition of the page it points to. -$wiki->write_node( "Test Page", "foo", undef, - { category => "Alpha", lat=>"" } ) - or die "Couldn't write node"; -$wiki->write_node( "Test Page 2", "foo2", undef, - { category => "Alpha", lat=>"22.22" } ) - or die "Couldn't write node"; -$wiki->write_node( "Test Page 3", "foo33", undef, - { category => "Alpha" } ) - or die "Couldn't write node"; -$wiki->write_node( "Category Foo", "foo", undef, - { category => "Categories", lat=>"-8.77" } ) - or die "Couldn't write category"; -$wiki->write_node( "Locale Bar", "foo", undef, - { category => "Locales", lat=>"8.22" } ) - or die "Couldn't write locale"; -my %data = $wiki->retrieve_node( "Locale Bar" ); -$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, - { category => "Locales", lat=>"8.88" } ) - or die "Couldn't write locale for the 2nd time"; -OpenGuides::Test->write_data( - guide => $guide, - node => "Redirect Test", - content => "#REDIRECT [[Test Page]]", - return_output => 1, - ); - -# Try without search parameters -my %ttvars = eval { - $guide->show_missing_metadata( return_tt_vars=> 1 ); -}; -my @nodes; -is( $@, "", "->show_missing_metadata doesn't die" ); - -is( scalar @{$ttvars{'nodes'}}, 0, "No nodes when no search params" ); -is( $ttvars{'done_search'}, 0, "Didn't search" ); - - -# Now try searching for those without lat -%ttvars = eval { - $guide->show_missing_metadata( - metadata_type => 'lat', - return_tt_vars => 1 - ); -}; - -@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; -is( scalar @nodes, 2, "Two without / with empty lat" ); -is( $ttvars{'done_search'}, 1, "Did search" ); -is( $nodes[0]->{'name'}, "Test Page", "Right nodes" ); -is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" ); - - -# Now try searching for those without lat=22.22 -%ttvars = eval { - $guide->show_missing_metadata( - metadata_type => 'lat', - metadata_value => '22.22', - return_tt_vars => 1 - ); -}; - -@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; -is( scalar @nodes, 4, "Four without that lat" ); -is( $ttvars{'done_search'}, 1, "Did search" ); -is( $nodes[0]->{'name'}, "Category Foo", "Right nodes" ); -is( $nodes[1]->{'name'}, "Locale Bar", "Right nodes" ); -is( $nodes[2]->{'name'}, "Test Page", "Right nodes" ); -is( $nodes[3]->{'name'}, "Test Page 3", "Right nodes" ); - - -# Try again, but exclude locale and category -%ttvars = eval { - $guide->show_missing_metadata( - metadata_type => 'lat', - metadata_value => '22.22', - exclude_locales => 1, - exclude_categories => 2, - return_tt_vars => 1 - ); -}; - -@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; -is( scalar @nodes, 2, "Two without that lat" ); -is( $ttvars{'done_search'}, 1, "Did search" ); -is( $nodes[0]->{'name'}, "Test Page", "Right nodes" ); -is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" ); - - -# Test the normal, HTML version -my $output = eval { - $guide->show_missing_metadata( return_output=>1 ); -}; -is( $@, "", "->show_missing_metadata doesn't die" ); - -like( $output, qr|Missing Metadata|, "Right page" ); -like( $output, qr|Metadata Type|, "Has prompts" ); -unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" ); - -$output = eval { - $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' ); -}; -is( $@, "", "->show_missing_metadata doesn't die" ); -like( $output, qr|<h3>Pages</h3>|, "searched" ); -like( $output, qr|Test Page|, "had node" );
Deleted: trunk/t/72_node_moderation.t =================================================================== --- trunk/t/72_node_moderation.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/72_node_moderation.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,114 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 19; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); - - - -# Add a page -my $q = CGI->new; -$q->param( -name => "content", -value => "foo" ); -$q->param( -name => "categories", -value => "Alpha" ); -$q->param( -name => "locales", -value => "" ); -$q->param( -name => "phone", -value => "" ); -$q->param( -name => "fax", -value => "" ); -$q->param( -name => "website", -value => "" ); -$q->param( -name => "hours_text", -value => "" ); -$q->param( -name => "address", -value => "" ); -$q->param( -name => "postcode", -value => "" ); -$q->param( -name => "map_link", -value => "" ); -$q->param( -name => "os_x", -value => "" ); -$q->param( -name => "os_y", -value => "" ); -$q->param( -name => "username", -value => "bob" ); -$q->param( -name => "comment", -value => "foo" ); -$q->param( -name => "edit_type", -value => "Minor tidying" ); -$ENV{REMOTE_ADDR} = "127.0.0.1"; - -my $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check it's moderated -my %details = $wiki->retrieve_node("Wombats"); -is($details{'moderated'}, 1, "Moderated"); -is($wiki->node_required_moderation("Wombats"), 0, "No moderation"); - -# Turn on moderation -$wiki->set_node_moderation( - name => "Wombats", - required => 1, -); -is($wiki->node_required_moderation("Wombats"), 1, "Moderation"); - - -# Now add a new one, with new categories and locales -$q->param( -name => "categories", -value => "Alpha\r\nBeta" ); -$q->param( -name => "locales", -value => "Hello" ); -$q->param( -name => "edit_type", -value => "Normal edit" ); -$q->param( -name => "checksum", -value => $details{checksum} ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check that the current version is still 1 -%details = $wiki->retrieve_node("Wombats"); -is($details{'version'}, 1, "Still on v1"); -is($details{'moderated'}, 1, "v1 Moderated"); - -# Check that version 2 isn't moderated -my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2); -is($v2{'version'}, 2, "Is v2"); -is($v2{'moderated'}, 0, "Not moderated"); - -# Check that the new categories and locales aren't there -is(1, $wiki->node_exists("Category Alpha"), "Right Categories"); -is(0, $wiki->node_exists("Category Beta"), "Right Categories"); -is(0, $wiki->node_exists("Locale Hello"), "Right Locales"); - - -# Moderate -$guide->moderate_node( - id => "Wombats", - version => 2, - password => $guide->config->admin_pass -); - - -# Check that the current version is 2 -%details = $wiki->retrieve_node(name=>"Wombats"); -is($details{'version'}, 2, "Is v2"); -is($details{'moderated'}, 1, "Moderated"); - -# Check that version 2 is moderated -%v2 = $wiki->retrieve_node(name=>"Wombats",version=>2); -is($v2{'version'}, 2, "Is v2"); -is($v2{'moderated'}, 1, "Moderated"); - -# Check that the new categories and locales exist -is(1, $wiki->node_exists("Category Alpha"), "Right Categories"); -is(1, $wiki->node_exists("Category Beta"), "Right Categories"); -is(1, $wiki->node_exists("Locale Hello"), "Right Locales");
Deleted: trunk/t/73_toggle_moderation.t =================================================================== --- trunk/t/73_toggle_moderation.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/73_toggle_moderation.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,121 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 14; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); - - - -# Add 3 different pages, one of which with two versions -$wiki->write_node( "Test Page", "foo", undef, - { category => "Alpha", lat=>"" } ) - or die "Couldn't write node"; -$wiki->write_node( "Test Page 2", "foo2", undef, - { category => "Alpha", lat=>"22.22" } ) - or die "Couldn't write node"; -$wiki->write_node( "Test Page 3", "foo33", undef, - { category => "Alpha" } ) - or die "Couldn't write node"; -$wiki->write_node( "Category Foo", "foo", undef, - { category => "Categories", lat=>"-8.77" } ) - or die "Couldn't write category"; -$wiki->write_node( "Locale Bar", "foo", undef, - { category => "Locales", lat=>"8.22" } ) - or die "Couldn't write locale"; -my %data = $wiki->retrieve_node( "Locale Bar" ); -$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, - { category => "Locales", lat=>"8.88" } ) - or die "Couldn't write locale for the 2nd time"; - - -# First up, try with no password -my $output = $guide->set_node_moderation( - id => "Test Page 3", - moderation_flag => 0, - return_output => 1 -); -like($output, qr|Change moderation status|, "Confirm page"); -like($output, qr|Confirm Moderation|, "Confirm page"); - - -# Now, try with the wrong password -$output = $guide->set_node_moderation( - id => "Test Page 3", - moderation_flag => 0, - password => "I_AM_WRONG", - return_output => 1 -); -like($output, qr|Incorrect Password|, "Wrong password"); -like($output, qr|Incorrect password for page moderation|, "Wrong password"); - - -# Check that "Test Page 3" doesn't have moderation set -my %node = $wiki->retrieve_node("Test Page 3"); -is($node{'node_requires_moderation'}, 0, "Doesn't have moderation on by default"); - -# Set the moderation flag on it to off -$guide->set_node_moderation( - id => "Test Page 3", - moderation_flag => 0, - password => $guide->config->admin_pass -); -%node = $wiki->retrieve_node("Test Page 3"); -is($node{'node_requires_moderation'}, 0, "Doesn't have moderation set when called with 0"); - -# Set it to on -$guide->set_node_moderation( - id => "Test Page 3", - moderation_flag => 1, - password => $guide->config->admin_pass -); -%node = $wiki->retrieve_node("Test Page 3"); -is($node{'node_requires_moderation'}, 1, "Turned on properly"); - -# Set it back to off -$guide->set_node_moderation( - id => "Test Page 3", - moderation_flag => 0, - password => $guide->config->admin_pass -); -%node = $wiki->retrieve_node("Test Page 3"); -is($node{'node_requires_moderation'}, 0, "Turned off properly"); - - -# Test we were sent to the right place -$output = $guide->set_node_moderation( - id => "Test Page 3", - moderation_flag => 0, - password => $guide->config->admin_pass, - return_output => 1 -); -like($output, qr|Location: http://example.com/wiki.cgi%5C?action=admin;moderation=changed%7C, "Right location"); -like($output, qr|Status: 302|, "Right status"); - -# And again, but this time with a made up node -$output = $guide->set_node_moderation( - id => "THIS PAGE DOES NOT EXIST", - moderation_flag => 0, - password => $guide->config->admin_pass, - return_output => 1 -); -like($output, qr|Location: http://example.com/wiki.cgi%5C?action=admin;moderation=unknown_node%7C, "Right location"); -like($output, qr|Status: 302|, "Right status");
Deleted: trunk/t/74_ping_plugin.t =================================================================== --- trunk/t/74_ping_plugin.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/74_ping_plugin.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,94 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 11; - -eval { require Wiki::Toolkit::Plugin::Ping; }; -my $have_ping = $@ ? 0 : 1; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_url => "http://wiki.example.com/", - script_name => "mywiki.cgi", - site_name => "Wiki::Toolkit Test Site", - default_city => "London", - default_country => "United Kingdom", - ping_services => "" - } -); -my $guide = OpenGuides->new( config => $config ); - -ok( $guide, "Created a guide with blank ping_services" ); - -# Check for the plugin -my @plugins = @{ $guide->wiki->{_registered_plugins} }; -is( scalar @plugins, 2, "...and it has two plugins" ); - - -# Now with the plugin -$config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_url => "http://wiki.example.com/", - script_name => "mywiki.cgi", - site_name => "Wiki::Toolkit Test Site", - default_city => "London", - default_country => "United Kingdom", - ping_services => "pingerati,geourl,FOOOO" - } -); - -SKIP: { - skip "Wiki::Toolkit::Plugin::Ping installed - no need to test graceful " - . "failure", 2 - if $have_ping; - eval { - # Suppress warnings; we expect them. - local $SIG{__WARN__} = sub { }; - $guide = OpenGuides->new( config => $config ); - }; - ok( !$@, "Guide creation doesn't die if we ask for ping_services but " - . "don't have Wiki::Toolkit::Plugin::Ping" ); - eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - $guide = OpenGuides->new( config => $config ); - }; - ok( $@, "...but it does warn" ); -} - -SKIP: { - skip "Wiki::Toolkit::Plugin::Ping not installed - can't test if it works", - 7 - unless $have_ping; - - $guide = OpenGuides->new( config => $config ); - ok($guide, "Made the guide OK"); - - @plugins = @{ $guide->wiki->{_registered_plugins} }; - is( scalar @plugins, 3, "Has plugin now" ); - ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin" ), "Right plugin" ); - ok( $plugins[2]->isa( "Wiki::Toolkit::Plugin::Ping" ), "Right plugin" ); - - # Check it has the right services registered - my %services = $plugins[2]->services; - my @snames = sort keys %services; - is( scalar @snames, 2, "Has 2 services as expected" ); - is( $snames[0], "geourl", "Right service" ); - is( $snames[1], "pingerati", "Right service" ); -}
Deleted: trunk/t/75_revert_user.t =================================================================== --- trunk/t/75_revert_user.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/75_revert_user.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,208 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 23; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); - - -my %details; -my %vars; - - -# Add a page, user is bob -my $q = CGI->new; -$q->param( -name => "content", -value => "foo" ); -$q->param( -name => "categories", -value => "Alpha" ); -$q->param( -name => "locales", -value => "" ); -$q->param( -name => "phone", -value => "" ); -$q->param( -name => "fax", -value => "" ); -$q->param( -name => "website", -value => "" ); -$q->param( -name => "hours_text", -value => "" ); -$q->param( -name => "address", -value => "" ); -$q->param( -name => "postcode", -value => "" ); -$q->param( -name => "map_link", -value => "" ); -$q->param( -name => "os_x", -value => "" ); -$q->param( -name => "os_y", -value => "" ); -$q->param( -name => "username", -value => "bob" ); -$q->param( -name => "comment", -value => "foo" ); -$q->param( -name => "edit_type", -value => "Minor tidying" ); -$ENV{REMOTE_ADDR} = "127.0.0.1"; - -my $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -%details = $wiki->retrieve_node("Wombats"); -is( $details{version}, 1 ); -is( $details{metadata}->{username}->[0], "bob" ); - - -# Now add a new version, user is jim -$q->param( -name => "categories", -value => "Alpha\r\nBeta" ); -$q->param( -name => "locales", -value => "Hello" ); -$q->param( -name => "edit_type", -value => "Normal edit" ); -$q->param( -name => "checksum", -value => $details{checksum} ); -$q->param( -name => "username", -value => "jim" ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -%details = $wiki->retrieve_node("Wombats"); -is( $details{version}, 2 ); -is( $details{metadata}->{username}->[0], "jim" ); - - -# And again, another bob one -$q->param( -name => "checksum", -value => $details{checksum} ); -$q->param( -name => "username", -value => "bob" ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -%details = $wiki->retrieve_node("Wombats"); -is( $details{version}, 3 ); -is( $details{metadata}->{username}->[0], "bob" ); - -# Finally, a foo one -$q->param( -name => "checksum", -value => $details{checksum} ); -$q->param( -name => "username", -value => "foo" ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -%details = $wiki->retrieve_node("Wombats"); -is( $details{version}, 4 ); -is( $details{metadata}->{username}->[0], "foo" ); - - -# Check that there are 2 versions for bob -$q = CGI->new; -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - username => 'bob' -); -my @edits = @{$vars{'edits'}}; -is( scalar @edits, 2 ); - -# And one for foo -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - username => 'foo' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 1 ); - -# And one for jim -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - username => 'jim' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 1 ); - - -# Currently, we're on v4 -%details = $wiki->retrieve_node("Wombats"); -is( $details{'version'}, 4 ); - - -# Delete for foo - last one -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - password => $guide->config->admin_pass, - username => 'foo' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 0 ); - -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - username => 'foo' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 0 ); - - -# Now down to version 3 -%details = $wiki->retrieve_node("Wombats"); -is( $details{'version'}, 3 ); - - -# Now for jim - middle one (v2) -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - password => $guide->config->admin_pass, - username => 'jim' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 0 ); - -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - username => 'jim' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 0 ); - - -# Still on v3 -%details = $wiki->retrieve_node("Wombats"); -is( $details{'version'}, 3 ); - - -# Now for bob - first and last -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - password => $guide->config->admin_pass, - username => 'bob' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 0 ); - -%vars = $guide->revert_user_interface( - return_tt_vars => 1, - return_output => 0, - username => 'bob' -); -@edits = @{$vars{'edits'}}; -is( scalar @edits, 0 ); - - -# Page is gone -%details = $wiki->retrieve_node("Wombats"); -is( $details{'version'}, 0 );
Deleted: trunk/t/76_detect_spam.t =================================================================== --- trunk/t/76_detect_spam.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/76_detect_spam.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,50 +0,0 @@ -use strict; - -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 2; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Set up a guide which uses a spam detector module. -my $config = OpenGuides::Test->make_basic_config; -$config->spam_detector_module( "OpenGuides::Local::SpamDetector" ); -my $guide = OpenGuides->new( config => $config ); - -# Try to write something that isn't spam. -my $q = OpenGuides::Test->make_cgi_object( content => "puppies" ); -my $output = $guide->commit_node( - id => "Puppies", - cgi_obj => $q, - return_output => 1, - ); -ok( $guide->wiki->node_exists( "Puppies" ), "can write non-spam node" ); - -# Try to write something that is. -$q = OpenGuides::Test->make_cgi_object( content => "kittens" ); -$output = $guide->commit_node( - id => "Kittens", - cgi_obj => $q, - return_output => 1, - ); -ok( !$guide->wiki->node_exists( "Kittens" ), "can't write spammy node" ); - -package OpenGuides::Local::SpamDetector; - -sub looks_like_spam { - my ( $class, %args ) = @_; - if ( $args{content} =~ /kittens/i ) { - return 1; - } - return 0; -}
Deleted: trunk/t/77_send_email.t =================================================================== --- trunk/t/77_send_email.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/77_send_email.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,45 +0,0 @@ -use strict; -use OpenGuides::Config; -use OpenGuides::Utils; -use Test::More; - -plan tests => 6; - -my $config = OpenGuides::Config->new( - vars => { - contact_email => 'admin@example.com' - } -); - -my $output = OpenGuides::Utils->send_email( - config => $config, - return_output => 1, - to => [ 'user@example.com' ], - subject => 'Test subject', - body => 'Test body' -); - -like( $output, qr|^From: admin@example.com|m, "From address shown" ); -like( $output, qr|^To: user@example.com|m, "To address shown correctly" ); -like( $output, qr|^Subject: Test subject|m, "Subject shown correctly" ); -like( $output, qr|^Test body|m, "Body text appears at the start of a line" ); - -$output = OpenGuides::Utils->send_email( - config => $config, - return_output => 1, - admin => 1, - subject => 'Test subject', - body => 'Test body' -); - -like( $output, qr|^To: admin@example.com|m, "Admin address used ". - "appropriately" ); - -eval { $output = OpenGuides::Utils->send_email( - config => $config, - return_output => 1, - subject => 'Test subject', - body => 'Test body' -); }; - -like( $@, qr|No recipients specified|, "No recipients error caught" );
Deleted: trunk/t/78_about.t =================================================================== --- trunk/t/78_about.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/78_about.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,32 +0,0 @@ -use strict; -use warnings; - -use Test::More; -use OpenGuides; -use OpenGuides::Test; - -plan tests => 3; - -my $config = OpenGuides::Test->make_basic_config; -$config->site_name('My site'); -$config->contact_email('me@example.com'); -my $guide = OpenGuides->new(config => $config); - -my $output = $guide->display_about(return_output => 1); - -like( $output, qr|My site</a></h1>.*<h2>is powered by|ms, - "HTML about text is displayed, including the site name" ); - -$output = $guide->display_about(return_output => 1, - format => "opensearch" - ); - -like( $output, qr|OpenSearchDescription.*<Tags>My site</Tags>.*<Contact>me@example.com</Contact>|ms, - "OpenSearch about text is displayed, including the site name and contact"); - -$output = $guide->display_about(return_output => 1, - format => "rdf" - ); - -like( $output, qr|<Project rdf:ID="OpenGuides">|ms, - "RDF about text is displayed");
Deleted: trunk/t/79_host_blacklist.t =================================================================== --- trunk/t/79_host_blacklist.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/79_host_blacklist.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,50 +0,0 @@ -use strict; - -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 1; - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Set up a guide which uses a spam detector module. -my $config = OpenGuides::Test->make_basic_config; -$config->host_checker_module( "OpenGuides::Local::HostBlacklist" ); -my $guide = OpenGuides->new( config => $config ); - -# Ensure CGI tells us what we expect to hear. -sub fake {'127.0.0.1'} - -use CGI; -{ - no warnings 'once'; - *CGI::remote_host = &fake; -} - -my $output = $guide->display_node( - id => "Nonesuch", - return_output => 1, - ); - -like($output, qr/Access denied/, 'host blacklist picks up IP'); - -package OpenGuides::Local::HostBlacklist; - -sub blacklisted_host { - my ( $class, $host ) = @_; - - if ( $host =~ /^127/ ) { - return 1; - } - - return 0; -}
Copied: trunk/t/801_node_moderate_whitelist.t (from rev 1381, trunk/t/81_node_moderate_whitelist.t) =================================================================== --- trunk/t/801_node_moderate_whitelist.t (rev 0) +++ trunk/t/801_node_moderate_whitelist.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,92 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; + +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +plan tests => 12; + + OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +$config->script_name( "wiki.cgi" ); +$config->script_url( "http://example.com/" ); +$config->moderate_whitelist( "127.0.0.1,127.0.0.2" ); +my $guide = OpenGuides->new( config => $config ); +isa_ok( $guide, "OpenGuides" ); +my $wiki = $guide->wiki; +isa_ok( $wiki, "Wiki::Toolkit" ); + + + +# Add a page +my $q = CGI->new; +$q->param( -name => "content", -value => "foo" ); +$q->param( -name => "categories", -value => "Alpha" ); +$q->param( -name => "locales", -value => "" ); +$q->param( -name => "phone", -value => "" ); +$q->param( -name => "fax", -value => "" ); +$q->param( -name => "website", -value => "" ); +$q->param( -name => "hours_text", -value => "" ); +$q->param( -name => "address", -value => "" ); +$q->param( -name => "postcode", -value => "" ); +$q->param( -name => "map_link", -value => "" ); +$q->param( -name => "os_x", -value => "" ); +$q->param( -name => "os_y", -value => "" ); +$q->param( -name => "username", -value => "bob" ); +$q->param( -name => "comment", -value => "foo" ); +$q->param( -name => "edit_type", -value => "Minor tidying" ); +$ENV{REMOTE_ADDR} = "127.0.0.1"; + +my $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check it's moderated +my %details = $wiki->retrieve_node("Wombats"); +is($details{'moderated'}, 1, "Moderated"); +is($wiki->node_required_moderation("Wombats"), 0, "No moderation"); + +# Turn on moderation +$wiki->set_node_moderation( + name => "Wombats", + required => 1, +); +is($wiki->node_required_moderation("Wombats"), 1, "Moderation"); + + +# Now add a new one, with new categories and locales +$q->param( -name => "categories", -value => "Alpha\r\nBeta" ); +$q->param( -name => "locales", -value => "Hello" ); +$q->param( -name => "edit_type", -value => "Normal edit" ); +$q->param( -name => "checksum", -value => $details{checksum} ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check that the current version is now 2 +%details = $wiki->retrieve_node("Wombats"); +is($details{'version'}, 2, "Still on v1"); +is($details{'moderated'}, 1, "v1 Moderated"); + +# Check that version 2 is moderated +my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2); +is($v2{'version'}, 2, "Is v2"); +is($v2{'moderated'}, 1, "Moderated"); + +# Check that the new categories and locales are there +is(1, $wiki->node_exists("Category Alpha"), "Right Categories"); +is(1, $wiki->node_exists("Category Beta"), "Right Categories"); +is(1, $wiki->node_exists("Locale Hello"), "Right Locales"); +
Copied: trunk/t/802_stylesheet.t (from rev 1381, trunk/t/82_stylesheet.t) =================================================================== --- trunk/t/802_stylesheet.t (rev 0) +++ trunk/t/802_stylesheet.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,50 @@ +use strict; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not available."; +} + +plan tests => 3; + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Write a node. +OpenGuides::Test->write_data( guide => $guide, node => "Red Lion", + return_output => 1 ); + +# Display it, and make sure we get the openguides-base.css in there. +$config->static_url( "http://example.org/static/" ); +my $output = $guide->display_node( id => "Red Lion", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "link", + { rel => "stylesheet", + href => "http://example.org/static/openguides-base.css" }, + "openguides-base stylesheet used when none provided" ); + +# Make sure the guide's own stylesheet overrides this though. +$config->stylesheet_url( "http://example.com/styles.css" ); +$output = $guide->display_node( id => "Red Lion", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::no_tag( $output, "link", + { rel => "stylesheet", href => "openguides-base.css" }, + "...but not when one is provided" ); +Test::HTML::Content::tag_ok( $output, "link", + { rel => "stylesheet", href => "http://example.com/styles.css" }, + "...and the guide's own stylesheet is used instead" );
Copied: trunk/t/803_show_delete_to_admins_only.t (from rev 1381, trunk/t/83_show_delete_to_admins_only.t) =================================================================== --- trunk/t/803_show_delete_to_admins_only.t (rev 0) +++ trunk/t/803_show_delete_to_admins_only.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,122 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::CGI; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +sub get_recent_changes { + my ($guide) = @_; + + my $output = $guide->display_recent_changes( return_output => 1 ); + $output =~ s/^Content-Type.*[\r\n]+//m; + + return $output; +} + +sub get_preferences { + my ($guide) = @_; + + return OpenGuides::Template->output( + wiki => $guide->wiki, + config => $guide->config, + template => "preferences.tt", + noheaders => 1, + vars => { + not_editable => 1, + show_form => 1 + }, + ); +} + +plan tests => 4; + +my ( $config, $guide, $wiki, $output ); + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Make a guide +$config = OpenGuides::Test->make_basic_config; +$config->enable_page_deletion( 1 ); +$guide = OpenGuides->new( config => $config ); + +# set is_admin to 1 +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; +OpenGuides::Test->write_data( + guide => $guide, + node => "Test Page", + ); + +$output = $guide->display_node( + return_output => 1, + noheaders => 1, + id => "Test Page", + ); + +# check delete link is shown in footer +Test::HTML::Content::tag_ok( $output, "div", { id => "footer_delete_link" }, + "delete link in footer for admin" ); + +$output = $guide->list_all_versions( + return_output => 1, + id => "Test Page", + ); +like( $output, qr/version=1;action=delete/, + "delete links on history page" ); + +# set is_admin to 0 +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 0, +); +$ENV{HTTP_COOKIE} = $cookie; + +$output = $guide->display_node( + return_output => 1, + noheaders => 1, + id => "Test Page", + ); + +# check that the delete link in footer isnt shown +Test::HTML::Content::no_tag( $output, "div", { id => "footer_delete_link" }, + "delete link in footer not shown"); +$output = $guide->list_all_versions( + return_output => 1, + id => "Test Page", + ); +unlike( $output, qr/version=1;action=delete/, + "no delete links on history page");
Copied: trunk/t/804_navbar_admin.t (from rev 1381, trunk/t/84_navbar_admin.t) =================================================================== --- trunk/t/804_navbar_admin.t (rev 0) +++ trunk/t/804_navbar_admin.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,108 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides::CGI; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; + exit 0; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; + exit 0; +} + +sub get_recent_changes { + my ($guide) = @_; + + my $output = $guide->display_recent_changes( return_output => 1 ); + $output =~ s/^Content-Type.*[\r\n]+//m; + + return $output; +} + +sub get_preferences { + my ($guide) = @_; + + return OpenGuides::Template->output( + wiki => $guide->wiki, + config => $guide->config, + template => "preferences.tt", + noheaders => 1, + vars => { + not_editable => 1, + show_form => 1 + }, + ); +} + +plan tests => 2; + +my ( $config, $guide, $wiki, $output ); + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Make a guide +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); + +# set is_admin to 1 +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; +OpenGuides::Test->write_data( + guide => $guide, + node => "Test Page", + ); + +$output = $guide->display_node( + return_output => 1, + noheaders => 1, + id => "Test Page", + ); + +# check navbar_admin div is shown. +Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_admin" }, + "admin section displayed in navbar" ); + +# set is_admin to 0 +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 0, +); +$ENV{HTTP_COOKIE} = $cookie; + +$output = $guide->display_node( + return_output => 1, + noheaders => 1, + id => "Test Page", + ); + +# check that the navbar_admin div isnt shown +Test::HTML::Content::no_tag( $output, "div", { id => "navbar_admin" }, + "navbar not shown" );
Copied: trunk/t/805_universal_edit_link.t (from rev 1381, trunk/t/85_universal_edit_link.t) =================================================================== --- trunk/t/805_universal_edit_link.t (rev 0) +++ trunk/t/805_universal_edit_link.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,43 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Wiki::Toolkit::Setup::SQLite; + +eval { require DBD::SQLite; }; +if ( $@ ) { + plan skip_all => "DBD::SQLite not installed - no database to test with"; +} + +plan tests => 2; + +# An editable page should get the universal edit <link>; a non-editable one +# shouldn't. + +my ( $config, $guide, $wiki, $cookie, $output ); + +# Clear out the database from any previous runs. + OpenGuides::Test::refresh_db(); + +# Make a guide. +$config = OpenGuides::Test->make_basic_config; +$guide = OpenGuides->new( config => $config ); +$wiki = $guide->wiki; + +# Write a node. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + return_output => 1, + ); + +# Check an editable node. +$output = $guide->display_node( + id => "Red Lion", + return_output => 1, + ); +like( $output, qr|<link rel="alternate" type="application/wiki" title="Edit this page!"|ms, "universal edit link present on editable page" ); + +# Check a non-editable node. +$output = $guide->display_recent_changes( return_output => 1 ); +unlike( $output, qr|<link rel="alternate" type="application/wiki" title="Edit this page!"|ms, "universal edit link not present on non-editable page" );
Copied: trunk/t/806_recent_changes.t (from rev 1381, trunk/t/86_recent_changes.t) =================================================================== --- trunk/t/806_recent_changes.t (rev 0) +++ trunk/t/806_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,225 @@ +use strict; +use OpenGuides; +use OpenGuides::Test; +use Test::More; +use Time::Piece; +use Time::Seconds; +use Wiki::Toolkit::Store::Database; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 16; + +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Set things up so that we have the following nodes and edit types. All +# nodes added 11 days ago. +# - Red Lion, edited 9 days ago (normal), 3 days ago (normal) and today (minor) +# - Blue Lion, edited 7 days ago (minor), 5 days ago (normal) & today (minor) +setup_pages(); + +# Check all went in OK. +my %red = $wiki->retrieve_node( "Red Lion" ); +my %blue = $wiki->retrieve_node( "Blue Lion" ); +ok( $wiki->node_exists( "Red Lion" ), "Red Lion written." ); +ok( $wiki->node_exists( "Blue Lion" ), "Blue Lion written." ); +is( $red{version}, 4, "Correct Red version." ); +is( $blue{version}, 4, "Correct Blue version." ); + +# Check recent changes output when minor edits switched on. +my $cookie = OpenGuides::CGI->make_prefs_cookie( config => $config, + show_minor_edits_in_rc => 1 ); +$ENV{HTTP_COOKIE} = $cookie; + +# First check default display. +my %tt_vars = $guide->display_recent_changes( return_tt_vars => 1 ); +my @nodes = extract_nodes( %tt_vars ); +my @names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], + "With minor edits: nodes returned only once however many times changed." ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Should see the same thing for past 10 days. +my $now = localtime; # overloaded by Time::Piece +my $tendays = $now - ( ONE_DAY * 10 ); +%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, + since => $tendays->epoch ); +@nodes = extract_nodes( %tt_vars ); +@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], + "...same result when looking at past 10 days" ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Check last day (both nodes edited minorly today, should show up). +my $yesterday = $now - ONE_DAY; +%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, + since => $yesterday->epoch ); +@nodes = extract_nodes( %tt_vars ); +@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], + "...and both nodes included when we look at past day." ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Check last 4 days (again, both should show up since this is minor edits, +# but they should only show up once). +my $fourdays = $now - ( ONE_DAY * 4 ); +%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, + since => $fourdays->epoch ); +@nodes = extract_nodes( %tt_vars ); +@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], + "...and past 4 days" ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Now test with minor edits switched off. +$cookie = OpenGuides::CGI->make_prefs_cookie( config => $config, + show_minor_edits_in_rc => 0 ); +$ENV{HTTP_COOKIE} = $cookie; + +# First check default display. +%tt_vars = $guide->display_recent_changes( return_tt_vars => 1 ); +@nodes = extract_nodes( %tt_vars ); +@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +is_deeply( @names_vers, [ "Blue Lion (v3)", "Red Lion (v3)" ], + "Without minor edits: node returned only once however many times changed." ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Should see the same thing for past 10 days. +%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, + since => $tendays->epoch ); +@nodes = extract_nodes( %tt_vars ); +@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +is_deeply( @names_vers, [ "Blue Lion (v3)", "Red Lion (v3)" ], + "...same result when looking at past 10 days" ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Check last day (last normal edit 3 days ago - nothing should show up). +%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, + since => $yesterday->epoch ); +@nodes = extract_nodes( %tt_vars ); +@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +ok( scalar @nodes == 0, + "...and nothing returned when no recent normal edits." ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Check last 4 days (should only see one normal edit, for Red Lion). +%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, + since => $fourdays->epoch ); +@nodes = extract_nodes( %tt_vars ); +@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; +is_deeply( @names_vers, [ "Red Lion (v3)" ], + "...and only normally-edited nodes returned for past 4 days" ); +diag( "Found: " . join( ", ", @names_vers ) ); + +# Now write a node that will Auto Create a locale, and check the +# Recent Changes output with minor edits and admin links switched on. +# We can't use OG::Test->write_data() for this, because it calls +# make_cgi_object(), which overwrites REMOTE_ADDR (and we want to test +# output of IP address). +my $q = OpenGuides::Test->make_cgi_object(); +$q->param( -name => "username", -value => "Anonymous" ); +$q->param( -name => "locales", -value => "London" ); +my $test_host = "198.51.100.255"; +$ENV{REMOTE_ADDR} = $test_host; +$guide->commit_node( id => "A Pub", cgi_obj => $q, return_output => 1 ); +$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( + config => $config, show_minor_edits_in_rc => 1, is_admin => 1 ); +my $output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr|Auto\s+Create|, + "Auto Create stuff shown on Recent Changes." ); +unlike( $output, qr|host=;action=userstats|, + "...and no spurious link to host userstats" ); + +# Make sure IP addresses always show up for anonymous edits. +$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( + config => $config, is_admin => 1 ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr|$test_host|, + "IP addresses show for anon edits when admin links switched on" ); +$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( + config => $config, is_admin => 0 ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr|$test_host|, + "...also when admin links switched off" ); + +sub setup_pages { + # We write directly to the database because that way we can fake the pages + # having been written in the past. Copied from test 062 in Wiki::Toolkit. + my $dbh = $wiki->store->dbh; + my $content_sth = $dbh->prepare( "INSERT INTO content + (node_id,version,text,modified) + VALUES (?,?,?,?)"); + my $node_sth = $dbh->prepare( "INSERT INTO node + (id,name,version,text,modified) + VALUES (?,?,?,?,?)"); + my $md_sth = $dbh->prepare( "INSERT INTO metadata + (node_id,version,metadata_type,metadata_value) + VALUES (?,?,?,?)"); + + # Red Lion first. + $node_sth->execute( 10, "Red Lion", 3, "red 2", + get_timestamp( days => 3 ) ) + or die $dbh->errstr; + $content_sth->execute( 10, 3, "red 3", get_timestamp( days => 3 ) ) + or die $dbh->errstr; + $content_sth->execute( 10, 2, "red 2", get_timestamp( days => 9 ) ) + or die $dbh->errstr; + $content_sth->execute( 10, 1, "red 1", get_timestamp( days => 11 ) ) + or die $dbh->errstr; + $md_sth->execute( 10, 3, "edit_type", "Normal edit" ); + $md_sth->execute( 10, 2, "edit_type", "Normal edit" ); + $md_sth->execute( 10, 1, "edit_type", "Normal edit" ); + $md_sth->execute( 10, 3, "comment", "Third red edit." ); + $md_sth->execute( 10, 2, "comment", "Second red edit." ); + $md_sth->execute( 10, 1, "comment", "First red edit." ); + + # Now write it as per usual. + OpenGuides::Test->write_data( guide => $guide, node => "Red Lion", + content => "red 4", edit_type => "Minor tidying", + comment => "Fourth red edit.", return_output => 1 ); + + # Now Blue Lion. + $node_sth->execute( 20, "Blue Lion", 3, "blue 3", + get_timestamp( days => 5 ) ) + or die $dbh->errstr; + $content_sth->execute( 20, 3, "blue 3", get_timestamp( days => 5 ) ) + or die $dbh->errstr; + $content_sth->execute( 20, 2, "blue 2", get_timestamp( days => 7 ) ) + or die $dbh->errstr; + $content_sth->execute( 20, 1, "blue 1", get_timestamp( days => 11 ) ) + or die $dbh->errstr; + $md_sth->execute( 20, 3, "edit_type", "Normal edit" ); + $md_sth->execute( 20, 2, "edit_type", "Minor tidying" ); + $md_sth->execute( 20, 1, "edit_type", "Normal edit" ); + $md_sth->execute( 20, 3, "comment", "Third blue edit." ); + $md_sth->execute( 20, 2, "comment", "Second blue edit." ); + $md_sth->execute( 20, 1, "comment", "First blue edit." ); + + # Now write it as per usual. + OpenGuides::Test->write_data( guide => $guide, node => "Blue Lion", + content => "blue 4", edit_type => "Minor tidying", + comment => "Fourth blue edit.", return_output => 1); +} + +sub get_timestamp { + my %args = @_; + my $days = $args{days}; + my $now = localtime; # overloaded by Time::Piece + my $time = $now - ( $days * ONE_DAY ); + return Wiki::Toolkit::Store::Database->_get_timestamp( $time ); +} + +sub extract_nodes { + my %tt_vars = @_; + my %rc = %{$tt_vars{recent_changes} }; + return @{ $rc{1} || [] }, @{ $rc{7} || [] }, @{ $rc{14} || [] }, + @{ $rc{since} || [] }; +}
Copied: trunk/t/807_more_recent_changes.t (from rev 1381, trunk/t/87_more_recent_changes.t) =================================================================== --- trunk/t/807_more_recent_changes.t (rev 0) +++ trunk/t/807_more_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,156 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Feed; +use OpenGuides::Utils; +use OpenGuides::Test; +use Test::More; +use OpenGuides::CGI; + + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +plan tests => 15; + +# Clear out the database from any previous runs. +unlink "t/node.db"; +unlink <t/indexes/*>; + +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + use_plucene => 1 + } +); + +# Basic sanity check first. +my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + +my $feed = OpenGuides::Feed->new( wiki => $wiki, + config => $config ); + + +# Write the first version +my $guide = OpenGuides->new( config => $config ); + +# Set up CGI parameters ready for a node write. +my $q = OpenGuides::Test->make_cgi_object( + content => "foo", + username => "bob", + comment => "First edit", + node_image => "image", + edit_type => "Normal edit", +); + +my $output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check we have it +ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); + +my %node = $wiki->retrieve_node("Wombats"); +is( $node{version}, 1, "First version" ); + +sleep(2); +# Now write a second version of it +$q->param( -name => "edit_type", -value => "Normal edit" ); +$q->param( -name => "checksum", -value => $node{checksum} ); +$q->param( -name => "comment", -value => "Second edit" ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check it's as expected +%node = $wiki->retrieve_node("Wombats"); +is( $node{version}, 2, "First version" ); +is( $node{metadata}->{edit_type}[0], "Normal edit", "Right edit type" ); + +sleep(2); +# Now write a third version of it +$q->param( -name => "edit_type", -value => "Minor tidying" ); +$q->param( -name => "checksum", -value => $node{checksum} ); +$q->param( -name => "comment", -value => "Third edit" ); +$output = $guide->commit_node( + return_output => 1, + id => "Wombats", + cgi_obj => $q, + ); + +# Check it's as expected +%node = $wiki->retrieve_node("Wombats"); +is( $node{version}, 3, "Third version" ); +is( $node{metadata}->{edit_type}[0], "Minor tidying", "Right edit type" ); + + +my @nodes = $wiki->list_recent_changes( days => 1 ); + is( scalar @nodes, 1, + "By default each node returned only once however many times changed" ); + @nodes = $wiki->list_recent_changes( days => 1, include_all_changes => 1 ); + is( scalar @nodes, 3, + "...returned more than once when 'include_all_changes' set" ); + +# when minor_edits = 1 + +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$output = $guide->display_recent_changes( return_output => 1 ); + +like ($output, qr/<td class="recentchanges_node_name">/, "expecting a table defintion for an edit"); +like ($output, qr/Third edit/, "showing the most recent minor edit"); +unlike ($output, qr/First edit/, "showing a page edit twice when show minor edits enabled. "); + + +# set show_minor_edits to 0. +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 0, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; + +$output = $guide->display_recent_changes( return_output => 1 ); +like ($output, qr/<td class="recentchanges_node_name">/, "expecting a table defintion for an edit"); +like ($output, qr/Second edit/, "expecting at least one edit"); +unlike ($output, qr/First edit/, "showing a page edit twice when not showing minor edits"); +unlike ($output, qr/Third edit/, "showing a page edit twice when not showing minor edits");
Copied: trunk/t/808_recent_changes_overtime.t (from rev 1381, trunk/t/88_recent_changes_overtime.t) =================================================================== --- trunk/t/808_recent_changes_overtime.t (rev 0) +++ trunk/t/808_recent_changes_overtime.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,181 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides::Config; +use OpenGuides; +use OpenGuides::Utils; +use OpenGuides::Test; +use Test::More; +use OpenGuides::CGI; + + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Wiki::Toolkit::Search::Plucene; }; +if ( $@ ) { + plan skip_all => "Plucene not installed"; +} + + +plan tests => 28; + +# Clear out the database from any previous runs. +unlink "t/node.db"; +unlink <t/indexes/*>; + + + +Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); +my $config = OpenGuides::Config->new( + vars => { + dbtype => "sqlite", + dbname => "t/node.db", + indexing_directory => "t/indexes", + script_name => "wiki.cgi", + script_url => "http://example.com/", + site_name => "Test Site", + template_path => "./templates", + home_name => "Home", + use_plucene => 1 + } +); + +# Basic sanity check first. +my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + +my $feed = OpenGuides::Feed->new( wiki => $wiki, + config => $config ); + + +my $guide = OpenGuides->new( config => $config ); + +# Generate 3 nodes +$guide->wiki->write_node( "Wombats","Wombats are cool",undef, { username => "bob", comment => "wombats rock", edit_type => "Normal edit" } ) or die "Can't write node"; + +$guide->wiki->write_node( "Armadillos","Armadillos are cool",undef, { username => "bob", comment => "Armadillos rock", edit_type => "Normal edit" } ) or die "Can't write node"; + +$guide->wiki->write_node( "Echidnas","Echidnas are cool",undef, { username => "bob", comment => "Echidnas rock", edit_type => "Normal edit" } ) or die "Can't write node"; + +#check they got created properly +my %node; + +ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); + +%node = $wiki->retrieve_node("Wombats"); +is( $node{version}, 1, "First version" ); + +ok( $wiki->node_exists( "Armadillos" ), "Armadillos written" ); + +%node = $wiki->retrieve_node("Armadillos"); +is( $node{version}, 1, "First version" ); +ok( $wiki->node_exists( "Echidnas" ), "Echidnas written" ); + +%node = $wiki->retrieve_node("Echidnas"); +is( $node{version}, 1, "First version" ); + +# Make them go back in time + +my $dbh = DBI->connect("dbi:SQLite:dbname=t/node.db", "", "", + { RaiseError => 1, AutoCommit => 1 }); + +$dbh->do("update content set modified = datetime('now','-13 day') where node_id = 1"); +$dbh->do("update node set modified = datetime('now','-13 day') where id = 1"); +$dbh->do("update content set modified = datetime('now','-2 day') where node_id = 2"); +$dbh->do("update node set modified = datetime('now','-2 day') where id = 2"); +$dbh->do("update content set modified = datetime('now','-25 day') where node_id = 3"); +$dbh->do("update node set modified = datetime('now','-25 day') where id = 3"); + +#check we only find 1 node in each time period +my @nodes; +@nodes = $wiki->list_recent_changes( between_days => [14, 30] ); + is( scalar @nodes, 1, + "node edited between 14 to 30 days ago" ); +@nodes = $wiki->list_recent_changes( between_days => [7, 14] ); + is( scalar @nodes, 1, + "node edited between 7 to 14 days ago" ); +@nodes = $wiki->list_recent_changes( between_days => [1, 6] ); + is( scalar @nodes, 1, + "node edited between 1 to 7 days ago" ); +# when minor_edits = 1 + +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +my $output = $guide->display_recent_changes( return_output => 1 ); + +# check recent changes renders properly +unlike ($output, qr/24 hours/, "no pages changed in the last 24 hours"); +like ($output, qr/last week/, "edits in the last week"); +like ($output, qr/last fortnight/, "edits in the last fornight"); +like ($output, qr/last 30 days/, "edits in the last 30 days"); + +# set show_minor_edits to 0. +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 0, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; + + + +$output = $guide->display_recent_changes( return_output => 1 ); +# check recent changes renders properly +unlike ($output, qr/24 hours/, "no pages changed in the last 24 hours"); +like ($output, qr/last week/, "edits in the last week"); +like ($output, qr/last fortnight/, "edits in the last fornight"); +like ($output, qr/last 30 days/, "edits in the last 30 days"); + +# make an extra edit now. +my %data = $wiki->retrieve_node( "Echidnas" ); +$guide->wiki->write_node( "Echidnas","Echidnas are so cool", $data{checksum}, { username => "bob", comment => "Echidnas suck", edit_type => "Normal edit" } ) or die "Can't write node"; +%node = $wiki->retrieve_node("Echidnas"); +is( $node{version}, 2, "Second version" ); +$output = $guide->display_recent_changes( return_output => 1 ); +# check recent changes renders properly +like ($output, qr/24 hours/, "pages changed in the last 24 hours"); +unlike ($output, qr/Echidnas rock/, "not showing multiple edits"); +like ($output, qr/last week/, "edits in the last week"); +like ($output, qr/last fortnight/, "edits in the last fornight"); +unlike ($output, qr/last 30 days/, "no edits in the last 30 days"); + +$cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "bob", + include_geocache_link => 1, + preview_above_edit_box => 1, + omit_help_links => 1, + show_minor_edits_in_rc => 1, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; +$output = $guide->display_recent_changes( return_output => 1 ); + +# check recent changes renders properly +like ($output, qr/24 hours/, "pages changed in the last 24 hours"); +unlike ($output, qr/Echidnas rock/, "not showing multiple edits"); +like ($output, qr/last week/, "edits in the last week"); +like ($output, qr/last fortnight/, "edits in the last fornight"); +unlike ($output, qr/last 30 days/, "no edits in the last 30 days");
Copied: trunk/t/809_recent_changes_ip_addr.t (from rev 1381, trunk/t/89_recent_changes_ip_addr.t) =================================================================== --- trunk/t/809_recent_changes_ip_addr.t (rev 0) +++ trunk/t/809_recent_changes_ip_addr.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,118 @@ +use strict; +use Cwd; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 10; + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# First we need to make sure that the preferences are accessible +# from the recent changes view. Can't test this using return_tt_vars +# because the prefs TT var is set in OpenGuides::Template->output(), +# and if return_tt_vars is set then execution never gets that far. +# So write a custom navbar template that just prints the variable we're +# interested in. + +$config->custom_template_path( cwd . "/t/templates/" ); +eval { + unlink cwd . "/t/templates/navbar.tt"; +}; +open( FILE, ">", cwd . "/t/templates/navbar.tt" ) + or die $!; +print FILE <<EOF; +PREFS_IS_ADMIN: [% prefs.is_admin %] +EOF +close FILE or die $!; + +$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1 ); +my $output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr/PREFS_IS_ADMIN:\s+1/, + "prefs available as TT var on recent changes" ); + +# Make sure this still works when they have a recent changes tracking cookie. +$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr/PREFS_IS_ADMIN:\s+1/, + "...even when there's a recent changes tracking cookie set" ); + +# Clean up. +unlink cwd . "/t/templates/navbar.tt"; + +# Write a node from an IPv6 address. We can't use OG::Test->write_data() +# for this, because it calls make_cgi_object(), which overwrites REMOTE_ADDR. +my $q = OpenGuides::Test->make_cgi_object(); +$ENV{REMOTE_ADDR} = "2001:db8:ca94:869f:226:8ff:fef9:453d"; +$guide->commit_node( id => "Red Lion", cgi_obj => $q, return_output => 1 ); + +# View recent changes with admin links switched off. +$ENV{HTTP_COOKIE} = make_cookie(); +$output = $guide->display_recent_changes( return_output => 1 ); +unlike( $output, qr/2001/, + "Recent changes omits IP address when admin links switched off" ); +$ENV{HTTP_COOKIE} = make_cookie( track_rc => 1 ); +$output = $guide->display_recent_changes( return_output => 1 ); +unlike( $output, qr/2001/, + "...also with recent changes tracking on" ); + +# And with them switched on. +$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1 ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr/">2001/, + "Recent changes shows IP address when admin links switched on" ); +unlike( $output, qr/">2001:db8:ca94:869f:226:8ff:fef9:453d/, + "...but not the full thing, if it's too long" ); +$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr/">2001/, + "IP address also shown when admin links and rc tracking both on" ); +unlike( $output, qr/">2001:db8:ca94:869f:226:8ff:fef9:453d/, + "...and again, full thing not shown if it's too long" ); + +# Now try it from an IPv4 address, which should fit. +$q = OpenGuides::Test->make_cgi_object(); +$ENV{REMOTE_ADDR} = "198.51.100.255"; +$guide->commit_node( id => "Yellow Lion", cgi_obj => $q, return_output => 1 ); +$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1 ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr/">198.51.100.255/, "Full IP address shown if short enough" ); +$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 ); +$output = $guide->display_recent_changes( return_output => 1 ); +like( $output, qr/">198.51.100.255/, + "...also if recent changes tracking is on" ); + +sub make_cookie { + my %args = @_; + + my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "Kake", + is_admin => $args{is_admin} || 0, + track_recent_changes_views => $args{track_rc} || 0, + ); + + if ( $args{track_rc} ) { + my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( + config => $config, + ); + my @prefs_bits = split( qr/\s*;\s*/, $prefs_cookie ); + my @rc_bits = split( qr/\s*;\s*/, $rc_cookie ); + return $prefs_bits[0] . "; " . $rc_bits[0]; + } + + return $prefs_cookie; +}
Deleted: trunk/t/81_node_moderate_whitelist.t =================================================================== --- trunk/t/81_node_moderate_whitelist.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/81_node_moderate_whitelist.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,92 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; - -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -plan tests => 12; - - OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -$config->script_name( "wiki.cgi" ); -$config->script_url( "http://example.com/" ); -$config->moderate_whitelist( "127.0.0.1,127.0.0.2" ); -my $guide = OpenGuides->new( config => $config ); -isa_ok( $guide, "OpenGuides" ); -my $wiki = $guide->wiki; -isa_ok( $wiki, "Wiki::Toolkit" ); - - - -# Add a page -my $q = CGI->new; -$q->param( -name => "content", -value => "foo" ); -$q->param( -name => "categories", -value => "Alpha" ); -$q->param( -name => "locales", -value => "" ); -$q->param( -name => "phone", -value => "" ); -$q->param( -name => "fax", -value => "" ); -$q->param( -name => "website", -value => "" ); -$q->param( -name => "hours_text", -value => "" ); -$q->param( -name => "address", -value => "" ); -$q->param( -name => "postcode", -value => "" ); -$q->param( -name => "map_link", -value => "" ); -$q->param( -name => "os_x", -value => "" ); -$q->param( -name => "os_y", -value => "" ); -$q->param( -name => "username", -value => "bob" ); -$q->param( -name => "comment", -value => "foo" ); -$q->param( -name => "edit_type", -value => "Minor tidying" ); -$ENV{REMOTE_ADDR} = "127.0.0.1"; - -my $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check it's moderated -my %details = $wiki->retrieve_node("Wombats"); -is($details{'moderated'}, 1, "Moderated"); -is($wiki->node_required_moderation("Wombats"), 0, "No moderation"); - -# Turn on moderation -$wiki->set_node_moderation( - name => "Wombats", - required => 1, -); -is($wiki->node_required_moderation("Wombats"), 1, "Moderation"); - - -# Now add a new one, with new categories and locales -$q->param( -name => "categories", -value => "Alpha\r\nBeta" ); -$q->param( -name => "locales", -value => "Hello" ); -$q->param( -name => "edit_type", -value => "Normal edit" ); -$q->param( -name => "checksum", -value => $details{checksum} ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check that the current version is now 2 -%details = $wiki->retrieve_node("Wombats"); -is($details{'version'}, 2, "Still on v1"); -is($details{'moderated'}, 1, "v1 Moderated"); - -# Check that version 2 is moderated -my %v2 = $wiki->retrieve_node(name=>"Wombats",version=>2); -is($v2{'version'}, 2, "Is v2"); -is($v2{'moderated'}, 1, "Moderated"); - -# Check that the new categories and locales are there -is(1, $wiki->node_exists("Category Alpha"), "Right Categories"); -is(1, $wiki->node_exists("Category Beta"), "Right Categories"); -is(1, $wiki->node_exists("Locale Hello"), "Right Locales"); -
Deleted: trunk/t/82_stylesheet.t =================================================================== --- trunk/t/82_stylesheet.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/82_stylesheet.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,50 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not available."; -} - -plan tests => 3; - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Write a node. -OpenGuides::Test->write_data( guide => $guide, node => "Red Lion", - return_output => 1 ); - -# Display it, and make sure we get the openguides-base.css in there. -$config->static_url( "http://example.org/static/" ); -my $output = $guide->display_node( id => "Red Lion", return_output => 1, - noheaders => 1 ); -Test::HTML::Content::tag_ok( $output, "link", - { rel => "stylesheet", - href => "http://example.org/static/openguides-base.css" }, - "openguides-base stylesheet used when none provided" ); - -# Make sure the guide's own stylesheet overrides this though. -$config->stylesheet_url( "http://example.com/styles.css" ); -$output = $guide->display_node( id => "Red Lion", return_output => 1, - noheaders => 1 ); -Test::HTML::Content::no_tag( $output, "link", - { rel => "stylesheet", href => "openguides-base.css" }, - "...but not when one is provided" ); -Test::HTML::Content::tag_ok( $output, "link", - { rel => "stylesheet", href => "http://example.com/styles.css" }, - "...and the guide's own stylesheet is used instead" );
Deleted: trunk/t/83_show_delete_to_admins_only.t =================================================================== --- trunk/t/83_show_delete_to_admins_only.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/83_show_delete_to_admins_only.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,122 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::CGI; - -eval { require DBD::SQLite; }; -if ( $@ ) { - plan skip_all => "DBD::SQLite not installed - no database to test with"; - exit 0; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; - exit 0; -} - -sub get_recent_changes { - my ($guide) = @_; - - my $output = $guide->display_recent_changes( return_output => 1 ); - $output =~ s/^Content-Type.*[\r\n]+//m; - - return $output; -} - -sub get_preferences { - my ($guide) = @_; - - return OpenGuides::Template->output( - wiki => $guide->wiki, - config => $guide->config, - template => "preferences.tt", - noheaders => 1, - vars => { - not_editable => 1, - show_form => 1 - }, - ); -} - -plan tests => 4; - -my ( $config, $guide, $wiki, $output ); - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Make a guide -$config = OpenGuides::Test->make_basic_config; -$config->enable_page_deletion( 1 ); -$guide = OpenGuides->new( config => $config ); - -# set is_admin to 1 -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -$ENV{HTTP_COOKIE} = $cookie; -OpenGuides::Test->write_data( - guide => $guide, - node => "Test Page", - ); - -$output = $guide->display_node( - return_output => 1, - noheaders => 1, - id => "Test Page", - ); - -# check delete link is shown in footer -Test::HTML::Content::tag_ok( $output, "div", { id => "footer_delete_link" }, - "delete link in footer for admin" ); - -$output = $guide->list_all_versions( - return_output => 1, - id => "Test Page", - ); -like( $output, qr/version=1;action=delete/, - "delete links on history page" ); - -# set is_admin to 0 -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 0, -); -$ENV{HTTP_COOKIE} = $cookie; - -$output = $guide->display_node( - return_output => 1, - noheaders => 1, - id => "Test Page", - ); - -# check that the delete link in footer isnt shown -Test::HTML::Content::no_tag( $output, "div", { id => "footer_delete_link" }, - "delete link in footer not shown"); -$output = $guide->list_all_versions( - return_output => 1, - id => "Test Page", - ); -unlike( $output, qr/version=1;action=delete/, - "no delete links on history page");
Deleted: trunk/t/84_navbar_admin.t =================================================================== --- trunk/t/84_navbar_admin.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/84_navbar_admin.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,108 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides::CGI; - -eval { require DBD::SQLite; }; -if ( $@ ) { - plan skip_all => "DBD::SQLite not installed - no database to test with"; - exit 0; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; - exit 0; -} - -sub get_recent_changes { - my ($guide) = @_; - - my $output = $guide->display_recent_changes( return_output => 1 ); - $output =~ s/^Content-Type.*[\r\n]+//m; - - return $output; -} - -sub get_preferences { - my ($guide) = @_; - - return OpenGuides::Template->output( - wiki => $guide->wiki, - config => $guide->config, - template => "preferences.tt", - noheaders => 1, - vars => { - not_editable => 1, - show_form => 1 - }, - ); -} - -plan tests => 2; - -my ( $config, $guide, $wiki, $output ); - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Make a guide -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); - -# set is_admin to 1 -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -$ENV{HTTP_COOKIE} = $cookie; -OpenGuides::Test->write_data( - guide => $guide, - node => "Test Page", - ); - -$output = $guide->display_node( - return_output => 1, - noheaders => 1, - id => "Test Page", - ); - -# check navbar_admin div is shown. -Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_admin" }, - "admin section displayed in navbar" ); - -# set is_admin to 0 -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 0, -); -$ENV{HTTP_COOKIE} = $cookie; - -$output = $guide->display_node( - return_output => 1, - noheaders => 1, - id => "Test Page", - ); - -# check that the navbar_admin div isnt shown -Test::HTML::Content::no_tag( $output, "div", { id => "navbar_admin" }, - "navbar not shown" );
Deleted: trunk/t/85_universal_edit_link.t =================================================================== --- trunk/t/85_universal_edit_link.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/85_universal_edit_link.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,43 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Wiki::Toolkit::Setup::SQLite; - -eval { require DBD::SQLite; }; -if ( $@ ) { - plan skip_all => "DBD::SQLite not installed - no database to test with"; -} - -plan tests => 2; - -# An editable page should get the universal edit <link>; a non-editable one -# shouldn't. - -my ( $config, $guide, $wiki, $cookie, $output ); - -# Clear out the database from any previous runs. - OpenGuides::Test::refresh_db(); - -# Make a guide. -$config = OpenGuides::Test->make_basic_config; -$guide = OpenGuides->new( config => $config ); -$wiki = $guide->wiki; - -# Write a node. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - return_output => 1, - ); - -# Check an editable node. -$output = $guide->display_node( - id => "Red Lion", - return_output => 1, - ); -like( $output, qr|<link rel="alternate" type="application/wiki" title="Edit this page!"|ms, "universal edit link present on editable page" ); - -# Check a non-editable node. -$output = $guide->display_recent_changes( return_output => 1 ); -unlike( $output, qr|<link rel="alternate" type="application/wiki" title="Edit this page!"|ms, "universal edit link not present on non-editable page" );
Deleted: trunk/t/86_recent_changes.t =================================================================== --- trunk/t/86_recent_changes.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/86_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,225 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::Test; -use Test::More; -use Time::Piece; -use Time::Seconds; -use Wiki::Toolkit::Store::Database; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 16; - -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Set things up so that we have the following nodes and edit types. All -# nodes added 11 days ago. -# - Red Lion, edited 9 days ago (normal), 3 days ago (normal) and today (minor) -# - Blue Lion, edited 7 days ago (minor), 5 days ago (normal) & today (minor) -setup_pages(); - -# Check all went in OK. -my %red = $wiki->retrieve_node( "Red Lion" ); -my %blue = $wiki->retrieve_node( "Blue Lion" ); -ok( $wiki->node_exists( "Red Lion" ), "Red Lion written." ); -ok( $wiki->node_exists( "Blue Lion" ), "Blue Lion written." ); -is( $red{version}, 4, "Correct Red version." ); -is( $blue{version}, 4, "Correct Blue version." ); - -# Check recent changes output when minor edits switched on. -my $cookie = OpenGuides::CGI->make_prefs_cookie( config => $config, - show_minor_edits_in_rc => 1 ); -$ENV{HTTP_COOKIE} = $cookie; - -# First check default display. -my %tt_vars = $guide->display_recent_changes( return_tt_vars => 1 ); -my @nodes = extract_nodes( %tt_vars ); -my @names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], - "With minor edits: nodes returned only once however many times changed." ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Should see the same thing for past 10 days. -my $now = localtime; # overloaded by Time::Piece -my $tendays = $now - ( ONE_DAY * 10 ); -%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, - since => $tendays->epoch ); -@nodes = extract_nodes( %tt_vars ); -@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], - "...same result when looking at past 10 days" ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Check last day (both nodes edited minorly today, should show up). -my $yesterday = $now - ONE_DAY; -%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, - since => $yesterday->epoch ); -@nodes = extract_nodes( %tt_vars ); -@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], - "...and both nodes included when we look at past day." ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Check last 4 days (again, both should show up since this is minor edits, -# but they should only show up once). -my $fourdays = $now - ( ONE_DAY * 4 ); -%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, - since => $fourdays->epoch ); -@nodes = extract_nodes( %tt_vars ); -@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -is_deeply( @names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ], - "...and past 4 days" ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Now test with minor edits switched off. -$cookie = OpenGuides::CGI->make_prefs_cookie( config => $config, - show_minor_edits_in_rc => 0 ); -$ENV{HTTP_COOKIE} = $cookie; - -# First check default display. -%tt_vars = $guide->display_recent_changes( return_tt_vars => 1 ); -@nodes = extract_nodes( %tt_vars ); -@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -is_deeply( @names_vers, [ "Blue Lion (v3)", "Red Lion (v3)" ], - "Without minor edits: node returned only once however many times changed." ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Should see the same thing for past 10 days. -%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, - since => $tendays->epoch ); -@nodes = extract_nodes( %tt_vars ); -@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -is_deeply( @names_vers, [ "Blue Lion (v3)", "Red Lion (v3)" ], - "...same result when looking at past 10 days" ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Check last day (last normal edit 3 days ago - nothing should show up). -%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, - since => $yesterday->epoch ); -@nodes = extract_nodes( %tt_vars ); -@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -ok( scalar @nodes == 0, - "...and nothing returned when no recent normal edits." ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Check last 4 days (should only see one normal edit, for Red Lion). -%tt_vars = $guide->display_recent_changes( return_tt_vars => 1, - since => $fourdays->epoch ); -@nodes = extract_nodes( %tt_vars ); -@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes; -is_deeply( @names_vers, [ "Red Lion (v3)" ], - "...and only normally-edited nodes returned for past 4 days" ); -diag( "Found: " . join( ", ", @names_vers ) ); - -# Now write a node that will Auto Create a locale, and check the -# Recent Changes output with minor edits and admin links switched on. -# We can't use OG::Test->write_data() for this, because it calls -# make_cgi_object(), which overwrites REMOTE_ADDR (and we want to test -# output of IP address). -my $q = OpenGuides::Test->make_cgi_object(); -$q->param( -name => "username", -value => "Anonymous" ); -$q->param( -name => "locales", -value => "London" ); -my $test_host = "198.51.100.255"; -$ENV{REMOTE_ADDR} = $test_host; -$guide->commit_node( id => "A Pub", cgi_obj => $q, return_output => 1 ); -$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( - config => $config, show_minor_edits_in_rc => 1, is_admin => 1 ); -my $output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr|Auto\s+Create|, - "Auto Create stuff shown on Recent Changes." ); -unlike( $output, qr|host=;action=userstats|, - "...and no spurious link to host userstats" ); - -# Make sure IP addresses always show up for anonymous edits. -$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( - config => $config, is_admin => 1 ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr|$test_host|, - "IP addresses show for anon edits when admin links switched on" ); -$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( - config => $config, is_admin => 0 ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr|$test_host|, - "...also when admin links switched off" ); - -sub setup_pages { - # We write directly to the database because that way we can fake the pages - # having been written in the past. Copied from test 062 in Wiki::Toolkit. - my $dbh = $wiki->store->dbh; - my $content_sth = $dbh->prepare( "INSERT INTO content - (node_id,version,text,modified) - VALUES (?,?,?,?)"); - my $node_sth = $dbh->prepare( "INSERT INTO node - (id,name,version,text,modified) - VALUES (?,?,?,?,?)"); - my $md_sth = $dbh->prepare( "INSERT INTO metadata - (node_id,version,metadata_type,metadata_value) - VALUES (?,?,?,?)"); - - # Red Lion first. - $node_sth->execute( 10, "Red Lion", 3, "red 2", - get_timestamp( days => 3 ) ) - or die $dbh->errstr; - $content_sth->execute( 10, 3, "red 3", get_timestamp( days => 3 ) ) - or die $dbh->errstr; - $content_sth->execute( 10, 2, "red 2", get_timestamp( days => 9 ) ) - or die $dbh->errstr; - $content_sth->execute( 10, 1, "red 1", get_timestamp( days => 11 ) ) - or die $dbh->errstr; - $md_sth->execute( 10, 3, "edit_type", "Normal edit" ); - $md_sth->execute( 10, 2, "edit_type", "Normal edit" ); - $md_sth->execute( 10, 1, "edit_type", "Normal edit" ); - $md_sth->execute( 10, 3, "comment", "Third red edit." ); - $md_sth->execute( 10, 2, "comment", "Second red edit." ); - $md_sth->execute( 10, 1, "comment", "First red edit." ); - - # Now write it as per usual. - OpenGuides::Test->write_data( guide => $guide, node => "Red Lion", - content => "red 4", edit_type => "Minor tidying", - comment => "Fourth red edit.", return_output => 1 ); - - # Now Blue Lion. - $node_sth->execute( 20, "Blue Lion", 3, "blue 3", - get_timestamp( days => 5 ) ) - or die $dbh->errstr; - $content_sth->execute( 20, 3, "blue 3", get_timestamp( days => 5 ) ) - or die $dbh->errstr; - $content_sth->execute( 20, 2, "blue 2", get_timestamp( days => 7 ) ) - or die $dbh->errstr; - $content_sth->execute( 20, 1, "blue 1", get_timestamp( days => 11 ) ) - or die $dbh->errstr; - $md_sth->execute( 20, 3, "edit_type", "Normal edit" ); - $md_sth->execute( 20, 2, "edit_type", "Minor tidying" ); - $md_sth->execute( 20, 1, "edit_type", "Normal edit" ); - $md_sth->execute( 20, 3, "comment", "Third blue edit." ); - $md_sth->execute( 20, 2, "comment", "Second blue edit." ); - $md_sth->execute( 20, 1, "comment", "First blue edit." ); - - # Now write it as per usual. - OpenGuides::Test->write_data( guide => $guide, node => "Blue Lion", - content => "blue 4", edit_type => "Minor tidying", - comment => "Fourth blue edit.", return_output => 1); -} - -sub get_timestamp { - my %args = @_; - my $days = $args{days}; - my $now = localtime; # overloaded by Time::Piece - my $time = $now - ( $days * ONE_DAY ); - return Wiki::Toolkit::Store::Database->_get_timestamp( $time ); -} - -sub extract_nodes { - my %tt_vars = @_; - my %rc = %{$tt_vars{recent_changes} }; - return @{ $rc{1} || [] }, @{ $rc{7} || [] }, @{ $rc{14} || [] }, - @{ $rc{since} || [] }; -}
Deleted: trunk/t/87_more_recent_changes.t =================================================================== --- trunk/t/87_more_recent_changes.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/87_more_recent_changes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,156 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Feed; -use OpenGuides::Utils; -use OpenGuides::Test; -use Test::More; -use OpenGuides::CGI; - - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -plan tests => 15; - -# Clear out the database from any previous runs. -unlink "t/node.db"; -unlink <t/indexes/*>; - -Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - use_plucene => 1 - } -); - -# Basic sanity check first. -my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - -my $feed = OpenGuides::Feed->new( wiki => $wiki, - config => $config ); - - -# Write the first version -my $guide = OpenGuides->new( config => $config ); - -# Set up CGI parameters ready for a node write. -my $q = OpenGuides::Test->make_cgi_object( - content => "foo", - username => "bob", - comment => "First edit", - node_image => "image", - edit_type => "Normal edit", -); - -my $output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check we have it -ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); - -my %node = $wiki->retrieve_node("Wombats"); -is( $node{version}, 1, "First version" ); - -sleep(2); -# Now write a second version of it -$q->param( -name => "edit_type", -value => "Normal edit" ); -$q->param( -name => "checksum", -value => $node{checksum} ); -$q->param( -name => "comment", -value => "Second edit" ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check it's as expected -%node = $wiki->retrieve_node("Wombats"); -is( $node{version}, 2, "First version" ); -is( $node{metadata}->{edit_type}[0], "Normal edit", "Right edit type" ); - -sleep(2); -# Now write a third version of it -$q->param( -name => "edit_type", -value => "Minor tidying" ); -$q->param( -name => "checksum", -value => $node{checksum} ); -$q->param( -name => "comment", -value => "Third edit" ); -$output = $guide->commit_node( - return_output => 1, - id => "Wombats", - cgi_obj => $q, - ); - -# Check it's as expected -%node = $wiki->retrieve_node("Wombats"); -is( $node{version}, 3, "Third version" ); -is( $node{metadata}->{edit_type}[0], "Minor tidying", "Right edit type" ); - - -my @nodes = $wiki->list_recent_changes( days => 1 ); - is( scalar @nodes, 1, - "By default each node returned only once however many times changed" ); - @nodes = $wiki->list_recent_changes( days => 1, include_all_changes => 1 ); - is( scalar @nodes, 3, - "...returned more than once when 'include_all_changes' set" ); - -# when minor_edits = 1 - -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -$output = $guide->display_recent_changes( return_output => 1 ); - -like ($output, qr/<td class="recentchanges_node_name">/, "expecting a table defintion for an edit"); -like ($output, qr/Third edit/, "showing the most recent minor edit"); -unlike ($output, qr/First edit/, "showing a page edit twice when show minor edits enabled. "); - - -# set show_minor_edits to 0. -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 0, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -$ENV{HTTP_COOKIE} = $cookie; - -$output = $guide->display_recent_changes( return_output => 1 ); -like ($output, qr/<td class="recentchanges_node_name">/, "expecting a table defintion for an edit"); -like ($output, qr/Second edit/, "expecting at least one edit"); -unlike ($output, qr/First edit/, "showing a page edit twice when not showing minor edits"); -unlike ($output, qr/Third edit/, "showing a page edit twice when not showing minor edits");
Deleted: trunk/t/88_recent_changes_overtime.t =================================================================== --- trunk/t/88_recent_changes_overtime.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/88_recent_changes_overtime.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,181 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides::Config; -use OpenGuides; -use OpenGuides::Utils; -use OpenGuides::Test; -use Test::More; -use OpenGuides::CGI; - - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Wiki::Toolkit::Search::Plucene; }; -if ( $@ ) { - plan skip_all => "Plucene not installed"; -} - - -plan tests => 28; - -# Clear out the database from any previous runs. -unlink "t/node.db"; -unlink <t/indexes/*>; - - - -Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); -my $config = OpenGuides::Config->new( - vars => { - dbtype => "sqlite", - dbname => "t/node.db", - indexing_directory => "t/indexes", - script_name => "wiki.cgi", - script_url => "http://example.com/", - site_name => "Test Site", - template_path => "./templates", - home_name => "Home", - use_plucene => 1 - } -); - -# Basic sanity check first. -my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - -my $feed = OpenGuides::Feed->new( wiki => $wiki, - config => $config ); - - -my $guide = OpenGuides->new( config => $config ); - -# Generate 3 nodes -$guide->wiki->write_node( "Wombats","Wombats are cool",undef, { username => "bob", comment => "wombats rock", edit_type => "Normal edit" } ) or die "Can't write node"; - -$guide->wiki->write_node( "Armadillos","Armadillos are cool",undef, { username => "bob", comment => "Armadillos rock", edit_type => "Normal edit" } ) or die "Can't write node"; - -$guide->wiki->write_node( "Echidnas","Echidnas are cool",undef, { username => "bob", comment => "Echidnas rock", edit_type => "Normal edit" } ) or die "Can't write node"; - -#check they got created properly -my %node; - -ok( $wiki->node_exists( "Wombats" ), "Wombats written" ); - -%node = $wiki->retrieve_node("Wombats"); -is( $node{version}, 1, "First version" ); - -ok( $wiki->node_exists( "Armadillos" ), "Armadillos written" ); - -%node = $wiki->retrieve_node("Armadillos"); -is( $node{version}, 1, "First version" ); -ok( $wiki->node_exists( "Echidnas" ), "Echidnas written" ); - -%node = $wiki->retrieve_node("Echidnas"); -is( $node{version}, 1, "First version" ); - -# Make them go back in time - -my $dbh = DBI->connect("dbi:SQLite:dbname=t/node.db", "", "", - { RaiseError => 1, AutoCommit => 1 }); - -$dbh->do("update content set modified = datetime('now','-13 day') where node_id = 1"); -$dbh->do("update node set modified = datetime('now','-13 day') where id = 1"); -$dbh->do("update content set modified = datetime('now','-2 day') where node_id = 2"); -$dbh->do("update node set modified = datetime('now','-2 day') where id = 2"); -$dbh->do("update content set modified = datetime('now','-25 day') where node_id = 3"); -$dbh->do("update node set modified = datetime('now','-25 day') where id = 3"); - -#check we only find 1 node in each time period -my @nodes; -@nodes = $wiki->list_recent_changes( between_days => [14, 30] ); - is( scalar @nodes, 1, - "node edited between 14 to 30 days ago" ); -@nodes = $wiki->list_recent_changes( between_days => [7, 14] ); - is( scalar @nodes, 1, - "node edited between 7 to 14 days ago" ); -@nodes = $wiki->list_recent_changes( between_days => [1, 6] ); - is( scalar @nodes, 1, - "node edited between 1 to 7 days ago" ); -# when minor_edits = 1 - -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -my $output = $guide->display_recent_changes( return_output => 1 ); - -# check recent changes renders properly -unlike ($output, qr/24 hours/, "no pages changed in the last 24 hours"); -like ($output, qr/last week/, "edits in the last week"); -like ($output, qr/last fortnight/, "edits in the last fornight"); -like ($output, qr/last 30 days/, "edits in the last 30 days"); - -# set show_minor_edits to 0. -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 0, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -$ENV{HTTP_COOKIE} = $cookie; - - - -$output = $guide->display_recent_changes( return_output => 1 ); -# check recent changes renders properly -unlike ($output, qr/24 hours/, "no pages changed in the last 24 hours"); -like ($output, qr/last week/, "edits in the last week"); -like ($output, qr/last fortnight/, "edits in the last fornight"); -like ($output, qr/last 30 days/, "edits in the last 30 days"); - -# make an extra edit now. -my %data = $wiki->retrieve_node( "Echidnas" ); -$guide->wiki->write_node( "Echidnas","Echidnas are so cool", $data{checksum}, { username => "bob", comment => "Echidnas suck", edit_type => "Normal edit" } ) or die "Can't write node"; -%node = $wiki->retrieve_node("Echidnas"); -is( $node{version}, 2, "Second version" ); -$output = $guide->display_recent_changes( return_output => 1 ); -# check recent changes renders properly -like ($output, qr/24 hours/, "pages changed in the last 24 hours"); -unlike ($output, qr/Echidnas rock/, "not showing multiple edits"); -like ($output, qr/last week/, "edits in the last week"); -like ($output, qr/last fortnight/, "edits in the last fornight"); -unlike ($output, qr/last 30 days/, "no edits in the last 30 days"); - -$cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "bob", - include_geocache_link => 1, - preview_above_edit_box => 1, - omit_help_links => 1, - show_minor_edits_in_rc => 1, - default_edit_type => "tidying", - cookie_expires => "never", - track_recent_changes_views => 1, - is_admin => 1, -); -$ENV{HTTP_COOKIE} = $cookie; -$output = $guide->display_recent_changes( return_output => 1 ); - -# check recent changes renders properly -like ($output, qr/24 hours/, "pages changed in the last 24 hours"); -unlike ($output, qr/Echidnas rock/, "not showing multiple edits"); -like ($output, qr/last week/, "edits in the last week"); -like ($output, qr/last fortnight/, "edits in the last fornight"); -unlike ($output, qr/last 30 days/, "no edits in the last 30 days");
Deleted: trunk/t/89_recent_changes_ip_addr.t =================================================================== --- trunk/t/89_recent_changes_ip_addr.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/89_recent_changes_ip_addr.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,118 +0,0 @@ -use strict; -use Cwd; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 10; - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# First we need to make sure that the preferences are accessible -# from the recent changes view. Can't test this using return_tt_vars -# because the prefs TT var is set in OpenGuides::Template->output(), -# and if return_tt_vars is set then execution never gets that far. -# So write a custom navbar template that just prints the variable we're -# interested in. - -$config->custom_template_path( cwd . "/t/templates/" ); -eval { - unlink cwd . "/t/templates/navbar.tt"; -}; -open( FILE, ">", cwd . "/t/templates/navbar.tt" ) - or die $!; -print FILE <<EOF; -PREFS_IS_ADMIN: [% prefs.is_admin %] -EOF -close FILE or die $!; - -$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1 ); -my $output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr/PREFS_IS_ADMIN:\s+1/, - "prefs available as TT var on recent changes" ); - -# Make sure this still works when they have a recent changes tracking cookie. -$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr/PREFS_IS_ADMIN:\s+1/, - "...even when there's a recent changes tracking cookie set" ); - -# Clean up. -unlink cwd . "/t/templates/navbar.tt"; - -# Write a node from an IPv6 address. We can't use OG::Test->write_data() -# for this, because it calls make_cgi_object(), which overwrites REMOTE_ADDR. -my $q = OpenGuides::Test->make_cgi_object(); -$ENV{REMOTE_ADDR} = "2001:db8:ca94:869f:226:8ff:fef9:453d"; -$guide->commit_node( id => "Red Lion", cgi_obj => $q, return_output => 1 ); - -# View recent changes with admin links switched off. -$ENV{HTTP_COOKIE} = make_cookie(); -$output = $guide->display_recent_changes( return_output => 1 ); -unlike( $output, qr/2001/, - "Recent changes omits IP address when admin links switched off" ); -$ENV{HTTP_COOKIE} = make_cookie( track_rc => 1 ); -$output = $guide->display_recent_changes( return_output => 1 ); -unlike( $output, qr/2001/, - "...also with recent changes tracking on" ); - -# And with them switched on. -$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1 ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr/">2001/, - "Recent changes shows IP address when admin links switched on" ); -unlike( $output, qr/">2001:db8:ca94:869f:226:8ff:fef9:453d/, - "...but not the full thing, if it's too long" ); -$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr/">2001/, - "IP address also shown when admin links and rc tracking both on" ); -unlike( $output, qr/">2001:db8:ca94:869f:226:8ff:fef9:453d/, - "...and again, full thing not shown if it's too long" ); - -# Now try it from an IPv4 address, which should fit. -$q = OpenGuides::Test->make_cgi_object(); -$ENV{REMOTE_ADDR} = "198.51.100.255"; -$guide->commit_node( id => "Yellow Lion", cgi_obj => $q, return_output => 1 ); -$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1 ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr/">198.51.100.255/, "Full IP address shown if short enough" ); -$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 ); -$output = $guide->display_recent_changes( return_output => 1 ); -like( $output, qr/">198.51.100.255/, - "...also if recent changes tracking is on" ); - -sub make_cookie { - my %args = @_; - - my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "Kake", - is_admin => $args{is_admin} || 0, - track_recent_changes_views => $args{track_rc} || 0, - ); - - if ( $args{track_rc} ) { - my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( - config => $config, - ); - my @prefs_bits = split( qr/\s*;\s*/, $prefs_cookie ); - my @rc_bits = split( qr/\s*;\s*/, $rc_cookie ); - return $prefs_bits[0] . "; " . $rc_bits[0]; - } - - return $prefs_cookie; -}
Copied: trunk/t/900_css_category_locale_classes.t (from rev 1381, trunk/t/90_css_category_locale_classes.t) =================================================================== --- trunk/t/900_css_category_locale_classes.t (rev 0) +++ trunk/t/900_css_category_locale_classes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,65 @@ +use strict; +use Cwd; +use OpenGuides; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not installed"; +} + +plan tests => 3; + +my $config = OpenGuides::Test->make_basic_config; +$config->custom_template_path( cwd . "/t/templates/" ); +my $guide = OpenGuides->new( config => $config ); + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Check that a node in one locale and one category has CSS classes for both. +OpenGuides::Test->write_data( + guide => $guide, + node => "Crown", + categories => "Pubs", + locales => "Cornmarket", + return_output => 1, + ); + +my $output = $guide->display_node( id => "Crown", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "div", + { id => "content", class => "cat_pubs loc_cornmarket" }, + "Node in one locale and one category has CSS classes for both." ); + +# Check that spaces in locale/category names are replaced by underscores. +OpenGuides::Test->write_data( + guide => $guide, + node => "Debenhams", + categories => "Baby Changing", + locales => "Magdalen Street", + return_output => 1, + ); +$output = $guide->display_node( id => "Debenhams", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::tag_ok( $output, "div", + { id => "content", class => "cat_baby_changing loc_magdalen_street" }, + "...and spaces in locale/category names are replaced by underscores." ); + +# Check that nodes with no locales or categories don't have classes added. +OpenGuides::Test->write_data( + guide => $guide, + node => "A Blank Node", + return_output => 1, + ); +$output = $guide->display_node( id => "A Blank Node", return_output => 1 ); +like( $output, qr|<div id="content">|, + "Nodes with no locales or categories don't have classes added." );
Copied: trunk/t/901_username_in_templates.t (from rev 1381, trunk/t/91_username_in_templates.t) =================================================================== --- trunk/t/901_username_in_templates.t (rev 0) +++ trunk/t/901_username_in_templates.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,67 @@ +use strict; +use Cwd; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 2; + +my $config = OpenGuides::Test->make_basic_config; +$config->custom_template_path( cwd . "/t/templates/tmp/" ); +my $guide = OpenGuides->new( config => $config ); + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Write a node. +OpenGuides::Test->write_data( + guide => $guide, + node => "Ship Of Fools", + return_output => 1, + ); +# Make sure the tmp directory exists +eval { + mkdir cwd . "/t/templates/tmp"; +}; +# Write a custom banner template that includes the username. +eval { + unlink cwd . "/t/templates/tmp/custom_banner.tt"; +}; + +open( my $fh, ">", cwd . "/t/templates/tmp/custom_banner.tt" ) or die $!; +print $fh <<EOF; +<div class="banner_username"> + [% IF username %] + You are logged in as [% username %]. + [% ELSE %] + You are not logged in. + [% END %] +</div> +EOF +close $fh or die $!; + +# Set a username in the cookie. +my $cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + username => "Kake", +); +$ENV{HTTP_COOKIE} = $cookie; + +# Check that username appears if cookie is set. +my $output = $guide->display_node( id => "Ship Of Fools", return_output => 1 ); +like( $output, qr/You are logged in as Kake./, + "username sent to templates if set in prefs cookie" ); + +# Check that username doesn't appear if cookie not set. +delete $ENV{HTTP_COOKIE}; +$output = $guide->display_node( id => "Ship Of Fools", return_output => 1 ); +like( $output, qr/You are not logged in./, + "...but not if no username is set." );
Copied: trunk/t/902_node_name_from_cgi_obj.t (from rev 1381, trunk/t/92_node_name_from_cgi_obj.t) =================================================================== --- trunk/t/902_node_name_from_cgi_obj.t (rev 0) +++ trunk/t/902_node_name_from_cgi_obj.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,101 @@ +use strict; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 18; + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Write a node. +OpenGuides::Test->write_data( + guide => $guide, + node => "Ship Of Fools", + return_output => 1, + ); + +my ( $q, $node, $param ); + +# Test we get the right name/param with various CGI objects. Make sure to +# always start with an empty one by passing the empty string as arg. + +$q = CGI->new( "" ); +$q->param( -name => "id", -value => "Ship_Of_Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", + "extract_node_name gives correct name with id param" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship_Of_Fools", "...as does extract_node_param" ); + +$q = CGI->new( "" ); +$q->param( -name => "title", -value => "Ship_Of_Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", "title param works for node name" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship_Of_Fools", "...and for node param" ); + +$q = CGI->new( "Ship_Of_Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", "whole-string node param works for node name" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship_Of_Fools", "...and for node param" ); + +# Now try it with encoded spaces instead of underscores. +$q = CGI->new( "" ); +$q->param( -name => "id", -value => "Ship%20Of%20Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", + "id param works for node name with encoded spaces" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship Of Fools", "...as does node param" ); + +$q = CGI->new( "" ); +$q->param( -name => "title", -value => "Ship%20Of%20Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", + "title param works for node name with encoded spaces" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship Of Fools", "...as does node param" ); + +$q = CGI->new( "Ship%20Of%20Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", + "whole-string node param works for node name with encoded spaces" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship Of Fools", "...as does node param" ); + +# Finally try it with plus signs. +$q = CGI->new( "" ); +$q->param( -name => "id", -value => "Ship+Of+Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", "id param works for node name with plus signs" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship Of Fools", "...as does node param" ); + +$q = CGI->new( "" ); +$q->param( -name => "title", -value => "Ship+Of+Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", + "title param works for node name with plus signs" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship Of Fools", "...as does node param" ); + +$q = CGI->new( "Ship+Of+Fools" ); +$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); +is( $node, "Ship Of Fools", + "whole-string node param works for node name with plus signs" ); +$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); +is( $param, "Ship Of Fools", "...as does node param" );
Copied: trunk/t/903_redirect_without_spaces.t (from rev 1381, trunk/t/93_redirect_without_spaces.t) =================================================================== --- trunk/t/903_redirect_without_spaces.t (rev 0) +++ trunk/t/903_redirect_without_spaces.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,139 @@ +use strict; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 27; + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Write a couple of nodes, one with a single-word name, one with multiple. +OpenGuides::Test->write_data( + guide => $guide, + node => "Croydon", + return_output => 1, + ); +OpenGuides::Test->write_data( + guide => $guide, + node => "Ship Of Fools", + return_output => 1, + ); + +my ( $q, $url ); + +# Check we don't get redirects with the single-word node. + +$q = CGI->new( "" ); +$q->param( -name => "id", -value => "Croydon" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( !$url, "No URL redirect for id param with single-word node" ); + +$q = CGI->new( "" ); +$q->param( -name => "title", -value => "Croydon" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( !$url, "...nor for title param" ); + +$q = CGI->new( "Croydon" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( !$url, "...nor for whole-string param" ); + +# Nor with the "proper" URLs with underscores. + +$q = CGI->new( "" ); +$q->param( -name => "id", -value => "Ship_Of_Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( !$url, "No URL redirect for id param with underscores" ); + +$q = CGI->new( "" ); +$q->param( -name => "title", -value => "Ship_Of_Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( !$url, "...nor for title param with underscores" ); + +$q = CGI->new( "Ship_Of_Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( !$url, "...nor for whole-string node param with underscores" ); + +# Now check that we get redirects when supplying CGI objects with spaces +# in the node parameter. + +# First encoded spaces. + +$q = CGI->new( "" ); +$q->param( -name => "id", -value => "Ship%20Of%20Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "We do get a redirect for id param with encoded spaces" ); +is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); +$q->param( -name => "action", -value => "edit" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "...also get redirect with edit param" ); +is( $url, "http://localhost?id=Ship_Of_Fools;action=edit", + "...the right one" ); + +$q = CGI->new( "" ); +$q->param( -name => "title", -value => "Ship%20Of%20Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "...also get redirect for title param with encoded spaces" ); +is( $url, "http://localhost?title=Ship_Of_Fools", "...the right one" ); +$q->param( -name => "action", -value => "edit" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "...also get redirect with edit param" ); +is( $url, "http://localhost?title=Ship_Of_Fools;action=edit", + "...the right one" ); + +$q = CGI->new( "Ship%20Of%20Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, + "...also get redirect for whole-string node param with encoded spaces" ); +is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); + +# Try it with plus signs. + +$q = CGI->new( "" ); +$q->param( -name => "id", -value => "Ship+Of+Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "We do get a redirect for id param with plus signs" ); +is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); +$q->param( -name => "action", -value => "edit" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "...also get redirect with edit param" ); +is( $url, "http://localhost?id=Ship_Of_Fools;action=edit", + "...the right one" ); + +$q = CGI->new( "" ); +$q->param( -name => "title", -value => "Ship+Of+Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "...and for title param with plus signs" ); +is( $url, "http://localhost?title=Ship_Of_Fools", "...the right one" ); +$q->param( -name => "action", -value => "edit" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "...also get redirect with edit param" ); +is( $url, "http://localhost?title=Ship_Of_Fools;action=edit", + "...the right one" ); + +$q = CGI->new( "Ship+Of+Fools" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +ok( $url, "...and for whole-string node param with plus signs" ); +is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); + +# Make sure commas don't get escaped, for it is unnecessary and ugly. +OpenGuides::Test->write_data( + guide => $guide, + node => "Londis, Pitlake", + return_output => 1, + ); +$q = CGI->new( "Londis, Pitlake" ); +$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); +is( $url, "http://localhost?id=Londis,_Pitlake", "Commas don't get escaped." );
Copied: trunk/t/904_leaflet.t (from rev 1381, trunk/t/94_leaflet.t) =================================================================== --- trunk/t/904_leaflet.t (rev 0) +++ trunk/t/904_leaflet.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,175 @@ +use strict; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +plan tests => 23; + +my $config = OpenGuides::Test->make_basic_config; +$config->static_url( "http://example.com/static" ); +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Write a couple of nodes, two with legitimate geodata, another with +# broken geodata, another with no geodata. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + address => "High Street", + latitude => 51.4, + longitude => -0.2, + locales => "Croydon\r\nWaddon", + return_output => 1, + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Blue Lion", + latitude => 51.6, + longitude => 0.6, + locales => "Croydon", + return_output => 1, + ); + +# We have to write this one using Wiki::Toolkit, since OpenGuides now has +# checks for bad geodata - but we still want to test it, since someone might +# have old data in their database. +$wiki->write_node( "Broken Lion", "Here is some content.", undef, { + latitude => "51d 32m 31.94s", + longitude => "0d 0m 8.23s", + locale => "Croydon" + } ) + or die "Can't write node."; + +OpenGuides::Test->write_data( + guide => $guide, + node => "Lost Lion", + locales => "Croydon\r\nAddiscombe", + return_output => 1, + ); + +# Make sure we include the GMaps JavaScript if we're not using Leaflet and +# we've included an API key. +$config->use_leaflet( 0 ); +$config->gmaps_api_key( "I like using deprecated code" ); + +my $output = $guide->display_node( id => "Red Lion", return_output => 1 ); +like( $output, qr/<script.*I like using deprecated code/, + "GMaps JavaScript included when Leaflet switched off and GMaps API key " + . "supplied." ); + +# Conversely, if we are using Leaflet then we need its JS but not GMaps', and +# we also need our own. +$config->use_leaflet( 1 ); +$output = $guide->display_node( id => "Red Lion", return_output => 1 ); +unlike( $output, qr/<script.*I like using deprecated code/, + "...but not when Leaflet switched on." ); +like( $output, qr|http://code.leafletjs.com/.*leaflet.js%7C, + "Leaflet JavaScript is included when Leaflet switched on." ); +like( $output, qr|http://example.com/static/map-leaflet.js%7C, + "...as is our own Leaflet map JavaScript." ); + +# Make sure the map doesn't try to show nodes with missing or broken geodata. +my %tt_vars = $guide->show_index( loc => "Croydon", + format => "map", return_tt_vars => 1 ); +my @nodes = @{$tt_vars{nodes}}; +is( scalar @nodes, 4, "Right number of nodes in TT variables." ); +my %node_hash = map { $_->{name} => $_ } @nodes; +ok( !$node_hash{"Broken Lion"}{has_geodata}, + "Nodes with broken geodata don't have has_geodata set." ); +ok( !$node_hash{"Lost Lion"}{has_geodata}, + "Nodes with no geodata don't have has_geodata set." ); + +# And check again in the HTML, in case of template bugs. +$output = $guide->show_index( loc => "Croydon", + format => "map", return_output => 1 ); +unlike( $output, qr|name:\s*Lost\s+Lion|, + "Nodes with no geodata are not passed to JavaScript object." ); + +# Check geodata variables for nodes that do have such data. +ok( $node_hash{"Red Lion"}{has_geodata}, + "Nodes with geodata have has_geodata set" ); +ok( $node_hash{"Red Lion"}{wgs84_lat}, + "Nodes with geodata have wgs84_lat set" ); +ok( $node_hash{"Red Lion"}{wgs84_long}, + "Nodes with geodata have wgs84_long set" ); + +# Make sure the centre of the map is set properly. +is( $tt_vars{centre_lat}, 51.5, "centre_lat set correctly" ); +is( $tt_vars{centre_long}, 0.2, "centre_long set correctly" ); + +# Make sure name and address are passed through to the JavaScript for adding +# markers to the map. +$output = $guide->show_index( loc => "Waddon", + format => "map", return_output => 1 ); +like( $output, qr/name:\s*["']Red\s+Lion["']/, + "Name added to JavaScript object." ); +like( $output, qr/address:\s*["']High\s+Street["']/, + "Address added to JavaScript object." ); + +# Make sure nodes with no geodata get linked to despite not being on the map. +$output = $guide->show_index( loc => "Addiscombe", + format => "map", return_output => 1 ); +like( $output, qr|Lost_Lion|, "Nodes with no geodata still get linked." ); + +# Make sure nodes with zero lat or long still have has_geodata set. +OpenGuides::Test->write_data( + guide => $guide, + node => "Zero Lat", + latitude => 0, + longitude => -0.2, + locales => "Zero Land", + categories => "Numerical Nodes", + return_output => 1, + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Zero Long", + latitude => 51.6, + longitude => 0, + locales => "Zero Land", + return_output => 1, + ); + +%tt_vars = $guide->show_index( loc => "Zero Land", + format => "map", return_tt_vars => 1 ); +@nodes = @{$tt_vars{nodes}}; +%node_hash = map { $_->{name} => $_ } @nodes; +ok( $node_hash{"Zero Lat"}{has_geodata}, + "Nodes with zero latitude have has_geodata set." ); +ok( $node_hash{"Zero Long"}{has_geodata}, + "Nodes with zero longitude have has_geodata set." ); + +# Check capitalisation. +$output = $guide->show_index( cat => "numerical nodes", + format => "map", return_output => 1 ); +like( $output, qr/Category\s+Numerical\s+Nodes/, + "Multi-word categories are capitalised properly." ); +$output = $guide->show_index( loc => "zero land", + format => "map", return_output => 1 ); +like( $output, qr/Locale\s+Zero\s+Land/, + "Multi-word locales are capitalised properly." ); + +# Map shouldn't be displayed if none of the nodes have geodata. +%tt_vars = $guide->show_index( loc => "Addiscombe", + format => "map", return_tt_vars => 1 ); +ok( $tt_vars{no_nodes_on_map}, + "no_nodes_on_map template variable is set when no nodes have geodata" ); +$output = $guide->show_index( loc => "Addiscombe", + format => "map", return_output => 1 ); +unlike( $output, qr/not on map/, + "...and no warning about individual things not being on the map" ); +unlike( $output, qr/centre_lat/, + "...and no attempt to set centre_lat JavaScript variable" );
Copied: trunk/t/905_multiple_index.t (from rev 1381, trunk/t/95_multiple_index.t) =================================================================== --- trunk/t/905_multiple_index.t (rev 0) +++ trunk/t/905_multiple_index.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,121 @@ +use strict; +use JSON; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => + "DBD::SQLite could not be used - no database to test with. ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not available."; +} + +plan tests => 18; + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); +my $wiki = $guide->wiki; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +# Write some nodes. +OpenGuides::Test->write_data( + guide => $guide, + node => "Red Lion", + locales => "Croydon", + categories => "Pubs", + return_output => 1, + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Blue Lion", + locales => "Waddon", + categories => "Pubs", + return_output => 1, + ); + +OpenGuides::Test->write_data( + guide => $guide, + node => "Blue Ribbon", + locales => "Waddon", + categories => "Shops", + return_output => 1, + ); + +my %tt_vars = $guide->show_index( cat => "pubs", return_tt_vars => 1 ); +is( scalar @{$tt_vars{nodes}}, 2, + "Right number of nodes returned in pure category search" ); +my $output = $guide->show_index( cat => "pubs", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::title_ok( $output, "Index of Category Pubs - Test", + "...and page title is correct" ); +Test::HTML::Content::link_ok( $output, $config->script_name . "?Category_Pubs", + "...and we link to the category page." ); + +%tt_vars = $guide->show_index( loc => "waddon", return_tt_vars => 1 ); +is( scalar @{$tt_vars{nodes}}, 2, + "Right number of nodes returned in pure locale search" ); +$output = $guide->show_index( loc => "waddon", return_output => 1, + noheaders => 1 ); +Test::HTML::Content::title_ok( $output, "Index of Locale Waddon - Test", + "...and page title is correct" ); +Test::HTML::Content::link_ok( $output, $config->script_name . "?Locale_Waddon", + "...and we link to the locale page." ); + +%tt_vars = $guide->show_index( cat => "pubs", loc => "waddon", + return_tt_vars => 1 ); +is( scalar @{$tt_vars{nodes}}, 1, + "Right number of nodes returned in category+locale search" ); +$output = $guide->show_index( cat => "pubs", loc => "waddon", + return_output => 1, noheaders => 1 ); +Test::HTML::Content::title_ok( $output, + "Index of Category Pubs and Locale Waddon - Test", + "...and page title is correct" ); +Test::HTML::Content::link_ok( $output, $config->script_name . "?Category_Pubs", + "...and we link to the category page." ); +Test::HTML::Content::link_ok( $output, $config->script_name . "?Locale_Waddon", + "...and we link to the locale page." ); + +# Test the map version. +$config->use_leaflet( 1 ); +%tt_vars = $guide->show_index( cat => "pubs", loc => "waddon", format => "map", + return_tt_vars => 1 ); +is( scalar @{$tt_vars{nodes}}, 1, + "Right number of nodes returned in category+locale search with map" ); +$output = $guide->show_index( cat => "pubs", loc => "waddon", format => "map", + return_output => 1, noheaders => 1 ); +Test::HTML::Content::title_ok( $output, + "Map of Category Pubs and Locale Waddon - Test", + "...and page title is correct" ); +Test::HTML::Content::link_ok( $output, $config->script_name . "?Category_Pubs", + "...and we link to the category page." ); +Test::HTML::Content::link_ok( $output, $config->script_name . "?Locale_Waddon", + "...and we link to the locale page." ); + +# Test the RDF version. +$output = $guide->show_index( cat => "pubs", loc => "waddon", format => "rdf", + return_output => 1 ); +like( $output, + qr|dc:titleCategory Pubs and Locale Waddon</dc:title>|, + "Page title is correct on RDF version." ); + +# Test the JSON version. +$output = $guide->show_index( cat => "pubs", loc => "waddon", format => "json", + return_output => 1, noheaders => 1 ); +unlike( $output, qr/error/i, "JSON format invocation doesn't cause error." ); + +my $parsed = eval { + local $SIG{__WARN__} = sub { die $_[0]; }; + decode_json( $output ); +}; +ok( !$@, "...and its output looks like JSON." ); +is( scalar @$parsed, 1, "...and has the right number of nodes." );
Copied: trunk/t/906_show_index_form.t (from rev 1381, trunk/t/96_show_index_form.t) =================================================================== --- trunk/t/906_show_index_form.t (rev 0) +++ trunk/t/906_show_index_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,168 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Test; +use Test::More; + +eval { require DBD::SQLite; }; +if ( $@ ) { + my ($error) = $@ =~ /^(.*?)\n/; + plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; +} + +eval { require Test::HTML::Content; }; +if ( $@ ) { + plan skip_all => "Test::HTML::Content not available"; +} + +plan tests => 40; + +# Clear out the database from any previous runs. +OpenGuides::Test::refresh_db(); + +my $config = OpenGuides::Test->make_basic_config; +my $guide = OpenGuides->new( config => $config ); + +# Write some nodes with categories and things. +OpenGuides::Test->write_data( guide => $guide, node => "A Node", + categories => "Apples\r\nBananas\r\nCherries", + locales => "Anerley\r\nBrockley\r\nChiswick", + return_output => 1 ); + +# Test the form for altering the search - first with no criteria. +my @dropdowns = eval { + OpenGuides::CGI->make_index_form_dropdowns( guide => $guide ); +}; +ok( !$@, "->make_index_form_dropdowns doesn't die when no criteria supplied" ); +my $html = join( " ", ( map { $_->{html} } @dropdowns ) ); +Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, + "...and we have a 'cat' select" ); +like( $html, qr/apples.*bananas.*cherries/is, + "...and the categories seem to be in the right order" ); +Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, + "...and we have a 'loc' select" ); +like( $html, qr/anerley.*brockley.*chiswick/is, + "...and the locales seem to be in the right order" ); +ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", + "...and category dropdown comes before locale dropdown" ); +my @cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; +my @loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; +Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...and the empty value is selected for category" ); +Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...and the empty value is selected for locale" ); + +# Now try it with one category, no locale. +@dropdowns = eval { + OpenGuides::CGI->make_index_form_dropdowns( + guide => $guide, + selected => [ { type => "category", value => "bananas" } ], + ); +}; +ok( !$@, "->make_index_form_dropdowns doesn't die when category supplied" ); +$html = join( " ", ( map { $_->{html} } @dropdowns ) ); +Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, + "...and we have a 'cat' select" ); +like( $html, qr/apples.*bananas.*cherries/is, + "...and the categories seem to be in the right order" ); +Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, + "...and we have a 'loc' select" ); +like( $html, qr/anerley.*brockley.*chiswick/is, + "...and the locales seem to be in the right order" ); +ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", + "...and category dropdown comes before locale dropdown" ); +@cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; +@loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; +Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", + { value => "bananas", selected => "selected" }, + "...and the category is selected" ); +Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", + { value => "" }, + "...and the empty value is present in the category dropdown" ); +Test::HTML::Content::no_tag( $cat_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...but not selected" ); +Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...and the empty value is selected for locale" ); + +# Now with one locale, no category. +@dropdowns = eval { + OpenGuides::CGI->make_index_form_dropdowns( + guide => $guide, + selected => [ { type => "locale", value => "anerley" } ], + ); +}; +ok( !$@, "->make_index_form_dropdowns doesn't die when locale supplied" ); +$html = join( " ", ( map { $_->{html} } @dropdowns ) ); +Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, + "...and we have a 'cat' select" ); +like( $html, qr/apples.*bananas.*cherries/is, + "...and the categories seem to be in the right order" ); +Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, + "...and we have a 'loc' select" ); +like( $html, qr/anerley.*brockley.*chiswick/is, + "...and the locales seem to be in the right order" ); +ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", + "...and category dropdown comes before locale dropdown" ); +@cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; +@loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; +Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", + { value => "anerley", selected => "selected" }, + "...and the locale is selected" ); +Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", + { value => "" }, + "...and the empty value is present in the locale dropdown" ); +Test::HTML::Content::no_tag( $loc_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...but not selected" ); +Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...and the empty value is selected for category" ); + +# Now test with a category and a locale. +@dropdowns = eval { + OpenGuides::CGI->make_index_form_dropdowns( + guide => $guide, + selected => [ + { type => "category", value => "cherries" }, + { type => "locale", value => "chiswick" }, + ], + ); +}; +ok( !$@, + "->make_index_form_dropdowns doesn't die when locale and categorysupplied" ); +$html = join( " ", ( map { $_->{html} } @dropdowns ) ); +Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, + "...and we have a 'cat' select" ); +like( $html, qr/apples.*bananas.*cherries/is, + "...and the categories seem to be in the right order" ); +Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, + "...and we have a 'loc' select" ); +like( $html, qr/anerley.*brockley.*chiswick/is, + "...and the locales seem to be in the right order" ); +ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", + "...and category dropdown comes before locale dropdown" ); +@cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; +@loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; +Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", + { value => "cherries", selected => "selected" }, + "...and the category is selected" ); +Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", + { value => "" }, + "...and the empty value is present in the category dropdown" ); +Test::HTML::Content::no_tag( $cat_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...but not selected" ); +Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", + { value => "chiswick", selected => "selected" }, + "...and the locale is selected" ); +Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", + { value => "" }, + "...and the empty value is present in the locale dropdown" ); +Test::HTML::Content::no_tag( $loc_dropdowns[0]{html}, "option", + { value => "", selected => "selected" }, + "...but not selected" );
Deleted: trunk/t/90_css_category_locale_classes.t =================================================================== --- trunk/t/90_css_category_locale_classes.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/90_css_category_locale_classes.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,65 +0,0 @@ -use strict; -use Cwd; -use OpenGuides; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not installed"; -} - -plan tests => 3; - -my $config = OpenGuides::Test->make_basic_config; -$config->custom_template_path( cwd . "/t/templates/" ); -my $guide = OpenGuides->new( config => $config ); - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Check that a node in one locale and one category has CSS classes for both. -OpenGuides::Test->write_data( - guide => $guide, - node => "Crown", - categories => "Pubs", - locales => "Cornmarket", - return_output => 1, - ); - -my $output = $guide->display_node( id => "Crown", return_output => 1, - noheaders => 1 ); -Test::HTML::Content::tag_ok( $output, "div", - { id => "content", class => "cat_pubs loc_cornmarket" }, - "Node in one locale and one category has CSS classes for both." ); - -# Check that spaces in locale/category names are replaced by underscores. -OpenGuides::Test->write_data( - guide => $guide, - node => "Debenhams", - categories => "Baby Changing", - locales => "Magdalen Street", - return_output => 1, - ); -$output = $guide->display_node( id => "Debenhams", return_output => 1, - noheaders => 1 ); -Test::HTML::Content::tag_ok( $output, "div", - { id => "content", class => "cat_baby_changing loc_magdalen_street" }, - "...and spaces in locale/category names are replaced by underscores." ); - -# Check that nodes with no locales or categories don't have classes added. -OpenGuides::Test->write_data( - guide => $guide, - node => "A Blank Node", - return_output => 1, - ); -$output = $guide->display_node( id => "A Blank Node", return_output => 1 ); -like( $output, qr|<div id="content">|, - "Nodes with no locales or categories don't have classes added." );
Deleted: trunk/t/91_username_in_templates.t =================================================================== --- trunk/t/91_username_in_templates.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/91_username_in_templates.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,67 +0,0 @@ -use strict; -use Cwd; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 2; - -my $config = OpenGuides::Test->make_basic_config; -$config->custom_template_path( cwd . "/t/templates/tmp/" ); -my $guide = OpenGuides->new( config => $config ); - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Write a node. -OpenGuides::Test->write_data( - guide => $guide, - node => "Ship Of Fools", - return_output => 1, - ); -# Make sure the tmp directory exists -eval { - mkdir cwd . "/t/templates/tmp"; -}; -# Write a custom banner template that includes the username. -eval { - unlink cwd . "/t/templates/tmp/custom_banner.tt"; -}; - -open( my $fh, ">", cwd . "/t/templates/tmp/custom_banner.tt" ) or die $!; -print $fh <<EOF; -<div class="banner_username"> - [% IF username %] - You are logged in as [% username %]. - [% ELSE %] - You are not logged in. - [% END %] -</div> -EOF -close $fh or die $!; - -# Set a username in the cookie. -my $cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - username => "Kake", -); -$ENV{HTTP_COOKIE} = $cookie; - -# Check that username appears if cookie is set. -my $output = $guide->display_node( id => "Ship Of Fools", return_output => 1 ); -like( $output, qr/You are logged in as Kake./, - "username sent to templates if set in prefs cookie" ); - -# Check that username doesn't appear if cookie not set. -delete $ENV{HTTP_COOKIE}; -$output = $guide->display_node( id => "Ship Of Fools", return_output => 1 ); -like( $output, qr/You are not logged in./, - "...but not if no username is set." );
Deleted: trunk/t/92_node_name_from_cgi_obj.t =================================================================== --- trunk/t/92_node_name_from_cgi_obj.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/92_node_name_from_cgi_obj.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,101 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 18; - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Write a node. -OpenGuides::Test->write_data( - guide => $guide, - node => "Ship Of Fools", - return_output => 1, - ); - -my ( $q, $node, $param ); - -# Test we get the right name/param with various CGI objects. Make sure to -# always start with an empty one by passing the empty string as arg. - -$q = CGI->new( "" ); -$q->param( -name => "id", -value => "Ship_Of_Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", - "extract_node_name gives correct name with id param" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship_Of_Fools", "...as does extract_node_param" ); - -$q = CGI->new( "" ); -$q->param( -name => "title", -value => "Ship_Of_Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", "title param works for node name" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship_Of_Fools", "...and for node param" ); - -$q = CGI->new( "Ship_Of_Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", "whole-string node param works for node name" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship_Of_Fools", "...and for node param" ); - -# Now try it with encoded spaces instead of underscores. -$q = CGI->new( "" ); -$q->param( -name => "id", -value => "Ship%20Of%20Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", - "id param works for node name with encoded spaces" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship Of Fools", "...as does node param" ); - -$q = CGI->new( "" ); -$q->param( -name => "title", -value => "Ship%20Of%20Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", - "title param works for node name with encoded spaces" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship Of Fools", "...as does node param" ); - -$q = CGI->new( "Ship%20Of%20Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", - "whole-string node param works for node name with encoded spaces" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship Of Fools", "...as does node param" ); - -# Finally try it with plus signs. -$q = CGI->new( "" ); -$q->param( -name => "id", -value => "Ship+Of+Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", "id param works for node name with plus signs" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship Of Fools", "...as does node param" ); - -$q = CGI->new( "" ); -$q->param( -name => "title", -value => "Ship+Of+Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", - "title param works for node name with plus signs" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship Of Fools", "...as does node param" ); - -$q = CGI->new( "Ship+Of+Fools" ); -$node = OpenGuides::CGI->extract_node_name( cgi_obj => $q, wiki => $wiki ); -is( $node, "Ship Of Fools", - "whole-string node param works for node name with plus signs" ); -$param = OpenGuides::CGI->extract_node_param( cgi_obj => $q, wiki => $wiki ); -is( $param, "Ship Of Fools", "...as does node param" );
Deleted: trunk/t/93_redirect_without_spaces.t =================================================================== --- trunk/t/93_redirect_without_spaces.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/93_redirect_without_spaces.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,139 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 27; - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Write a couple of nodes, one with a single-word name, one with multiple. -OpenGuides::Test->write_data( - guide => $guide, - node => "Croydon", - return_output => 1, - ); -OpenGuides::Test->write_data( - guide => $guide, - node => "Ship Of Fools", - return_output => 1, - ); - -my ( $q, $url ); - -# Check we don't get redirects with the single-word node. - -$q = CGI->new( "" ); -$q->param( -name => "id", -value => "Croydon" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( !$url, "No URL redirect for id param with single-word node" ); - -$q = CGI->new( "" ); -$q->param( -name => "title", -value => "Croydon" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( !$url, "...nor for title param" ); - -$q = CGI->new( "Croydon" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( !$url, "...nor for whole-string param" ); - -# Nor with the "proper" URLs with underscores. - -$q = CGI->new( "" ); -$q->param( -name => "id", -value => "Ship_Of_Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( !$url, "No URL redirect for id param with underscores" ); - -$q = CGI->new( "" ); -$q->param( -name => "title", -value => "Ship_Of_Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( !$url, "...nor for title param with underscores" ); - -$q = CGI->new( "Ship_Of_Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( !$url, "...nor for whole-string node param with underscores" ); - -# Now check that we get redirects when supplying CGI objects with spaces -# in the node parameter. - -# First encoded spaces. - -$q = CGI->new( "" ); -$q->param( -name => "id", -value => "Ship%20Of%20Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "We do get a redirect for id param with encoded spaces" ); -is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); -$q->param( -name => "action", -value => "edit" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "...also get redirect with edit param" ); -is( $url, "http://localhost?id=Ship_Of_Fools;action=edit", - "...the right one" ); - -$q = CGI->new( "" ); -$q->param( -name => "title", -value => "Ship%20Of%20Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "...also get redirect for title param with encoded spaces" ); -is( $url, "http://localhost?title=Ship_Of_Fools", "...the right one" ); -$q->param( -name => "action", -value => "edit" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "...also get redirect with edit param" ); -is( $url, "http://localhost?title=Ship_Of_Fools;action=edit", - "...the right one" ); - -$q = CGI->new( "Ship%20Of%20Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, - "...also get redirect for whole-string node param with encoded spaces" ); -is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); - -# Try it with plus signs. - -$q = CGI->new( "" ); -$q->param( -name => "id", -value => "Ship+Of+Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "We do get a redirect for id param with plus signs" ); -is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); -$q->param( -name => "action", -value => "edit" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "...also get redirect with edit param" ); -is( $url, "http://localhost?id=Ship_Of_Fools;action=edit", - "...the right one" ); - -$q = CGI->new( "" ); -$q->param( -name => "title", -value => "Ship+Of+Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "...and for title param with plus signs" ); -is( $url, "http://localhost?title=Ship_Of_Fools", "...the right one" ); -$q->param( -name => "action", -value => "edit" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "...also get redirect with edit param" ); -is( $url, "http://localhost?title=Ship_Of_Fools;action=edit", - "...the right one" ); - -$q = CGI->new( "Ship+Of+Fools" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -ok( $url, "...and for whole-string node param with plus signs" ); -is( $url, "http://localhost?id=Ship_Of_Fools", "...the right one" ); - -# Make sure commas don't get escaped, for it is unnecessary and ugly. -OpenGuides::Test->write_data( - guide => $guide, - node => "Londis, Pitlake", - return_output => 1, - ); -$q = CGI->new( "Londis, Pitlake" ); -$url = OpenGuides::CGI->check_spaces_redirect( cgi_obj => $q, wiki => $wiki ); -is( $url, "http://localhost?id=Londis,_Pitlake", "Commas don't get escaped." );
Deleted: trunk/t/94_leaflet.t =================================================================== --- trunk/t/94_leaflet.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/94_leaflet.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,175 +0,0 @@ -use strict; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -plan tests => 23; - -my $config = OpenGuides::Test->make_basic_config; -$config->static_url( "http://example.com/static" ); -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Write a couple of nodes, two with legitimate geodata, another with -# broken geodata, another with no geodata. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - address => "High Street", - latitude => 51.4, - longitude => -0.2, - locales => "Croydon\r\nWaddon", - return_output => 1, - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Blue Lion", - latitude => 51.6, - longitude => 0.6, - locales => "Croydon", - return_output => 1, - ); - -# We have to write this one using Wiki::Toolkit, since OpenGuides now has -# checks for bad geodata - but we still want to test it, since someone might -# have old data in their database. -$wiki->write_node( "Broken Lion", "Here is some content.", undef, { - latitude => "51d 32m 31.94s", - longitude => "0d 0m 8.23s", - locale => "Croydon" - } ) - or die "Can't write node."; - -OpenGuides::Test->write_data( - guide => $guide, - node => "Lost Lion", - locales => "Croydon\r\nAddiscombe", - return_output => 1, - ); - -# Make sure we include the GMaps JavaScript if we're not using Leaflet and -# we've included an API key. -$config->use_leaflet( 0 ); -$config->gmaps_api_key( "I like using deprecated code" ); - -my $output = $guide->display_node( id => "Red Lion", return_output => 1 ); -like( $output, qr/<script.*I like using deprecated code/, - "GMaps JavaScript included when Leaflet switched off and GMaps API key " - . "supplied." ); - -# Conversely, if we are using Leaflet then we need its JS but not GMaps', and -# we also need our own. -$config->use_leaflet( 1 ); -$output = $guide->display_node( id => "Red Lion", return_output => 1 ); -unlike( $output, qr/<script.*I like using deprecated code/, - "...but not when Leaflet switched on." ); -like( $output, qr|http://code.leafletjs.com/.*leaflet.js%7C, - "Leaflet JavaScript is included when Leaflet switched on." ); -like( $output, qr|http://example.com/static/map-leaflet.js%7C, - "...as is our own Leaflet map JavaScript." ); - -# Make sure the map doesn't try to show nodes with missing or broken geodata. -my %tt_vars = $guide->show_index( loc => "Croydon", - format => "map", return_tt_vars => 1 ); -my @nodes = @{$tt_vars{nodes}}; -is( scalar @nodes, 4, "Right number of nodes in TT variables." ); -my %node_hash = map { $_->{name} => $_ } @nodes; -ok( !$node_hash{"Broken Lion"}{has_geodata}, - "Nodes with broken geodata don't have has_geodata set." ); -ok( !$node_hash{"Lost Lion"}{has_geodata}, - "Nodes with no geodata don't have has_geodata set." ); - -# And check again in the HTML, in case of template bugs. -$output = $guide->show_index( loc => "Croydon", - format => "map", return_output => 1 ); -unlike( $output, qr|name:\s*Lost\s+Lion|, - "Nodes with no geodata are not passed to JavaScript object." ); - -# Check geodata variables for nodes that do have such data. -ok( $node_hash{"Red Lion"}{has_geodata}, - "Nodes with geodata have has_geodata set" ); -ok( $node_hash{"Red Lion"}{wgs84_lat}, - "Nodes with geodata have wgs84_lat set" ); -ok( $node_hash{"Red Lion"}{wgs84_long}, - "Nodes with geodata have wgs84_long set" ); - -# Make sure the centre of the map is set properly. -is( $tt_vars{centre_lat}, 51.5, "centre_lat set correctly" ); -is( $tt_vars{centre_long}, 0.2, "centre_long set correctly" ); - -# Make sure name and address are passed through to the JavaScript for adding -# markers to the map. -$output = $guide->show_index( loc => "Waddon", - format => "map", return_output => 1 ); -like( $output, qr/name:\s*["']Red\s+Lion["']/, - "Name added to JavaScript object." ); -like( $output, qr/address:\s*["']High\s+Street["']/, - "Address added to JavaScript object." ); - -# Make sure nodes with no geodata get linked to despite not being on the map. -$output = $guide->show_index( loc => "Addiscombe", - format => "map", return_output => 1 ); -like( $output, qr|Lost_Lion|, "Nodes with no geodata still get linked." ); - -# Make sure nodes with zero lat or long still have has_geodata set. -OpenGuides::Test->write_data( - guide => $guide, - node => "Zero Lat", - latitude => 0, - longitude => -0.2, - locales => "Zero Land", - categories => "Numerical Nodes", - return_output => 1, - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Zero Long", - latitude => 51.6, - longitude => 0, - locales => "Zero Land", - return_output => 1, - ); - -%tt_vars = $guide->show_index( loc => "Zero Land", - format => "map", return_tt_vars => 1 ); -@nodes = @{$tt_vars{nodes}}; -%node_hash = map { $_->{name} => $_ } @nodes; -ok( $node_hash{"Zero Lat"}{has_geodata}, - "Nodes with zero latitude have has_geodata set." ); -ok( $node_hash{"Zero Long"}{has_geodata}, - "Nodes with zero longitude have has_geodata set." ); - -# Check capitalisation. -$output = $guide->show_index( cat => "numerical nodes", - format => "map", return_output => 1 ); -like( $output, qr/Category\s+Numerical\s+Nodes/, - "Multi-word categories are capitalised properly." ); -$output = $guide->show_index( loc => "zero land", - format => "map", return_output => 1 ); -like( $output, qr/Locale\s+Zero\s+Land/, - "Multi-word locales are capitalised properly." ); - -# Map shouldn't be displayed if none of the nodes have geodata. -%tt_vars = $guide->show_index( loc => "Addiscombe", - format => "map", return_tt_vars => 1 ); -ok( $tt_vars{no_nodes_on_map}, - "no_nodes_on_map template variable is set when no nodes have geodata" ); -$output = $guide->show_index( loc => "Addiscombe", - format => "map", return_output => 1 ); -unlike( $output, qr/not on map/, - "...and no warning about individual things not being on the map" ); -unlike( $output, qr/centre_lat/, - "...and no attempt to set centre_lat JavaScript variable" );
Deleted: trunk/t/95_multiple_index.t =================================================================== --- trunk/t/95_multiple_index.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/95_multiple_index.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,121 +0,0 @@ -use strict; -use JSON; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => - "DBD::SQLite could not be used - no database to test with. ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not available."; -} - -plan tests => 18; - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); -my $wiki = $guide->wiki; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -# Write some nodes. -OpenGuides::Test->write_data( - guide => $guide, - node => "Red Lion", - locales => "Croydon", - categories => "Pubs", - return_output => 1, - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Blue Lion", - locales => "Waddon", - categories => "Pubs", - return_output => 1, - ); - -OpenGuides::Test->write_data( - guide => $guide, - node => "Blue Ribbon", - locales => "Waddon", - categories => "Shops", - return_output => 1, - ); - -my %tt_vars = $guide->show_index( cat => "pubs", return_tt_vars => 1 ); -is( scalar @{$tt_vars{nodes}}, 2, - "Right number of nodes returned in pure category search" ); -my $output = $guide->show_index( cat => "pubs", return_output => 1, - noheaders => 1 ); -Test::HTML::Content::title_ok( $output, "Index of Category Pubs - Test", - "...and page title is correct" ); -Test::HTML::Content::link_ok( $output, $config->script_name . "?Category_Pubs", - "...and we link to the category page." ); - -%tt_vars = $guide->show_index( loc => "waddon", return_tt_vars => 1 ); -is( scalar @{$tt_vars{nodes}}, 2, - "Right number of nodes returned in pure locale search" ); -$output = $guide->show_index( loc => "waddon", return_output => 1, - noheaders => 1 ); -Test::HTML::Content::title_ok( $output, "Index of Locale Waddon - Test", - "...and page title is correct" ); -Test::HTML::Content::link_ok( $output, $config->script_name . "?Locale_Waddon", - "...and we link to the locale page." ); - -%tt_vars = $guide->show_index( cat => "pubs", loc => "waddon", - return_tt_vars => 1 ); -is( scalar @{$tt_vars{nodes}}, 1, - "Right number of nodes returned in category+locale search" ); -$output = $guide->show_index( cat => "pubs", loc => "waddon", - return_output => 1, noheaders => 1 ); -Test::HTML::Content::title_ok( $output, - "Index of Category Pubs and Locale Waddon - Test", - "...and page title is correct" ); -Test::HTML::Content::link_ok( $output, $config->script_name . "?Category_Pubs", - "...and we link to the category page." ); -Test::HTML::Content::link_ok( $output, $config->script_name . "?Locale_Waddon", - "...and we link to the locale page." ); - -# Test the map version. -$config->use_leaflet( 1 ); -%tt_vars = $guide->show_index( cat => "pubs", loc => "waddon", format => "map", - return_tt_vars => 1 ); -is( scalar @{$tt_vars{nodes}}, 1, - "Right number of nodes returned in category+locale search with map" ); -$output = $guide->show_index( cat => "pubs", loc => "waddon", format => "map", - return_output => 1, noheaders => 1 ); -Test::HTML::Content::title_ok( $output, - "Map of Category Pubs and Locale Waddon - Test", - "...and page title is correct" ); -Test::HTML::Content::link_ok( $output, $config->script_name . "?Category_Pubs", - "...and we link to the category page." ); -Test::HTML::Content::link_ok( $output, $config->script_name . "?Locale_Waddon", - "...and we link to the locale page." ); - -# Test the RDF version. -$output = $guide->show_index( cat => "pubs", loc => "waddon", format => "rdf", - return_output => 1 ); -like( $output, - qr|dc:titleCategory Pubs and Locale Waddon</dc:title>|, - "Page title is correct on RDF version." ); - -# Test the JSON version. -$output = $guide->show_index( cat => "pubs", loc => "waddon", format => "json", - return_output => 1, noheaders => 1 ); -unlike( $output, qr/error/i, "JSON format invocation doesn't cause error." ); - -my $parsed = eval { - local $SIG{__WARN__} = sub { die $_[0]; }; - decode_json( $output ); -}; -ok( !$@, "...and its output looks like JSON." ); -is( scalar @$parsed, 1, "...and has the right number of nodes." );
Deleted: trunk/t/96_show_index_form.t =================================================================== --- trunk/t/96_show_index_form.t 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/96_show_index_form.t 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,168 +0,0 @@ -use strict; -use Wiki::Toolkit::Setup::SQLite; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Test; -use Test::More; - -eval { require DBD::SQLite; }; -if ( $@ ) { - my ($error) = $@ =~ /^(.*?)\n/; - plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; -} - -eval { require Test::HTML::Content; }; -if ( $@ ) { - plan skip_all => "Test::HTML::Content not available"; -} - -plan tests => 40; - -# Clear out the database from any previous runs. -OpenGuides::Test::refresh_db(); - -my $config = OpenGuides::Test->make_basic_config; -my $guide = OpenGuides->new( config => $config ); - -# Write some nodes with categories and things. -OpenGuides::Test->write_data( guide => $guide, node => "A Node", - categories => "Apples\r\nBananas\r\nCherries", - locales => "Anerley\r\nBrockley\r\nChiswick", - return_output => 1 ); - -# Test the form for altering the search - first with no criteria. -my @dropdowns = eval { - OpenGuides::CGI->make_index_form_dropdowns( guide => $guide ); -}; -ok( !$@, "->make_index_form_dropdowns doesn't die when no criteria supplied" ); -my $html = join( " ", ( map { $_->{html} } @dropdowns ) ); -Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, - "...and we have a 'cat' select" ); -like( $html, qr/apples.*bananas.*cherries/is, - "...and the categories seem to be in the right order" ); -Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, - "...and we have a 'loc' select" ); -like( $html, qr/anerley.*brockley.*chiswick/is, - "...and the locales seem to be in the right order" ); -ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", - "...and category dropdown comes before locale dropdown" ); -my @cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; -my @loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; -Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...and the empty value is selected for category" ); -Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...and the empty value is selected for locale" ); - -# Now try it with one category, no locale. -@dropdowns = eval { - OpenGuides::CGI->make_index_form_dropdowns( - guide => $guide, - selected => [ { type => "category", value => "bananas" } ], - ); -}; -ok( !$@, "->make_index_form_dropdowns doesn't die when category supplied" ); -$html = join( " ", ( map { $_->{html} } @dropdowns ) ); -Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, - "...and we have a 'cat' select" ); -like( $html, qr/apples.*bananas.*cherries/is, - "...and the categories seem to be in the right order" ); -Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, - "...and we have a 'loc' select" ); -like( $html, qr/anerley.*brockley.*chiswick/is, - "...and the locales seem to be in the right order" ); -ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", - "...and category dropdown comes before locale dropdown" ); -@cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; -@loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; -Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", - { value => "bananas", selected => "selected" }, - "...and the category is selected" ); -Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", - { value => "" }, - "...and the empty value is present in the category dropdown" ); -Test::HTML::Content::no_tag( $cat_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...but not selected" ); -Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...and the empty value is selected for locale" ); - -# Now with one locale, no category. -@dropdowns = eval { - OpenGuides::CGI->make_index_form_dropdowns( - guide => $guide, - selected => [ { type => "locale", value => "anerley" } ], - ); -}; -ok( !$@, "->make_index_form_dropdowns doesn't die when locale supplied" ); -$html = join( " ", ( map { $_->{html} } @dropdowns ) ); -Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, - "...and we have a 'cat' select" ); -like( $html, qr/apples.*bananas.*cherries/is, - "...and the categories seem to be in the right order" ); -Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, - "...and we have a 'loc' select" ); -like( $html, qr/anerley.*brockley.*chiswick/is, - "...and the locales seem to be in the right order" ); -ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", - "...and category dropdown comes before locale dropdown" ); -@cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; -@loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; -Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", - { value => "anerley", selected => "selected" }, - "...and the locale is selected" ); -Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", - { value => "" }, - "...and the empty value is present in the locale dropdown" ); -Test::HTML::Content::no_tag( $loc_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...but not selected" ); -Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...and the empty value is selected for category" ); - -# Now test with a category and a locale. -@dropdowns = eval { - OpenGuides::CGI->make_index_form_dropdowns( - guide => $guide, - selected => [ - { type => "category", value => "cherries" }, - { type => "locale", value => "chiswick" }, - ], - ); -}; -ok( !$@, - "->make_index_form_dropdowns doesn't die when locale and categorysupplied" ); -$html = join( " ", ( map { $_->{html} } @dropdowns ) ); -Test::HTML::Content::tag_ok( $html, "select", { name => "cat" }, - "...and we have a 'cat' select" ); -like( $html, qr/apples.*bananas.*cherries/is, - "...and the categories seem to be in the right order" ); -Test::HTML::Content::tag_ok( $html, "select", { name => "loc" }, - "...and we have a 'loc' select" ); -like( $html, qr/anerley.*brockley.*chiswick/is, - "...and the locales seem to be in the right order" ); -ok( $dropdowns[0]{type} eq "category" && $dropdowns[1]{type} eq "locale", - "...and category dropdown comes before locale dropdown" ); -@cat_dropdowns = grep { $_->{type} eq "category" } @dropdowns; -@loc_dropdowns = grep { $_->{type} eq "locale" } @dropdowns; -Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", - { value => "cherries", selected => "selected" }, - "...and the category is selected" ); -Test::HTML::Content::tag_ok( $cat_dropdowns[0]{html}, "option", - { value => "" }, - "...and the empty value is present in the category dropdown" ); -Test::HTML::Content::no_tag( $cat_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...but not selected" ); -Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", - { value => "chiswick", selected => "selected" }, - "...and the locale is selected" ); -Test::HTML::Content::tag_ok( $loc_dropdowns[0]{html}, "option", - { value => "" }, - "...and the empty value is present in the locale dropdown" ); -Test::HTML::Content::no_tag( $loc_dropdowns[0]{html}, "option", - { value => "", selected => "selected" }, - "...but not selected" );
Copied: trunk/t/templates/105_test.tt (from rev 1381, trunk/t/templates/15_test.tt) =================================================================== --- trunk/t/templates/105_test.tt (rev 0) +++ trunk/t/templates/105_test.tt 2012-05-05 10:27:25 UTC (rev 1382) @@ -0,0 +1,19 @@ +FOO: [% foo %] + +SITE NAME: [% site_name %] +CGI URL: [% cgi_url %] +FULL CGI URL: [% full_cgi_url %] +CONTACT EMAIL: [% contact_email %] +STYLESHEET: [% stylesheet %] +HOME LINK: [% home_link %] +HOME NAME: [% home_name %] + +OPENGUIDES VERSION: [% openguides_version %] + +NODE NAME: [% node_name %] +NODE PARAM: [% node_param %] + +FORMATTING RULES LINK: [% formatting_rules_link %] +OMIT FORMATTING LINK: [% omit_formatting_link %] + +ENABLE PAGE DELETION: [% enable_page_deletion %]
Deleted: trunk/t/templates/15_test.tt =================================================================== --- trunk/t/templates/15_test.tt 2012-05-05 09:45:05 UTC (rev 1381) +++ trunk/t/templates/15_test.tt 2012-05-05 10:27:25 UTC (rev 1382) @@ -1,19 +0,0 @@ -FOO: [% foo %] - -SITE NAME: [% site_name %] -CGI URL: [% cgi_url %] -FULL CGI URL: [% full_cgi_url %] -CONTACT EMAIL: [% contact_email %] -STYLESHEET: [% stylesheet %] -HOME LINK: [% home_link %] -HOME NAME: [% home_name %] - -OPENGUIDES VERSION: [% openguides_version %] - -NODE NAME: [% node_name %] -NODE PARAM: [% node_param %] - -FORMATTING RULES LINK: [% formatting_rules_link %] -OMIT FORMATTING LINK: [% omit_formatting_link %] - -ENABLE PAGE DELETION: [% enable_page_deletion %]