Merge branch 'topic/image_upload'
[sgn.git] / t / integration / ajax.t
blob9ca57abc99a4ba0b1a415250097ae985f1cbc874
1 =head1 NAME
3 t/integration/ajax.t - Integration tests for AJAXy stuff
5 =head1 DESCRIPTION
7 Tests for AJAXy stuff.
9 =head1 AUTHORS
11 Jonathan "Duke" Leto
13 =cut
15 use strict;
16 use warnings;
17 use Test::More;
18 use Test::JSON;
19 use Test::WWW::Mechanize;
20 use lib 't/lib';
21 use SGN::Test;
23 my $base_url = $ENV{SGN_TEST_SERVER};
24 my $mech = Test::WWW::Mechanize->new;
26 my $ajax_urls = {
27     "/image/ajax/image_ajax_form.pl?action=view" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null,"error":"No object_id provided"}',
28     "/image/ajax/image_ajax_form.pl?action=" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null,"error":"No object_id provided"}',
29     "/image/ajax/image_ajax_form.pl" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null,"error":"No object_id provided"}',
30     "/image/ajax/image_ajax_form.pl?action=edit" => '{"is_owner":0,"user_type":"user","html":"<form id =\"image_form\" method=\"get\" action=\"\"> <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td> <input type=\"text\" id=\"\" name=\"name\" value=\"\" size=\"15\" />\n</td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td> <input type=\"text\" id=\"\" name=\"description\" value=\"\" size=\"40\" />\n</td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </td></tr>\n <tr><td colspan=\"3\" align=\"center\">  <input type=\"hidden\" id=\"\" name=\"object_id\" value=\"\" />  <input type=\"hidden\" id=\"\" name=\"action\" value=\"store\" />  </td></tr></table> ","editable_form_id":"image_form","error":"No object_id provided", "login":1}',
31     "/image/ajax/image_ajax_form.pl?object_id=0" => '{"is_owner":0,"user_type":"user","html":" <table> <tr><td>Image Name:</td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Image Description: </td><td width=\"20\">&nbsp;</td><td><b>\n</b></td></tr>\n<tr><td>Uploaded by: </td><td width=\"20\">&nbsp;</td><td><b><a href=\"/solpeople/personal-info.pl?sp_person_id=\">  </a> </b></td></tr>\n </table> ","editable_form_id":null}',
34 plan( tests => 3*(scalar keys %$ajax_urls));
36 while( my ($url, $json) = each %$ajax_urls) {
37     $mech->get_ok("$base_url/$url");
38     is_valid_json($mech->content, "$url is valid JSON");
39     is_json($mech->content, $ajax_urls->{$url}, "$url has the expected JSON");