pingback-server.t 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright (C) 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 => 13;
  18. use LWP::UserAgent;
  19. use RPC::XML::Client;
  20. use RPC::XML;
  21. add_module('pingback-server.pl');
  22. AppendStringToFile($ConfigFile, "\$CommentsPrefix = 'Comments_on_';\n");
  23. # This test is is going to use two servers in addition to this script, but in
  24. # actual fact we are all going to share the data directory.
  25. test_page(update_page('Target', 'This is the test page.'), 'This is the test page');
  26. # Server 1 is going to be the pingback server.
  27. start_server();
  28. # Check whether the child is up and running
  29. my $ua = LWP::UserAgent->new;
  30. my $response = $ua->get("$ScriptName?action=version");
  31. ok($response->is_success, "There is a wiki running at $ScriptName");
  32. like($response->decoded_content, qr/\bpingback-server\.pl/, "The server has the pingback-server extension installed");
  33. # Now that we have the pingback server running, we need to get the URL of the
  34. # test page, including its port.
  35. my $target_url = ScriptUrl('Target');
  36. my $pingback_url = ScriptUrl('pingback/Target');
  37. # Verify that the target exists via external request
  38. $response = $ua->get($target_url);
  39. ok($response->is_success, "Target URL response");
  40. like($response->decoded_content, qr/This is the test page/, "Target URL decoded");
  41. # Create the Source page before starting the next server (so that it knows about
  42. # the new page)
  43. test_page(update_page('Source', "Link to $target_url"), 'Link to');
  44. # Server 2 is going to be the source server.
  45. start_server(2);
  46. # Check whether the child is up and running (with a new $ScriptName!)
  47. $response = $ua->get("$ScriptName?action=version");
  48. ok($response->is_success, "There is a wiki running at $ScriptName");
  49. # New script name means we can now get the source_url.
  50. my $source_url = ScriptUrl('Source');
  51. # Verify that the source exists via external request
  52. $response = $ua->get($source_url);
  53. ok($response->is_success, "Source URL response");
  54. like($response->decoded_content, qr/Link to/, "Source URL decoded");
  55. like($response->decoded_content, qr/$target_url/, "Source page links to Target page");
  56. my $client = RPC::XML::Client->new($pingback_url);
  57. my $source = RPC::XML::string->new($source_url);
  58. my $target = RPC::XML::string->new($target_url);
  59. my $request = RPC::XML::request->new('pingback.ping', $source, $target);
  60. my $response = $client->send_request($request);
  61. ok(ref($response), 'Got a response reference');
  62. test_page(get_page('Comments_on_Target'),
  63. 'Pingback:',
  64. $source_url);