atom.t 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # Copyright (C) 2006–2019 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. require './t/test.pl';
  16. package OddMuse;
  17. use Test::More tests => 44;
  18. use LWP::UserAgent;
  19. use XML::Atom::Client;
  20. use XML::Atom::Entry;
  21. use XML::Atom::Person;
  22. add_module('atom.pl');
  23. start_server();
  24. # Check whether the child is up and running
  25. my $ua = LWP::UserAgent->new;
  26. my $response = $ua->get("$ScriptName?action=version");
  27. ok($response->is_success, "There is a wiki running at $ScriptName");
  28. like($response->content, qr/\batom\.pl/, "The server has the atom extension installed");
  29. # Testing the Atom API
  30. my $api = XML::Atom::Client->new;
  31. my $entry = XML::Atom::Entry->new;
  32. my $title = 'New Post';
  33. my $summary = 'Created';
  34. my $content = 'Content of my post ' . rand(999) . "\n";
  35. my $username = 'Alex';
  36. ok($entry->title($title), 'set post title');
  37. ok($entry->summary($summary), 'set post summary');
  38. ok($entry->content($content), 'set post content');
  39. my $author = XML::Atom::Person->new;
  40. ok($author->name($username), 'set author name');
  41. ok($entry->author($author), 'set entry author');
  42. my $PostURI = "$ScriptName/atom";
  43. my $MemberURI = $api->createEntry($PostURI, $entry);
  44. ok($MemberURI, "posting entry returns member URI $MemberURI")
  45. or diag($api->errstr);
  46. my $result = $api->getEntry($MemberURI);
  47. ok($result, 'get created entry')
  48. or diag($api->errstr);
  49. ok($result->title eq $title, 'verify title');
  50. ok($result->summary eq $summary, 'verify summary');
  51. ok($result->content->body eq $content, 'verify content');
  52. ok($result->author->name eq $username, 'verify author');
  53. $MemberURI = '';
  54. my @links = ($result->link);
  55. ok($#links >= 0, 'verify link');
  56. for my $link (@links) {
  57. if ($link->rel eq 'edit') {
  58. $MemberURI = $link->href;
  59. last;
  60. }
  61. }
  62. ok($MemberURI, "entry contains member URI $MemberURI");
  63. $summary = 'Updated';
  64. $content = "No more random numbers!\n";
  65. ok($entry->summary($summary), 'change summary');
  66. ok($entry->content($content), 'change content');
  67. ok($api->updateEntry($MemberURI, $entry), 'update entry')
  68. or diag($api->errstr);
  69. $result = $api->getEntry($MemberURI);
  70. ok($result, 'get updated entry')
  71. or diag($api->errstr);
  72. ok($result->title eq $title, 'verify title');
  73. ok($result->summary eq $summary, 'verify summary');
  74. ok($result->content->body eq $content, 'verify content');
  75. ok($result->author->name eq $username, 'verify author');
  76. my $new_title = 'Same old post';
  77. ok($entry->title($new_title), 'rename entry');
  78. ok($api->updateEntry($MemberURI, $entry), 'post renamed entry')
  79. or diag($api->errstr);
  80. $result = $api->getEntry($MemberURI);
  81. ok($result, 'get renamed old entry')
  82. or diag($api->errstr);
  83. ok($result->title eq $title, 'verify title');
  84. ok($result->summary eq "Renamed to $new_title", 'verify summary');
  85. ok($result->content->body eq 'DeletedPage', 'verify deleted page');
  86. ok($result->author->name eq $username, 'verify author');
  87. my $FeedURI = "$ScriptName/atom/feed";
  88. my $feed = $api->getFeed($FeedURI);
  89. ok($feed, 'checking feed');
  90. my @entries = $feed->entries;
  91. ok($#entries >= 1, 'verify feed entries'); # at least 2, start at 0
  92. $result = undef;
  93. for $entry (@entries) {
  94. if ($entry->author and $entry->author->name eq $username
  95. and $entry->title eq $new_title) {
  96. $result = $entry;
  97. last;
  98. }
  99. }
  100. ok($result, 'result found in the feed');
  101. ok($result->title eq $new_title, 'verify title');
  102. ok($result->summary eq $summary, 'verify summary');
  103. ok(!$result->content, 'no content in the default feed');
  104. ok($result->author->name eq $username, 'verify author');
  105. $FeedURI = "$ScriptName/atom/full/feed?rsslimit=2";
  106. my $feed = $api->getFeed($FeedURI);
  107. ok($feed, 'checking full feed');
  108. my @entries = $feed->entries;
  109. ok($#entries >= 1, 'verify full feed entries'); # at least 2, start at 0
  110. $result = undef;
  111. for $entry (@entries) {
  112. if ($entry->author and $entry->author->name eq $username
  113. and $entry->title eq $new_title) {
  114. $result = $entry;
  115. last;
  116. }
  117. }
  118. ok($result, 'result found in the full feed');
  119. ok($result->title eq $new_title, 'verify title');
  120. ok($result->summary eq $summary, 'verify summary');
  121. sub trim {
  122. $_ = shift;
  123. s/^\s+//g;
  124. s/\s+$//g;
  125. return $_;
  126. }
  127. my $re = "<p>" . trim($content) . '</p>';
  128. like($result->content->body, qr/$re/, 'verify content');
  129. ok($result->author->name eq $username, 'verify author');