Author: kake Date: 2012-07-01 19:57:38 +0100 (Sun, 01 Jul 2012) New Revision: 1417
Modified: trunk/t/701_missing_metadata.t trunk/templates/missing_metadata.tt Log: Use TT logic, not JavaScript, to make choice persistent in 'missing metadata' dropdown.
Modified: trunk/t/701_missing_metadata.t =================================================================== --- trunk/t/701_missing_metadata.t 2012-07-01 09:58:29 UTC (rev 1416) +++ trunk/t/701_missing_metadata.t 2012-07-01 18:57:38 UTC (rev 1417) @@ -5,13 +5,15 @@ use Test::More;
eval { require DBD::SQLite; }; - if ( $@ ) { my ($error) = $@ =~ /^(.*?)\n/; plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; }
-plan tests => 27; +eval { require Test::HTML::Content; }; +my $thc = $@ ? 0 : 1; + +plan tests => 29; OpenGuides::Test::refresh_db();
my $config = OpenGuides::Test->make_basic_config; @@ -26,23 +28,23 @@ # is a redirect. The redirect should not show up on any "missing metadata" # searches, regardless of the condition of the page it points to. $wiki->write_node( "Test Page", "foo", undef, - { category => "Alpha", lat=>"" } ) + { category => "Alpha", latitude => "" } ) or die "Couldn't write node"; $wiki->write_node( "Test Page 2", "foo2", undef, - { category => "Alpha", lat=>"22.22" } ) + { category => "Alpha", latitude => "22.22" } ) or die "Couldn't write node"; $wiki->write_node( "Test Page 3", "foo33", undef, { category => "Alpha" } ) or die "Couldn't write node"; $wiki->write_node( "Category Foo", "foo", undef, - { category => "Categories", lat=>"-8.77" } ) + { category => "Categories", latitude => "-8.77" } ) or die "Couldn't write category"; $wiki->write_node( "Locale Bar", "foo", undef, - { category => "Locales", lat=>"8.22" } ) + { category => "Locales", latitude => "8.22" } ) or die "Couldn't write locale"; my %data = $wiki->retrieve_node( "Locale Bar" ); $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, - { category => "Locales", lat=>"8.88" } ) + { category => "Locales", latitude => "8.88" } ) or die "Couldn't write locale for the 2nd time"; OpenGuides::Test->write_data( guide => $guide, @@ -65,7 +67,7 @@ # Now try searching for those without lat %ttvars = eval { $guide->show_missing_metadata( - metadata_type => 'lat', + metadata_type => 'latitude', return_tt_vars => 1 ); }; @@ -80,7 +82,7 @@ # Now try searching for those without lat=22.22 %ttvars = eval { $guide->show_missing_metadata( - metadata_type => 'lat', + metadata_type => 'latitude', metadata_value => '22.22', return_tt_vars => 1 ); @@ -103,7 +105,7 @@ # Try again, but exclude locale and category %ttvars = eval { $guide->show_missing_metadata( - metadata_type => 'lat', + metadata_type => 'latitude', metadata_value => '22.22', exclude_locales => 1, exclude_categories => 2, @@ -122,15 +124,26 @@ my $output = eval { $guide->show_missing_metadata( return_output=>1 ); }; -is( $@, "", "->show_missing_metadata doesn't die" ); +is( $@, "", + "->show_missing_metadata doesn't die when called with no metadata_type" );
like( $output, qr|Missing Metadata|, "Right page" ); like( $output, qr|Metadata Type|, "Has prompts" ); unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" ); +like( $output, qr|Telephone Number|, "...correct labels in the dropdown" );
$output = eval { - $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' ); + $guide->show_missing_metadata( return_output => 1, + metadata_type => "latitude" ); }; -is( $@, "", "->show_missing_metadata doesn't die" ); +is( $@, "", "->show_missing_metadata doesn't die when called with " + . "metadata_type 'latitude'" ); like( $output, qr|<h3>Pages</h3>|, "searched" ); like( $output, qr|Test Page|, "had node" ); + +SKIP: { + skip "Test::HTML::Content not available", 1 unless $thc; + Test::HTML::Content::tag_ok( + $output, "option", { value => "latitude", selected => "1" }, + "...latitude is selected in the dropdown" ); +}
Modified: trunk/templates/missing_metadata.tt =================================================================== --- trunk/templates/missing_metadata.tt 2012-07-01 09:58:29 UTC (rev 1416) +++ trunk/templates/missing_metadata.tt 2012-07-01 18:57:38 UTC (rev 1417) @@ -5,29 +5,26 @@ <div id="maincontent"> <h2>Pages Missing Metadata</h2>
+[% options = [ "category", "locale", "address", "postcode", "phone", + "latitude", "longitude", "os_x", "os_y" ] %] + +[% labels = { phone => "Telephone Number", os_x => "OS X", os_y => "OS Y" } %] + <form method="get" action="[% script_name %]"> <input type="hidden" name="action" value="show_missing_metadata" /> <div> <label for="metadata_type">Metadata Type:</label> <select name="metadata_type" id="metadata_type"> - <option value="category">Category</option> - <option value="locale">Locale</option> - <option value="address">Address</option> - <option value="postcode">Postcode</option> - <option value="phone">Telephone Number</option> - <option value="latitude">Latitude</option> - <option value="longitude">Longitude</option> - <option value="os_x">OS X</option> - <option value="os_y">OS Y</option> + [% FOREACH option = options %] + <option value="[% option %]"[% IF option == metadata_type %] selected="1"[% END %]> + [%- IF labels.$option -%] + [%- labels.$option -%] + [%- ELSE -%] + [%- option.ucfirst -%] + [%- END -%] + </option> + [% END %] </select> - <script type="text/javascript"> - var metadata_type = document.getElementById("metadata_type"); - for(var i=0; i<metadata_type.options.length; i++) { - if(metadata_type.options[i].value == '[% metadata_type %]') { - metadata_type.options[i].selected = true; - } - } - </script> </div> <div> <label for="metadata_value">Metadata Value:</label>
openguides-commits@lists.openguides.org