Author: bob Date: 2012-04-13 16:43:59 +0100 (Fri, 13 Apr 2012) New Revision: 1333
Added: trunk/t/87_more_recent_changes.t trunk/t/88_recent_changes_overtime.t Log: more tests for recent changes
Added: trunk/t/87_more_recent_changes.t =================================================================== --- trunk/t/87_more_recent_changes.t (rev 0) +++ trunk/t/87_more_recent_changes.t 2012-04-13 15:43:59 UTC (rev 1333) @@ -0,0 +1,160 @@ +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. +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 => 0, + default_edit_type => "tidying", + cookie_expires => "never", + track_recent_changes_views => 1, + is_admin => 1, +); +$ENV{HTTP_COOKIE} = $cookie; + + +TODO: { + local $TODO = "http://dev.openguides.org/ticket/270"; +$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"); +}
Added: trunk/t/88_recent_changes_overtime.t =================================================================== --- trunk/t/88_recent_changes_overtime.t (rev 0) +++ trunk/t/88_recent_changes_overtime.t 2012-04-13 15:43:59 UTC (rev 1333) @@ -0,0 +1,184 @@ +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"); +TODO: { + local $TODO = "http://dev.openguides.org/ticket/270"; +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");
openguides-commits@lists.openguides.org