File: sfWidgetFormReCaptchaTest.php

package info (click to toggle)
netbeans 7.0.1%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 625,684 kB
  • sloc: java: 4,186,825; xml: 465,705; php: 38,485; cpp: 19,252; ansic: 13,667; jsp: 10,961; sh: 9,710; sql: 1,469; makefile: 991; haskell: 698; objc: 288; perl: 265; fortran: 262; yacc: 30; awk: 17; lex: 11; asm: 4
file content (48 lines) | stat: -rw-r--r-- 2,076 bytes parent folder | download
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
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require_once dirname(__FILE__).'/../bootstrap.php';
require_once dirname(__FILE__).'/../../lib/widget/sfWidgetFormReCaptcha.class.php';
require_once $_SERVER['SYMFONY'].'/util/sfDomCssSelector.class.php';

$t = new lime_test(7, new lime_output_color());

$REMOTE_ADDR = 'symfony.example.com';
$PUBLIC_KEY  = '6Lf2DQEAAAAAALB9pGaVdcjMiv4CAuOVkfCSVvGh';
$PRIVATE_KEY = '6Lf2DQEAAAAAALnEL0iEogIxZNYMlG7pmNhwEXjk';

// __construct()
$t->diag('__construct()');
try
{
  new sfWidgetFormReCaptcha();
}
catch (RuntimeException $e)
{
  $t->pass('__construct() expects a "public_key" option');
}

// ->render()
$t->diag('->render()');
$w = new sfWidgetFormReCaptcha(array('public_key' => $PUBLIC_KEY));
$dom = new DomDocument('1.0', 'utf-8');
$dom->loadHTML($w->render('captcha'));
$c = new sfDomCssSelector($dom);
$t->is(count($c->matchSingle('script[src^="http://"]')->getNodes()), 1, '->render() uses the HTTP ReCaptcha URL by default');
$t->is(count($c->matchSingle(sprintf('script[src$="%s"]', $PUBLIC_KEY))->getNodes()), 1, '->render() embeds the ReCatpcha public key in the URL');
$t->is(count($c->matchSingle('iframe[src^="http://"]')->getNodes()), 1, '->render() uses the HTTP ReCaptcha URL by default');
$t->is(count($c->matchSingle(sprintf('iframe[src$="%s"]', $PUBLIC_KEY))->getNodes()), 1, '->render() embeds the ReCatpcha public key in the URL');

$w = new sfWidgetFormReCaptcha(array('public_key' => $PUBLIC_KEY, 'use_ssl' => true));
$dom = new DomDocument('1.0', 'utf-8');
$dom->loadHTML($w->render('captcha'));
$c = new sfDomCssSelector($dom);
$t->is(count($c->matchSingle('script[src^="https://"]')->getNodes()), 1, '->render() uses the HTTPS ReCaptcha URL is use_ssl is true');
$t->is(count($c->matchSingle('iframe[src^="https://"]')->getNodes()), 1, '->render() uses the HTTPS ReCaptcha URL is use_ssl is true');