atom.t 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Copyright (C) 2006–2015 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. # Give the child time to start
  25. sleep 1;
  26. # Check whether the child is up and running
  27. my $ua = LWP::UserAgent->new;
  28. my $response = $ua->get("$ScriptName?action=version");
  29. ok($response->is_success, "There is a wiki running at $ScriptName");
  30. like($response->content, qr/\batom\.pl/, "The server has the atom extension installed");
  31. # Testing the Atom API
  32. my $api = XML::Atom::Client->new;
  33. my $entry = XML::Atom::Entry->new;
  34. my $title = 'New Post';
  35. my $summary = 'Created';
  36. my $content = 'Content of my post ' . rand(999) . "\n";
  37. my $username = 'Alex';
  38. ok($entry->title($title), 'set post title');
  39. ok($entry->summary($summary), 'set post summary');
  40. ok($entry->content($content), 'set post content');
  41. my $author = XML::Atom::Person->new;
  42. ok($author->name($username), 'set author name');
  43. ok($entry->author($author), 'set entry author');
  44. my $PostURI = "$ScriptName/atom";
  45. my $MemberURI = $api->createEntry($PostURI, $entry);
  46. ok($MemberURI, "posting entry returns member URI $MemberURI")
  47. or diag($api->errstr);
  48. my $result = $api->getEntry($MemberURI);
  49. ok($result, 'get created entry')
  50. or diag($api->errstr);
  51. ok($result->title eq $title, 'verify title');
  52. ok($result->summary eq $summary, 'verify summary');
  53. ok($result->content->body eq $content, 'verify content');
  54. ok($result->author->name eq $username, 'verify author');
  55. $MemberURI = '';
  56. my @links = ($result->link);
  57. ok($#links >= 0, 'verify link');
  58. for my $link (@links) {
  59. if ($link->rel eq 'edit') {
  60. $MemberURI = $link->href;
  61. last;
  62. }
  63. }
  64. ok($MemberURI, "entry contains member URI $MemberURI");
  65. $summary = 'Updated';
  66. $content = "No more random numbers!\n";
  67. ok($entry->summary($summary), 'change summary');
  68. ok($entry->content($content), 'change content');
  69. ok($api->updateEntry($MemberURI, $entry), 'update entry')
  70. or diag($api->errstr);
  71. $result = $api->getEntry($MemberURI);
  72. ok($result, 'get updated entry')
  73. or diag($api->errstr);
  74. ok($result->title eq $title, 'verify title');
  75. ok($result->summary eq $summary, 'verify summary');
  76. ok($result->content->body eq $content, 'verify content');
  77. ok($result->author->name eq $username, 'verify author');
  78. my $new_title = 'Same old post';
  79. ok($entry->title($new_title), 'rename entry');
  80. ok($api->updateEntry($MemberURI, $entry), 'post renamed entry')
  81. or diag($api->errstr);
  82. $result = $api->getEntry($MemberURI);
  83. ok($result, 'get renamed old entry')
  84. or diag($api->errstr);
  85. ok($result->title eq $title, 'verify title');
  86. ok($result->summary eq "Renamed to $new_title", 'verify summary');
  87. ok($result->content->body eq 'DeletedPage', 'verify deleted page');
  88. ok($result->author->name eq $username, 'verify author');
  89. my $FeedURI = "$ScriptName/atom/feed";
  90. my $feed = $api->getFeed($FeedURI);
  91. ok($feed, 'checking feed');
  92. my @entries = $feed->entries;
  93. ok($#entries >= 1, 'verify feed entries'); # at least 2, start at 0
  94. $result = undef;
  95. for $entry (@entries) {
  96. if ($entry->author and $entry->author->name eq $username
  97. and $entry->title eq $new_title) {
  98. $result = $entry;
  99. last;
  100. }
  101. }
  102. ok($result, 'result found in the feed');
  103. ok($result->title eq $new_title, 'verify title');
  104. ok($result->summary eq $summary, 'verify summary');
  105. ok(!$result->content, 'no content in the default feed');
  106. ok($result->author->name eq $username, 'verify author');
  107. $FeedURI = "$ScriptName/atom/full/feed?rsslimit=2";
  108. my $feed = $api->getFeed($FeedURI);
  109. ok($feed, 'checking full feed');
  110. my @entries = $feed->entries;
  111. ok($#entries >= 1, 'verify full feed entries'); # at least 2, start at 0
  112. $result = undef;
  113. for $entry (@entries) {
  114. if ($entry->author and $entry->author->name eq $username
  115. and $entry->title eq $new_title) {
  116. $result = $entry;
  117. last;
  118. }
  119. }
  120. ok($result, 'result found in the full feed');
  121. ok($result->title eq $new_title, 'verify title');
  122. ok($result->summary eq $summary, 'verify summary');
  123. sub trim {
  124. $_ = shift;
  125. s/^\s+//g;
  126. s/\s+$//g;
  127. return $_;
  128. }
  129. ok(trim($result->content->body) eq ("<p>" . trim($content) . '</p>'), 'verify content');
  130. ok($result->author->name eq $username, 'verify author');