Ticket #41: test_for_metadata_wasnt_recent_changes.diff

File test_for_metadata_wasnt_recent_changes.diff, 5.2 KB (added by bob, 10 years ago)

diff which adds tests which exposes this bug.

  • t/011_recent_changes.t

     
    55if ( scalar @Wiki::Toolkit::TestLib::wiki_info == 0 ) {
    66    plan skip_all => "no backends configured";
    77} else {
    8     plan tests => ( 25 * scalar @Wiki::Toolkit::TestLib::wiki_info );
     8    plan tests => ( 28 * scalar @Wiki::Toolkit::TestLib::wiki_info );
    99}
    1010
    1111my $iterator = Wiki::Toolkit::TestLib->new_wiki_maker;
     
    2424    do_sleep();
    2525    my $node = "Node1";
    2626    my %node_data = $wiki->retrieve_node( $node );
    27     $wiki->write_node( $node, @node_data{ qw( content checksum ) },
     27    $wiki->write_node( $node, "data", @node_data{checksum} ,
    2828                       {
    2929                         username  => "Kake",
    3030                         edit_type => "Minor tidying",
     
    3434    do_sleep();
    3535    $node = "Everyone's Favourite Hobby";
    3636    %node_data = $wiki->retrieve_node( $node );
    37     $wiki->write_node( $node, @node_data{ qw( content checksum ) },
     37    $wiki->write_node( $node, "hobby data", @node_data{checksum},
    3838                       {
    3939                         comment   => "Test",
     40                         edit_type => "Normal edit",
    4041                       }
    4142                     );
    4243    do_sleep();
    4344    $node = "Another Node";
    4445    %node_data = $wiki->retrieve_node( $node );
    45     $wiki->write_node( $node, @node_data{ qw( content checksum ) },
     46    $wiki->write_node( $node, "another node 1", @node_data{checksum},
    4647                       {
    4748                         username  => "nou",
    4849                         comment   => "Test",
     50                         edit_type => "Normal edit",
    4951                       }
    5052                     );
    5153
     
    9698        last_n_changes => 2,
    9799        metadata_is    => { username => "Kake" }
    98100    );
     101
     102    @nodenames = map { $_->{name} } @nodes;
     103    print "# Found nodes: " . join(" ", @nodenames) . "\n";
    99104    is( scalar @nodes, 1, "metadata_is does constrain the search" );
    100105    is( $nodes[0]{name}, "Node1", "...correctly" );
    101106
     
    112117        last_n_changes => 1,
    113118        metadata_isnt  => { edit_type => "Minor tidying" }
    114119    );
     120    @nodenames = map { $_->{name} } @nodes;
     121    print "# Found nodes: " . join(" ", @nodenames) . "\n";
    115122    is( scalar @nodes, 1,
    116123       "metadata_isnt includes nodes where this metadata type isn't set" );
    117124    is( $nodes[0]{name}, "Another Node", "...correctly" );
     
    132139    do_sleep();
    133140    $node = "Another Node";
    134141    %node_data = $wiki->retrieve_node( $node );
    135     $wiki->write_node( $node, @node_data{ qw( content checksum ) },
     142    $wiki->write_node( $node, "another node 2", @node_data{checksum},
    136143                       {
    137144                         username  => "Kake",
    138145                         comment  => "Kake writes the node that nou wrote",
     
    141148                     );
    142149
    143150    @nodes = $wiki->list_recent_changes( days => 1 );
     151    @nodenames = map { $_->{name} } @nodes;
     152    print "# Found nodes: " . join(" ", @nodenames) . "\n";
    144153    is( scalar @nodes, 3,
    145154        "By default each node returned only once however many times changed" );
    146155
     
    152161        last_n_changes => 5,
    153162        metadata_was => { username => "nou" }
    154163    );
     164    @nodenames = map { $_->{name} } @nodes;
     165    print "# Found nodes: " . join(" ", @nodenames) . "\n";
    155166    is( scalar @nodes, 1,
    156167       "metadata_was returns nodes whose current version doesn't match" );
    157168    is( $nodes[0]{name}, "Another Node", "...correctly" );
     
    168179                            edit_type => "Minor tidying",
    169180                          },
    170181    );
     182    @nodenames = map { $_->{name} } @nodes;
     183    print "# Found nodes: " . join(" ", @nodenames) . "\n";
    171184    is( scalar @nodes, 2,
    172185        "metadata_wasnt returns nodes whose current version matches" );
     186
     187    # lets add yet another normal edit to check proper display of multple normal edits
     188    do_sleep();
     189    $node = "Another Node";
     190    %node_data = $wiki->retrieve_node( $node );
     191    $wiki->write_node( $node, "another node 3", @node_data{checksum},
     192                       {
     193                         username  => "bob",
     194                         comment  => "bob writes the node that nou and Kake aready wrote",
     195                         edit_type => "Normal edit",
     196                       }
     197                     );
     198
     199    @nodenames = map { $_->{name} } @nodes;
     200    print "# Found nodes: " . join(" ", @nodenames) . "\n";
     201    @nodes = $wiki->list_recent_changes( days => 1 );
     202    is( scalar @nodes, 3,
     203        "By default each node returned only once however many times changed" );
     204    @nodes = $wiki->list_recent_changes( days => 1, include_all_changes => 1 );
     205    is( scalar @nodes, 5,
     206        "...returned more than once when 'include_all_changes' set" );
     207    @nodes = $wiki->list_recent_changes(
     208        days => 1,
     209        metadata_was => {
     210                            edit_type => "Normal edit",
     211                          },
     212    );
     213    @nodenames = map { $_->{name} } @nodes;
     214    print "# Found nodes: " . join(" ", @nodenames) . "\n";
     215    is( scalar @nodes, 2,
     216        "metadata_was returns nodes whose current version matches" );
     217
    173218}
    174219
    175220sub do_sleep {