Debian Codegraph @

xt/captcha2.t

raw
1 use strict;
2 use warnings;
3
4 use lib 'xt/lib/';
5
6 # HFH::TraitFor::Captcha and HFH::Field::Captcha do not work with current
7 # versions of Catalyst.
8 #
9 # The reason seems to be that get_captcha and set_captcha use
10 # $form->ctx->{session} directly, instead of using the accessor
11 # $from->ctx->session.
12 #
13 # I am not sure if this works with older versions of Catalyst, but it is
14 # definitely broken when using Catalyst 5.90007
15 #
16 # I have attached a simple test.
17 #
18 # The patch makes get_captcha and set_captcha using the session-accessor
19 # IF $form->ctx has one. (if it is a catalyst context). Otherwise, the old
20 # behaviour will not change. The module should still work with
21 # non-catalyst applications.
22
23 use Test::More;
24 my @missing;
25 eval" use Test::WWW::Mechanize::Catalyst; ";
26 if($@){
27 push @missing, "Test::WWW::Mechanize";
28 }
29 eval" use GD::SecurityImage; ";
30 if($@){
31 push @missing, "GD::SecurityImage";
32 }
33
34 if(@missing){
35 plan skip_all => "The following Modules are required to run this test: " . join ", ", @missing;
36 }
37 else{
38 plan tests => 7;
39 }
40 my $mech = Test::WWW::Mechanize::Catalyst->new(catalyst_app => "MyCatalystApp");
41
42 $mech->get_ok("/captcha");
43 #diag explain $mech;
44
45 $mech->content_contains('<img src="/captcha/image"/><input id="captcha" name="captcha"/>');
46
47 $mech->get_ok("/captcha/get_rnd");
48
49 my $rnd = $mech->content;
50
51 $mech->get_ok("/captcha/image");
52
53 is $mech->res->content_type, "image/png";
54
55 $mech->get_ok("/captcha?captcha=$rnd");
56
57 $mech->content_is("verification succeeded");
58
59 done_testing;
60 exit;
61