source: trunk/t/71_missing_metadata.t @ 1317

Last change on this file since 1317 was 1317, checked in by kake, 10 years ago

Fixed bug where missing metadata search was picking up redirect pages.

File size: 4.6 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
8
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
12}
13
14plan tests => 26;
15    OpenGuides::Test::refresh_db();
16
17my $config = OpenGuides::Test->make_basic_config;
18$config->script_name( "wiki.cgi" );
19$config->script_url( "http://example.com/" );
20my $guide = OpenGuides->new( config => $config );
21isa_ok( $guide, "OpenGuides" );
22my $wiki = $guide->wiki;
23isa_ok( $wiki, "Wiki::Toolkit" );
24
25
26
27# Add four different pages, one of which with two versions, one of which
28# a redirect.  The redirect should not show up on any "missing metadata"
29# searches, regardless of the condition of the page it points to.
30$wiki->write_node( "Test Page", "foo", undef,
31                   { category => "Alpha", lat=>"" } )
32  or die "Couldn't write node";
33$wiki->write_node( "Test Page 2", "foo2", undef,
34                   { category => "Alpha", lat=>"22.22" } )
35  or die "Couldn't write node";
36$wiki->write_node( "Test Page 3", "foo33", undef,
37                   { category => "Alpha" } )
38  or die "Couldn't write node";
39$wiki->write_node( "Category Foo", "foo", undef,
40                   { category => "Categories", lat=>"-8.77" } )
41  or die "Couldn't write category";
42$wiki->write_node( "Locale Bar", "foo", undef,
43                   { category => "Locales", lat=>"8.22" } )
44  or die "Couldn't write locale";
45my %data = $wiki->retrieve_node( "Locale Bar" );
46$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
47                   { category => "Locales", lat=>"8.88" } )
48  or die "Couldn't write locale for the 2nd time";
49OpenGuides::Test->write_data(
50                              guide => $guide,
51                              node  => "Redirect Test",
52                              content => "#REDIRECT [[Test Page]]",
53                              return_output => 1,
54                            );
55
56# Try without search parameters
57my %ttvars = eval {
58       $guide->show_missing_metadata( return_tt_vars=> 1 );
59};
60my @nodes;
61is( $@, "", "->show_missing_metadata doesn't die" );
62
63is( scalar @{$ttvars{'nodes'}}, 0, "No nodes when no search params" );
64is( $ttvars{'done_search'}, 0, "Didn't search" );
65
66
67# Now try searching for those without lat
68%ttvars = eval {
69       $guide->show_missing_metadata(
70                                metadata_type => 'lat',
71                                return_tt_vars => 1
72        );
73};
74
75@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
76is( scalar @nodes, 2, "Two without / with empty lat" );
77is( $ttvars{'done_search'}, 1, "Did search" );
78is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
79is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
80
81
82# Now try searching for those without lat=22.22
83%ttvars = eval {
84       $guide->show_missing_metadata(
85                                metadata_type => 'lat',
86                                metadata_value => '22.22',
87                                return_tt_vars => 1
88        );
89};
90
91@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
92is( scalar @nodes, 4, "Four without that lat" );
93is( $ttvars{'done_search'}, 1, "Did search" );
94is( $nodes[0]->{'name'}, "Category Foo", "Right nodes" );
95is( $nodes[1]->{'name'}, "Locale Bar", "Right nodes" );
96is( $nodes[2]->{'name'}, "Test Page", "Right nodes" );
97is( $nodes[3]->{'name'}, "Test Page 3", "Right nodes" );
98
99
100# Try again, but exclude locale and category
101%ttvars = eval {
102       $guide->show_missing_metadata(
103                                metadata_type => 'lat',
104                                metadata_value => '22.22',
105                                exclude_locales => 1,
106                                exclude_categories => 2,
107                                return_tt_vars => 1
108        );
109};
110
111@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
112is( scalar @nodes, 2, "Two without that lat" );
113is( $ttvars{'done_search'}, 1, "Did search" );
114is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
115is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
116
117
118# Test the normal, HTML version
119my $output = eval {
120    $guide->show_missing_metadata( return_output=>1 );
121};
122is( $@, "", "->show_missing_metadata doesn't die" );
123
124like( $output, qr|Missing Metadata|, "Right page" );
125like( $output, qr|Metadata Type|, "Has prompts" );
126unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" );
127
128$output = eval {
129    $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' );
130};
131is( $@, "", "->show_missing_metadata doesn't die" );
132like( $output, qr|<h3>Pages</h3>|, "searched" );
133like( $output, qr|Test Page|, "had node" );
Note: See TracBrowser for help on using the repository browser.