File: 10.get_html.t

package info (click to toggle)
libcaptcha-recaptcha-perl 0.94-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 112 kB
  • sloc: perl: 183; makefile: 2
file content (90 lines) | stat: -rw-r--r-- 3,891 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use strict;
use warnings;
use Test::More;
use Captcha::reCAPTCHA;

# Looks real. Isn't.
use constant PUBKEY => '6LdAAAkAwAAAFJj6ACG3Wlix_GuQJMNGjMQnw5UY';

my @schedule;

BEGIN {
  my $pubkey = PUBKEY;

  @schedule = (
    {
      name => 'Simple',
      args => [$pubkey],
      expect =>
       qq{<script src="http://www.google.com/recaptcha/api/challenge?k=$pubkey" }
       . qq{type="text/javascript"></script>\n}
       . qq{<noscript><iframe frameborder="0" height="300" }
       . qq{src="http://www.google.com/recaptcha/api/noscript?k=$pubkey" }
       . qq{width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" }
       . qq{rows="3"></textarea><input name="recaptcha_response_field" type="hidden" }
       . qq{value="manual_challenge" /></noscript>\n}
    },
    {
      name => 'Error',
      args => [ $pubkey, '<<some random error>>' ],
      expect =>
       qq{<script src="http://www.google.com/recaptcha/api/challenge?error=%3c%3csome+random+error%3e%3e&amp;k=$pubkey" }
       . qq{type="text/javascript"></script>\n}
       . qq{<noscript><iframe frameborder="0" height="300" }
       . qq{src="http://www.google.com/recaptcha/api/noscript?error=%3c%3csome+random+error%3e%3e&amp;k=$pubkey" }
       . qq{width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" }
       . qq{rows="3"></textarea><input name="recaptcha_response_field" type="hidden" }
       . qq{value="manual_challenge" /></noscript>\n}
    },
    {
      name => 'Error in hash',
      args =>
       [ $pubkey, { is_valid => 0, error => '<<some random error>>' } ],
      expect =>
       qq{<script src="http://www.google.com/recaptcha/api/challenge?error=%3c%3csome+random+error%3e%3e&amp;k=$pubkey" }
       . qq{type="text/javascript"></script>\n}
       . qq{<noscript><iframe frameborder="0" height="300" }
       . qq{src="http://www.google.com/recaptcha/api/noscript?error=%3c%3csome+random+error%3e%3e&amp;k=$pubkey" }
       . qq{width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" }
       . qq{rows="3"></textarea><input name="recaptcha_response_field" type="hidden" }
       . qq{value="manual_challenge" /></noscript>\n}
    },
    {
      name => 'Secure',
      args => [ $pubkey, undef, 1 ],
      expect =>
       qq{<script src="https://www.google.com/recaptcha/api/challenge?k=$pubkey" }
       . qq{type="text/javascript"></script>\n}
       . qq{<noscript><iframe frameborder="0" height="300" }
       . qq{src="https://www.google.com/recaptcha/api/noscript?k=$pubkey" }
       . qq{width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" }
       . qq{rows="3"></textarea><input name="recaptcha_response_field" type="hidden" }
       . qq{value="manual_challenge" /></noscript>\n}
    },
    {
      name => 'Options',
      args =>
       [ $pubkey, undef, 0, { theme => 'white', tabindex => 3 } ],
      expect =>
       qq(<script type="text/javascript">\n//<![CDATA[\nvar RecaptchaOptions = )
       . qq({"tabindex":3,"theme":"white"};\n//]]>\n</script>\n)
       . qq{<script src="http://www.google.com/recaptcha/api/challenge?k=$pubkey" }
       . qq{type="text/javascript"></script>\n}
       . qq{<noscript><iframe frameborder="0" height="300" }
       . qq{src="http://www.google.com/recaptcha/api/noscript?k=$pubkey" }
       . qq{width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" }
       . qq{rows="3"></textarea><input name="recaptcha_response_field" type="hidden" }
       . qq{value="manual_challenge" /></noscript>\n}
    },
  );
  plan tests => 3 * @schedule;
}

for my $test ( @schedule ) {
  my $name = $test->{name};
  ok my $captcha = Captcha::reCAPTCHA->new(), "$name: Created OK";
  isa_ok $captcha, 'Captcha::reCAPTCHA';
  my $args = $test->{args};
  my $html = $captcha->get_html( @$args );
  is $html, $test->{expect}, "$name: Generate HTML OK";
}