source: wiki-toolkit/trunk/t/027_list_last_version_before.t @ 383

Revision 383, 2.9 KB checked in by nick, 7 years ago (diff)

Add list_last_version_before support, and script wiki-toolkit-revert-to-date

Line 
1use strict;
2use Wiki::Toolkit::TestLib;
3use Test::More;
4
5if ( scalar @Wiki::Toolkit::TestLib::wiki_info == 0 ) {
6    plan skip_all => "no backends configured";
7} else {
8    plan tests => ( 21 * scalar @Wiki::Toolkit::TestLib::wiki_info );
9}
10
11my $iterator = Wiki::Toolkit::TestLib->new_wiki_maker;
12
13while ( my $wiki = $iterator->new_wiki ) {
14        # Add three base nodes
15    foreach my $name ( qw( Carrots Handbags Cheese ) ) {
16        $wiki->write_node( $name, "content" ) or die "Can't write node";
17    }
18
19        # Add three more versions of Cheese
20        my %node = $wiki->retrieve_node("Cheese");
21        $wiki->write_node("Cheese", "Content v2", $node{checksum}, { "foo" => "bar" } ) or die "Can't write node";
22
23        %node = $wiki->retrieve_node("Cheese");
24        $wiki->write_node("Cheese", "Content v3", $node{checksum}, { "foo" => "bar", "bar" => "foo" } ) or die "Can't write node";
25
26        %node = $wiki->retrieve_node("Cheese");
27        $wiki->write_node("Cheese", "Content v4", $node{checksum} ) or die "Can't write node";
28
29    # Nobble the dates on these
30    $wiki->store->dbh->do("UPDATE content SET modified='2006-10-01' WHERE version = 1");
31    $wiki->store->dbh->do("UPDATE content SET modified='2006-09-04' WHERE version = 1 and node_id = 2");
32    $wiki->store->dbh->do("UPDATE content SET modified='2006-10-02' WHERE version = 2");
33    $wiki->store->dbh->do("UPDATE content SET modified='2006-10-03' WHERE version = 3");
34    $wiki->store->dbh->do("UPDATE content SET modified='2006-11-01' WHERE version = 4");
35
36
37        # Fetch everything before 2007
38    my @all = $wiki->store->list_last_version_before('2007-01-01');
39
40        is( scalar @all, 3, "list_last_version_before gives the right number back" );
41
42        # Check them
43        is( $all[0]->{'version'}, 1, "right ordering" );
44        is( $all[1]->{'version'}, 1, "right ordering" );
45        is( $all[2]->{'version'}, 4, "right ordering" );
46        is( $all[0]->{'name'}, 'Carrots', "right ordering" );
47        is( $all[1]->{'name'}, 'Handbags', "right ordering" );
48        is( $all[2]->{'name'}, 'Cheese', "right ordering" );
49
50    # Now before 2006-10-02
51    @all = $wiki->list_last_version_before('2006-10-02');
52
53        is( scalar @all, 3, "list_last_version_before gives the right number back" );
54        is( $all[0]->{'version'}, 1, "right ordering" );
55        is( $all[1]->{'version'}, 1, "right ordering" );
56        is( $all[2]->{'version'}, 2, "right ordering" );
57        is( $all[0]->{'name'}, 'Carrots', "right ordering" );
58        is( $all[1]->{'name'}, 'Handbags', "right ordering" );
59        is( $all[2]->{'name'}, 'Cheese', "right ordering" );
60
61    # Now before 2006-09-10
62    @all = $wiki->store->list_last_version_before('2006-09-10');
63
64        is( scalar @all, 3, "list_last_version_before gives the right number back" );
65        is( $all[0]->{'version'}, undef, "right ordering" );
66        is( $all[1]->{'version'}, 1, "right ordering" );
67        is( $all[2]->{'version'}, undef, "right ordering" );
68        is( $all[0]->{'name'}, 'Carrots', "right ordering" );
69        is( $all[1]->{'name'}, 'Handbags', "right ordering" );
70        is( $all[2]->{'name'}, 'Cheese', "right ordering" );
71}
72
Note: See TracBrowser for help on using the repository browser.