| 1 | use strict; |
|---|
| 2 | use OpenGuides; |
|---|
| 3 | use OpenGuides::Test; |
|---|
| 4 | use Test::More; |
|---|
| 5 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | my ($error) = $@ =~ /^(.*?)\n/; |
|---|
| 10 | plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | eval { require Test::HTML::Content; }; |
|---|
| 14 | if ( $@ ) { |
|---|
| 15 | plan skip_all => "Test::HTML::Content not installed"; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | plan tests => 16; |
|---|
| 19 | |
|---|
| 20 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 21 | |
|---|
| 22 | # Make a guide that works on latitude/longitude, and allows node images. |
|---|
| 23 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 24 | $config->geo_handler( 3 ); |
|---|
| 25 | $config->ellipsoid( "WGS-84" ); |
|---|
| 26 | $config->enable_node_image( 1 ); |
|---|
| 27 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 28 | my $wiki = $guide->wiki; |
|---|
| 29 | |
|---|
| 30 | # Clear out the database from any previous runs. |
|---|
| 31 | foreach my $del_node ( $wiki->list_all_nodes ) { |
|---|
| 32 | print "# Deleting node $del_node\n"; |
|---|
| 33 | $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | # Write some data. |
|---|
| 38 | OpenGuides::Test->write_data( |
|---|
| 39 | guide => $guide, |
|---|
| 40 | node => "Crabtree Tavern", |
|---|
| 41 | content => "A pub.", |
|---|
| 42 | locales => "W6", |
|---|
| 43 | categories => "Pubs\r\nPub Food", |
|---|
| 44 | latitude => 51.5, |
|---|
| 45 | longitude => -0.05, |
|---|
| 46 | ); |
|---|
| 47 | |
|---|
| 48 | # Make sure the normal edit form doesn't think there's a conflict. |
|---|
| 49 | my $output = $guide->display_edit_form( |
|---|
| 50 | id => "Crabtree Tavern", |
|---|
| 51 | return_output => 1, |
|---|
| 52 | ); |
|---|
| 53 | |
|---|
| 54 | # Strip Content-Type header to stop Test::HTML::Content getting confused. |
|---|
| 55 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 56 | |
|---|
| 57 | Test::HTML::Content::no_tag( $output, "div", { class => "warning_text" }, |
|---|
| 58 | "Normal edit form doesn't contain warning_text" ); |
|---|
| 59 | |
|---|
| 60 | # Now try to commit some edits without giving the checksum. |
|---|
| 61 | $output = OpenGuides::Test->write_data( |
|---|
| 62 | guide => $guide, |
|---|
| 63 | node => "Crabtree Tavern", |
|---|
| 64 | content => "Still a pub.", |
|---|
| 65 | locales => "Hammersmith", |
|---|
| 66 | categories => "Beer Garden", |
|---|
| 67 | latitude => 41.5, |
|---|
| 68 | longitude => -0.04, |
|---|
| 69 | omit_checksum => 1, |
|---|
| 70 | return_output => 1, |
|---|
| 71 | ); |
|---|
| 72 | |
|---|
| 73 | # Strip Content-Type header to stop Test::HTML::Content getting confused. |
|---|
| 74 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 75 | |
|---|
| 76 | Test::HTML::Content::tag_ok( $output, "div", { class => "warning_text" }, |
|---|
| 77 | "Edit conflict form contains warning_text" ); |
|---|
| 78 | |
|---|
| 79 | like( $output, qr/A pub./s, "...and old content" ); |
|---|
| 80 | like( $output, qr/Still a pub./s, "...and new content" ); |
|---|
| 81 | like( $output, qr/W6/s, "...and old locales" ); |
|---|
| 82 | like( $output, qr/Hammersmith/s, "...and new locales" ); |
|---|
| 83 | like( $output, qr/Pubs/s, "...and old categories" ); |
|---|
| 84 | like( $output, qr/Pub Food/s, "...both of them" ); |
|---|
| 85 | like( $output, qr/Beer Garden/s, "...and new categories" ); |
|---|
| 86 | |
|---|
| 87 | # Bug #173 (edit conflict form doesn't let you edit everything). |
|---|
| 88 | Test::HTML::Content::tag_ok( $output, "input", { name => "node_image" }, |
|---|
| 89 | "...and 'node_image' input box too" ); |
|---|
| 90 | |
|---|
| 91 | # Bug #48 (Edit conflict page erroneously converts lat/lon to os_x, os_y). |
|---|
| 92 | Test::HTML::Content::tag_ok( $output, "input", { name => "latitude" }, |
|---|
| 93 | "UTM guide has 'latitude' input box in edit " |
|---|
| 94 | . "conflict" ); |
|---|
| 95 | Test::HTML::Content::tag_ok( $output, "input", { name => "latitude", |
|---|
| 96 | value => 51.5 }, |
|---|
| 97 | "...with correct value" ); |
|---|
| 98 | Test::HTML::Content::tag_ok( $output, "input", { name => "longitude" }, |
|---|
| 99 | "...and 'longitude' input box too" ); |
|---|
| 100 | Test::HTML::Content::tag_ok( $output, "input", { name => "longitude", |
|---|
| 101 | value => -0.05 }, |
|---|
| 102 | "...with correct value" ); |
|---|
| 103 | like( $output, qr/41\.5/, "...new latitude is there too" ); |
|---|
| 104 | like( $output, qr/-0\.04/, "...and new longitude" ); |
|---|