root/branches/new-install-process/t/71_missing_metadata.t

Revision 956, 4.4 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

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
16Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
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# Clear out the database from any previous runs.
26foreach my $del_node ( $wiki->list_all_nodes ) {
27    print "# Deleting node $del_node\n";
28    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
29}
30
31
32# Add 3 different pages, one of which with two versions
33$wiki->write_node( "Test Page", "foo", undef,
34                   { category => "Alpha", lat=>"" } )
35  or die "Couldn't write node";
36$wiki->write_node( "Test Page 2", "foo2", undef,
37                   { category => "Alpha", lat=>"22.22" } )
38  or die "Couldn't write node";
39$wiki->write_node( "Test Page 3", "foo33", undef,
40                   { category => "Alpha" } )
41  or die "Couldn't write node";
42$wiki->write_node( "Category Foo", "foo", undef,
43                   { category => "Categories", lat=>"-8.77" } )
44  or die "Couldn't write category";
45$wiki->write_node( "Locale Bar", "foo", undef,
46                   { category => "Locales", lat=>"8.22" } )
47  or die "Couldn't write locale";
48my %data = $wiki->retrieve_node( "Locale Bar" );
49$wiki->write_node( "Locale Bar", "foo version 2", $data{checksum},
50                   { category => "Locales", lat=>"8.88" } )
51  or die "Couldn't write locale for the 2nd time";
52
53
54# Try without search parameters
55my %ttvars = eval {
56       $guide->show_missing_metadata( return_tt_vars=> 1 );
57};
58my @nodes;
59is( $@, "", "->show_missing_metadata doesn't die" );
60
61is( scalar @{$ttvars{'nodes'}}, 0, "No nodes when no search params" );
62is( $ttvars{'done_search'}, 0, "Didn't search" );
63
64
65# Now try searching for those without lat
66%ttvars = eval {
67       $guide->show_missing_metadata(
68                                metadata_type => 'lat',
69                                return_tt_vars => 1
70        );
71};
72
73@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
74is( scalar @nodes, 2, "Two without / with empty lat" );
75is( $ttvars{'done_search'}, 1, "Did search" );
76is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
77is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
78
79
80# Now try searching for those without lat=22.22
81%ttvars = eval {
82       $guide->show_missing_metadata(
83                                metadata_type => 'lat',
84                                metadata_value => '22.22',
85                                return_tt_vars => 1
86        );
87};
88
89@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
90is( scalar @nodes, 4, "Four without that lat" );
91is( $ttvars{'done_search'}, 1, "Did search" );
92is( $nodes[0]->{'name'}, "Category Foo", "Right nodes" );
93is( $nodes[1]->{'name'}, "Locale Bar", "Right nodes" );
94is( $nodes[2]->{'name'}, "Test Page", "Right nodes" );
95is( $nodes[3]->{'name'}, "Test Page 3", "Right nodes" );
96
97
98# Try again, but exclude locale and category
99%ttvars = eval {
100       $guide->show_missing_metadata(
101                                metadata_type => 'lat',
102                                metadata_value => '22.22',
103                                exclude_locales => 1,
104                                exclude_categories => 2,
105                                return_tt_vars => 1
106        );
107};
108
109@nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}};
110is( scalar @nodes, 2, "Two without that lat" );
111is( $ttvars{'done_search'}, 1, "Did search" );
112is( $nodes[0]->{'name'}, "Test Page", "Right nodes" );
113is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" );
114
115
116# Test the normal, HTML version
117my $output = eval {
118    $guide->show_missing_metadata( return_output=>1 );
119};
120is( $@, "", "->how_missing_metadata doesn't die" );
121
122like( $output, qr|Missing Metadata|, "Right page" );
123like( $output, qr|Metadata Type|, "Has prompts" );
124unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" );
125
126$output = eval {
127    $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' );
128};
129is( $@, "", "->how_missing_metadata doesn't die" );
130like( $output, qr|<h3>Pages</h3>|, "searched" );
131like( $output, qr|Test Page|, "had node" );
Note: See TracBrowser for help on using the browser.