| 21 | | my %stores = Wiki::Toolkit::TestConfig::Utilities->stores; |
| 22 | | |
| 23 | | my ($store_name, $store); |
| 24 | | while ( ($store_name, $store) = each %stores ) { |
| 25 | | SKIP: { |
| 26 | | skip "$store_name storage backend not configured for testing", 22 |
| 27 | | unless $store; |
| 28 | | |
| 29 | | print "#\n##### TEST CONFIG: Store: $store_name\n#\n"; |
| 30 | | |
| 31 | | my $wiki = Wiki::Toolkit->new( store => $store ); |
| 32 | | my %default_config = ( |
| 33 | | wiki => $wiki, |
| 34 | | site_name => "Wiki::Toolkit Test Site", |
| 35 | | make_node_url => sub { |
| 36 | | my $id = uri_escape($_[0]); |
| 37 | | my $version = $_[1] || ''; |
| 38 | | $version = uri_escape($version) if $version; |
| 39 | | "http://example.com/?id=$id;version=$version"; |
| 40 | | }, |
| 41 | | recent_changes_link => "http://example.com/recentchanges" |
| 42 | | ); |
| 43 | | my $rss = eval { |
| 44 | | Wiki::Toolkit::Feed::RSS->new( %default_config, site_url => "http://example.com/kakeswiki/" ); |
| 45 | | }; |
| 46 | | is( $@, "", |
| 47 | | "'new' doesn't croak if wiki object and mandatory parameters supplied" |
| 48 | | ); |
| 49 | | isa_ok( $rss, "Wiki::Toolkit::Feed::RSS" ); |
| 50 | | |
| 51 | | my $feed = eval { $rss->recent_changes; }; |
| 52 | | is( $@, "", "->recent_changes doesn't croak" ); |
| 53 | | |
| 54 | | # Check the things that are generated by the mandatory arguments. |
| 55 | | like( $feed, qr|<item rdf:about="http://example.com/\?id=Test%20Node%201;version=1">|, |
| 56 | | "make_node_url is used" ); |
| 57 | | |
| 58 | | like( $feed, qr|<modwiki:version>1</modwiki:version>|, |
| 59 | | "version numbers included in feed" ); |
| 60 | | |
| 61 | | like( $feed, qr|<modwiki:status>new</modwiki:status>|, |
| 62 | | "page status included in feed" ); |
| 63 | | |
| 64 | | like( $feed, qr|<modwiki:importance>major</modwiki:importance>|, |
| 65 | | "change importance included and defaults to 'major'" ); |
| 66 | | |
| 67 | | my $charset = $wiki->store->{_charset}; |
| 68 | | like( $feed, qr|<?xml version="1.0"|, "is xml" ); |
| 69 | | like( $feed, qr|<?xml version="1.0" encoding="$charset"|, "is xml" ); |
| 70 | | |
| 71 | | # Check stuff that comes from the metadata. |
| 72 | | like( $feed, qr|<dc:contributor>Kake</dc:contributor>|, |
| 73 | | "username picked up as contributor" ); |
| 74 | | |
| 75 | | like( $feed, qr|<description>.*\[nou]</description>|, |
| 76 | | "username included in description" ); |
| 77 | | |
| 78 | | like( $feed, qr|<dc:subject>TestCategory1</dc:subject>|, |
| 79 | | "dublin core subject contains category" ); |
| 80 | | |
| 81 | | # Check that interwiki things are passed through right. |
| 82 | | $rss = Wiki::Toolkit::Feed::RSS->new( |
| 83 | | %default_config, |
| 84 | | interwiki_identifier => "KakesWiki", |
| 85 | | site_url => "http://example.com/kakeswiki/", |
| 86 | | ); |
| 87 | | $feed = $rss->recent_changes; |
| 88 | | like( $feed, qr|<modwiki:interwiki>KakesWiki</modwiki:interwiki>|, |
| 89 | | "interwiki identifier passed through OK" ); |
| 90 | | |
| 91 | | # Check that diff url comes through. |
| 92 | | $rss = Wiki::Toolkit::Feed::RSS->new( |
| 93 | | %default_config, |
| 94 | | make_diff_url => sub { |
| 95 | | my $node_name = shift; |
| 96 | | return "http://example.com/?action=show_diff;id=" |
| 97 | | . uri_escape($node_name) |
| 98 | | }, |
| 99 | | site_url => "http://example.com/kakeswiki/", |
| 100 | | ); |
| 101 | | $feed = $rss->recent_changes; |
| 102 | | like( $feed, qr|<modwiki:diff>http://example.com/\?action=show_diff;id=Calthorpe%20Arms</modwiki:diff>|, |
| 103 | | "make_diff_url used" ); |
| 104 | | |
| 105 | | # Check that history url comes through. |
| 106 | | # Will use a different character set |
| 107 | | $rss = Wiki::Toolkit::Feed::RSS->new( |
| 108 | | %default_config, |
| 109 | | make_history_url => sub { |
| 110 | | my $node_name = shift; |
| 111 | | return "http://example.com/?action=history;id=" |
| 112 | | . uri_escape($node_name) |
| 113 | | }, |
| 114 | | site_url => "http://example.com/kakeswiki/", |
| 115 | | encoding => "UTF-16" |
| 116 | | ); |
| 117 | | $feed = $rss->recent_changes; |
| 118 | | like( $feed, qr|<modwiki:history>http://example.com/\?action=history;id=Calthorpe%20Arms</modwiki:history>|, |
| 119 | | "make_history_url used" ); |
| 120 | | |
| 121 | | # Test the 'items' parameter. |
| 122 | | $feed = $rss->recent_changes( items => 2 ); |
| 123 | | unlike( $feed, qr|<title>Test Node 1</title>|, "items param works" ); |
| 124 | | |
| 125 | | # Test the 'days' parameter. |
| 126 | | $feed = $rss->recent_changes( days => 2 ); |
| 127 | | like( $feed, qr|<title>Old Node</title>|, "days param works" ); |
| 128 | | |
| 129 | | # Test ignoring minor changes. |
| 130 | | $feed = $rss->recent_changes( ignore_minor_edits => 1 ); |
| 131 | | unlike( $feed, qr|This is a minor change.|, |
| 132 | | "ignore_minor_edits works" ); |
| 133 | | |
| 134 | | # Test personalised feeds. |
| 135 | | $feed = $rss->recent_changes( |
| 136 | | filter_on_metadata => { |
| 137 | | username => "Kake", |
| 138 | | }, |
| 139 | | ); |
| 140 | | unlike( $feed, qr|<dc:contributor>nou</dc:contributor>|, |
| 141 | | "can filter on a single metadata criterion" ); |
| 142 | | |
| 143 | | $feed = $rss->recent_changes( |
| 144 | | filter_on_metadata => { |
| 145 | | username => "Kake", |
| 146 | | locale => "Bloomsbury", |
| 147 | | }, |
| 148 | | ); |
| 149 | | unlike( $feed, qr|<title>Test Node 1</title>|, |
| 150 | | "can filter on two criteria" ); |
| 151 | | |
| 152 | | # Test the xml headers again, now we have given a character set |
| 153 | | like( $feed, qr|<?xml version="1.0"|, "is xml" ); |
| 154 | | like( $feed, qr|<?xml version="1.0" encoding="UTF-16"|, "is xml" ); |
| 155 | | |
| 156 | | } |
| | 20 | while ( my $wiki = $iterator->new_wiki ) { |
| | 21 | |
| | 22 | # First, write some data. |
| | 23 | |
| | 24 | # Write two versions of one node |
| | 25 | # The recent changes should only show it once though |
| | 26 | $wiki->write_node( "Old Node", |
| | 27 | "First version of Old Node" ); |
| | 28 | my %old_node = $wiki->retrieve_node("Old Node"); |
| | 29 | $wiki->write_node( "Old Node", |
| | 30 | "We will write at least 15 nodes after this one", |
| | 31 | $old_node{'checksum'} ); |
| | 32 | |
| | 33 | my $slept = sleep(2); |
| | 34 | warn "Slept for less than a second, 'days=n' test may pass even if buggy" |
| | 35 | unless $slept >= 1; |
| | 36 | |
| | 37 | for my $i ( 1 .. 15 ) { |
| | 38 | $wiki->write_node( "Temp Node $i", "foo" ); |
| | 39 | } |
| | 40 | |
| | 41 | $slept = sleep(2); |
| | 42 | warn "Slept for less than a second, test results may not be trustworthy" |
| | 43 | unless $slept >= 1; |
| | 44 | |
| | 45 | $wiki->write_node( "Test Node 1", |
| | 46 | "Just a plain test", |
| | 47 | undef, |
| | 48 | { username => "Kake", |
| | 49 | comment => "new node", |
| | 50 | category => [ 'TestCategory1', 'Meta' ] |
| | 51 | } |
| | 52 | ); |
| | 53 | |
| | 54 | $slept = sleep(2); |
| | 55 | warn "Slept for less than a second, 'items=n' test may fail" |
| | 56 | unless $slept >= 1; |
| | 57 | |
| | 58 | $wiki->write_node( "Calthorpe Arms", |
| | 59 | "CAMRA-approved pub near King's Cross", |
| | 60 | undef, |
| | 61 | { comment => "Stub page, please update!", |
| | 62 | username => "Kake", |
| | 63 | postcode => "WC1X 8JR", |
| | 64 | locale => [ "Bloomsbury" ] |
| | 65 | } |
| | 66 | ); |
| | 67 | |
| | 68 | $wiki->write_node( "Test Node 2", |
| | 69 | "Gosh, another test!", |
| | 70 | undef, |
| | 71 | { |
| | 72 | username => "nou", |
| | 73 | comment => "This is a minor edit.", |
| | 74 | major_change => 0, |
| | 75 | } |
| | 76 | ); |
| | 77 | |
| | 78 | # Now set up a feed object and test it. |
| | 79 | |
| | 80 | my %default_config = ( |
| | 81 | wiki => $wiki, |
| | 82 | site_name => "Wiki::Toolkit Test Site", |
| | 83 | make_node_url => sub { |
| | 84 | my $id = uri_escape($_[0]); |
| | 85 | my $version = $_[1] || ''; |
| | 86 | $version = uri_escape($version) if $version; |
| | 87 | "http://example.com/?id=$id;version=$version"; |
| | 88 | }, |
| | 89 | recent_changes_link => "http://example.com/recentchanges" |
| | 90 | ); |
| | 91 | my $rss = eval { |
| | 92 | Wiki::Toolkit::Feed::RSS->new( |
| | 93 | %default_config, |
| | 94 | site_url => "http://example.com/kakeswiki/", |
| | 95 | ); |
| | 96 | }; |
| | 97 | is( $@, "", |
| | 98 | "'new' doesn't croak if wiki object and mandatory parameters supplied" |
| | 99 | ); |
| | 100 | isa_ok( $rss, "Wiki::Toolkit::Feed::RSS" ); |
| | 101 | |
| | 102 | my $feed = eval { $rss->recent_changes; }; |
| | 103 | is( $@, "", "->recent_changes doesn't croak" ); |
| | 104 | |
| | 105 | # Check the things that are generated by the mandatory arguments. |
| | 106 | like( $feed, |
| | 107 | qr|<item rdf:about="http://example.com/\?id=Test%20Node%201;version=1">|, |
| | 108 | "make_node_url is used" ); |
| | 109 | |
| | 110 | like( $feed, qr|<modwiki:version>1</modwiki:version>|, |
| | 111 | "version numbers included in feed" ); |
| | 112 | |
| | 113 | like( $feed, qr|<modwiki:status>new</modwiki:status>|, |
| | 114 | "page status included in feed" ); |
| | 115 | |
| | 116 | like( $feed, qr|<modwiki:importance>major</modwiki:importance>|, |
| | 117 | "change importance included and defaults to 'major'" ); |
| | 118 | |
| | 119 | my $charset = $wiki->store->{_charset}; |
| | 120 | like( $feed, qr|<?xml version="1.0"|, "is xml" ); |
| | 121 | like( $feed, qr|<?xml version="1.0" encoding="$charset"|, "is xml" ); |
| | 122 | |
| | 123 | # Check stuff that comes from the metadata. |
| | 124 | like( $feed, qr|<dc:contributor>Kake</dc:contributor>|, |
| | 125 | "username picked up as contributor" ); |
| | 126 | |
| | 127 | like( $feed, qr|<description>.*\[nou]</description>|, |
| | 128 | "username included in description" ); |
| | 129 | |
| | 130 | like( $feed, qr|<dc:subject>TestCategory1</dc:subject>|, |
| | 131 | "dublin core subject contains category" ); |
| | 132 | |
| | 133 | # Check that interwiki things are passed through right. |
| | 134 | $rss = Wiki::Toolkit::Feed::RSS->new( |
| | 135 | %default_config, |
| | 136 | interwiki_identifier => "KakesWiki", |
| | 137 | site_url => "http://example.com/kakeswiki/", |
| | 138 | ); |
| | 139 | $feed = $rss->recent_changes; |
| | 140 | like( $feed, qr|<modwiki:interwiki>KakesWiki</modwiki:interwiki>|, |
| | 141 | "interwiki identifier passed through OK" ); |
| | 142 | |
| | 143 | # Check that diff url comes through. |
| | 144 | $rss = Wiki::Toolkit::Feed::RSS->new( |
| | 145 | %default_config, |
| | 146 | make_diff_url => sub { |
| | 147 | my $node_name = shift; |
| | 148 | return "http://example.com/?action=show_diff;id=" |
| | 149 | . uri_escape($node_name) |
| | 150 | }, |
| | 151 | site_url => "http://example.com/kakeswiki/", |
| | 152 | ); |
| | 153 | $feed = $rss->recent_changes; |
| | 154 | like( $feed, qr|<modwiki:diff>http://example.com/\?action=show_diff;id=Calthorpe%20Arms</modwiki:diff>|, |
| | 155 | "make_diff_url used" ); |
| | 156 | |
| | 157 | # Check that history url comes through. |
| | 158 | # Will use a different character set |
| | 159 | $rss = Wiki::Toolkit::Feed::RSS->new( |
| | 160 | %default_config, |
| | 161 | make_history_url => sub { |
| | 162 | my $node_name = shift; |
| | 163 | return "http://example.com/?action=history;id=" |
| | 164 | . uri_escape($node_name) |
| | 165 | }, |
| | 166 | site_url => "http://example.com/kakeswiki/", |
| | 167 | encoding => "UTF-16" |
| | 168 | ); |
| | 169 | $feed = $rss->recent_changes; |
| | 170 | like( $feed, qr|<modwiki:history>http://example.com/\?action=history;id=Calthorpe%20Arms</modwiki:history>|, |
| | 171 | "make_history_url used" ); |
| | 172 | |
| | 173 | # Test the 'items' parameter. |
| | 174 | $feed = $rss->recent_changes( items => 2 ); |
| | 175 | unlike( $feed, qr|<title>Test Node 1</title>|, "items param works" ); |
| | 176 | |
| | 177 | # Test the 'days' parameter. |
| | 178 | $feed = $rss->recent_changes( days => 2 ); |
| | 179 | like( $feed, qr|<title>Old Node</title>|, "days param works" ); |
| | 180 | |
| | 181 | # Test ignoring minor changes. |
| | 182 | $feed = $rss->recent_changes( ignore_minor_edits => 1 ); |
| | 183 | unlike( $feed, qr|This is a minor change.|, |
| | 184 | "ignore_minor_edits works" ); |
| | 185 | |
| | 186 | # Test personalised feeds. |
| | 187 | $feed = $rss->recent_changes( |
| | 188 | filter_on_metadata => { |
| | 189 | username => "Kake", |
| | 190 | }, |
| | 191 | ); |
| | 192 | unlike( $feed, qr|<dc:contributor>nou</dc:contributor>|, |
| | 193 | "can filter on a single metadata criterion" ); |
| | 194 | |
| | 195 | $feed = $rss->recent_changes( |
| | 196 | filter_on_metadata => { |
| | 197 | username => "Kake", |
| | 198 | locale => "Bloomsbury", |
| | 199 | }, |
| | 200 | ); |
| | 201 | unlike( $feed, qr|<title>Test Node 1</title>|, |
| | 202 | "can filter on two criteria" ); |
| | 203 | |
| | 204 | # Test the xml headers again, now we have given a character set |
| | 205 | like( $feed, qr|<?xml version="1.0"|, "is xml" ); |
| | 206 | like( $feed, qr|<?xml version="1.0" encoding="UTF-16"|, "is xml" ); |