Files
oddmuse/t/atom.t
Alex Schroeder c0a6bfebf2 Add language to body element and various divs
The benefit is that this allows us to use the CSS rule that allows the
browser to hyphenate words:

body { hyphens: auto }

This required a number of changes.

wiki.pl

- new option, $CurrentLanguage
- GetHtmlHeader adds lang attribute to body
- PrintAllPages adds lang attribute to div
- PrintPageContent adds lang attribute to div
- PageHtml adds div with lang attribute
- GetLanguages sorts languages by occurences
- GetLanguage is new and returns the first language of GetLanguages

Modules that had to be changed because they refer to the divs that
have now been changed:

- crossbar.pl

Tests that had to be changed:

- atom.t
- crossbar.t
- hr.t
- languages.t
- portrait-support.t
- rss.t
2019-09-27 21:34:32 +02:00

144 lines
4.8 KiB
Perl
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (C) 20062019 Alex Schroeder <alex@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require './t/test.pl';
package OddMuse;
use Test::More tests => 44;
use LWP::UserAgent;
use XML::Atom::Client;
use XML::Atom::Entry;
use XML::Atom::Person;
add_module('atom.pl');
start_server();
# Check whether the child is up and running
my $ua = LWP::UserAgent->new;
my $response = $ua->get("$ScriptName?action=version");
ok($response->is_success, "There is a wiki running at $ScriptName");
like($response->content, qr/\batom\.pl/, "The server has the atom extension installed");
# Testing the Atom API
my $api = XML::Atom::Client->new;
my $entry = XML::Atom::Entry->new;
my $title = 'New Post';
my $summary = 'Created';
my $content = 'Content of my post ' . rand(999) . "\n";
my $username = 'Alex';
ok($entry->title($title), 'set post title');
ok($entry->summary($summary), 'set post summary');
ok($entry->content($content), 'set post content');
my $author = XML::Atom::Person->new;
ok($author->name($username), 'set author name');
ok($entry->author($author), 'set entry author');
my $PostURI = "$ScriptName/atom";
my $MemberURI = $api->createEntry($PostURI, $entry);
ok($MemberURI, "posting entry returns member URI $MemberURI")
or diag($api->errstr);
my $result = $api->getEntry($MemberURI);
ok($result, 'get created entry')
or diag($api->errstr);
ok($result->title eq $title, 'verify title');
ok($result->summary eq $summary, 'verify summary');
ok($result->content->body eq $content, 'verify content');
ok($result->author->name eq $username, 'verify author');
$MemberURI = '';
my @links = ($result->link);
ok($#links >= 0, 'verify link');
for my $link (@links) {
if ($link->rel eq 'edit') {
$MemberURI = $link->href;
last;
}
}
ok($MemberURI, "entry contains member URI $MemberURI");
$summary = 'Updated';
$content = "No more random numbers!\n";
ok($entry->summary($summary), 'change summary');
ok($entry->content($content), 'change content');
ok($api->updateEntry($MemberURI, $entry), 'update entry')
or diag($api->errstr);
$result = $api->getEntry($MemberURI);
ok($result, 'get updated entry')
or diag($api->errstr);
ok($result->title eq $title, 'verify title');
ok($result->summary eq $summary, 'verify summary');
ok($result->content->body eq $content, 'verify content');
ok($result->author->name eq $username, 'verify author');
my $new_title = 'Same old post';
ok($entry->title($new_title), 'rename entry');
ok($api->updateEntry($MemberURI, $entry), 'post renamed entry')
or diag($api->errstr);
$result = $api->getEntry($MemberURI);
ok($result, 'get renamed old entry')
or diag($api->errstr);
ok($result->title eq $title, 'verify title');
ok($result->summary eq "Renamed to $new_title", 'verify summary');
ok($result->content->body eq 'DeletedPage', 'verify deleted page');
ok($result->author->name eq $username, 'verify author');
my $FeedURI = "$ScriptName/atom/feed";
my $feed = $api->getFeed($FeedURI);
ok($feed, 'checking feed');
my @entries = $feed->entries;
ok($#entries >= 1, 'verify feed entries'); # at least 2, start at 0
$result = undef;
for $entry (@entries) {
if ($entry->author and $entry->author->name eq $username
and $entry->title eq $new_title) {
$result = $entry;
last;
}
}
ok($result, 'result found in the feed');
ok($result->title eq $new_title, 'verify title');
ok($result->summary eq $summary, 'verify summary');
ok(!$result->content, 'no content in the default feed');
ok($result->author->name eq $username, 'verify author');
$FeedURI = "$ScriptName/atom/full/feed?rsslimit=2";
my $feed = $api->getFeed($FeedURI);
ok($feed, 'checking full feed');
my @entries = $feed->entries;
ok($#entries >= 1, 'verify full feed entries'); # at least 2, start at 0
$result = undef;
for $entry (@entries) {
if ($entry->author and $entry->author->name eq $username
and $entry->title eq $new_title) {
$result = $entry;
last;
}
}
ok($result, 'result found in the full feed');
ok($result->title eq $new_title, 'verify title');
ok($result->summary eq $summary, 'verify summary');
sub trim {
$_ = shift;
s/^\s+//g;
s/\s+$//g;
return $_;
}
my $re = "<p>" . trim($content) . '</p>';
like($result->content->body, qr/$re/, 'verify content');
ok($result->author->name eq $username, 'verify author');