Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bamarni committed May 11, 2016
1 parent 956bde3 commit c63e038
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
10 changes: 9 additions & 1 deletion Form/Core/Type/CaptchaType.php
Expand Up @@ -88,7 +88,7 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getParent()
{
return 'text';
return 'Symfony\Component\Form\Extension\Core\Type\TextType';
}

/**
Expand All @@ -98,4 +98,12 @@ public function getName()
{
return 'genemu_captcha';
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'genemu_captcha';
}
}
13 changes: 7 additions & 6 deletions Tests/Form/Core/Type/CaptchaTypeTest.php
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Genemu\Bundle\FormBundle\Tests\Form\Type\TypeTestCase;
use Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType;

/**
* @author Olivier Chauvel <olivier@generation-multiple.com>
Expand All @@ -30,7 +31,7 @@ public function setUp()

public function testDefaultConfigs()
{
$form = $this->factory->create('genemu_captcha');
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType');
$view = $form->createView();
$captcha = $form->getConfig()->getAttribute('captcha');

Expand All @@ -43,7 +44,7 @@ public function testDefaultConfigs()

public function testConfigs()
{
$form = $this->factory->create('genemu_captcha', null, array(
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType', null, array(
'width' => 200,
'font_color' => array('000'),
'code' => '1111',
Expand All @@ -62,7 +63,7 @@ public function testConfigs()
public function testFaultFonts()
{
try {
$form = $this->factory->create('genemu_captcha', null, array(
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType', null, array(
'fonts' => array('toto.ttf')
));
} catch (FileNotFoundException $excepted) {
Expand All @@ -77,7 +78,7 @@ public function testFaultFonts()

public function testFaultFormat()
{
$form = $this->factory->create('genemu_captcha', null, array(
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType', null, array(
'format' => 'bar'
));

Expand All @@ -88,7 +89,7 @@ public function testFaultFormat()

public function testCodePasses()
{
$form = $this->factory->create('genemu_captcha');
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType');
$form->createView();

$form->submit('1234');
Expand All @@ -98,7 +99,7 @@ public function testCodePasses()

public function testCodeFails()
{
$form = $this->factory->create('genemu_captcha');
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType');
$form->createView();

$form->submit('4321');
Expand Down
17 changes: 8 additions & 9 deletions Tests/Form/Core/Type/ReCaptchaTypeTest.php
Expand Up @@ -23,7 +23,7 @@ class ReCaptchaTypeTest extends TypeTestCase
{
public function testDefaultConfigs()
{
$form = $this->factory->create('genemu_recaptcha');
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\ReCaptchaType');
$view = $form->createView();

$this->assertEquals('publicKey', $view->vars['public_key']);
Expand All @@ -35,12 +35,13 @@ public function testDefaultConfigs()
'port' => 80,
'path' => '/recaptcha/api/verify',
'timeout' => 10,
'code' => '1234',
), $form->getConfig()->getAttribute('option_validator'));
}

public function testConfigs()
{
$form = $this->factory->create('genemu_recaptcha', null, array(
$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\ReCaptchaType', null, array(
'configs' => array(
'theme' => 'blackglass',
),
Expand All @@ -55,7 +56,8 @@ public function testConfigs()
'host' => 'www.google.com',
'port' => 80,
'path' => '/recaptcha/api/verify',
'timeout' => 30
'timeout' => 30,
'code' => '1234',
), $form->getConfig()->getAttribute('option_validator'));
}

Expand All @@ -65,12 +67,9 @@ public function testConfigs()
public function testCode($code, $isValid)
{
$request = new Request(array(), array('recaptcha_response_field' => $code));
$form = $this->factory->create(new ReCaptchaType(
new ReCaptchaValidator($request, 'privateKey', array('code' => '1234')),
'publicKey',
'http://www.google.com/recaptcha/api',
array()
));
$this->requestStack->method('getMasterRequest')->willReturn($request);

$form = $this->factory->create('Genemu\Bundle\FormBundle\Form\Core\Type\ReCaptchaType');

$form->submit(null);

Expand Down
13 changes: 7 additions & 6 deletions Tests/Form/Extension/TypeExtensionTest.php
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\Form\Extension\Core\CoreExtension;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

use Genemu\Bundle\FormBundle\Gd\Type\Captcha;
use Genemu\Bundle\FormBundle\Form\Core\Validator\ReCaptchaValidator;
Expand All @@ -25,11 +25,11 @@
*/
class TypeExtensionTest extends CoreExtension
{
protected $request;
protected $requestStack;

public function __construct(Request $request)
public function __construct(RequestStack $requestStack)
{
$this->request = $request;
$this->requestStack = $requestStack;
}

protected function loadTypes()
Expand Down Expand Up @@ -67,13 +67,14 @@ protected function loadTypes()
)),
new Form\Core\Type\ReCaptchaType(
new ReCaptchaValidator(
$this->request,
$this->requestStack,
'privateKey',
array(
'host' => 'www.google.com',
'port' => 80,
'path' => '/recaptcha/api/verify',
'timeout' => 10
'timeout' => 10,
'code' => '1234',
)),
'publicKey',
'http://www.google.com/recaptcha/api',
Expand Down
8 changes: 5 additions & 3 deletions Tests/Form/Type/TypeTestCase.php
Expand Up @@ -19,6 +19,8 @@
*/
abstract class TypeTestCase extends BaseTypeTestCase
{
protected $requestStack;

public function setUp()
{
parent::setUp();
Expand All @@ -29,12 +31,12 @@ public function setUp()
protected function getExtensions()
{
return array(
new TypeExtensionTest($this->createRequestMock())
new TypeExtensionTest($this->createRequestStackMock())
);
}

protected function createRequestMock()
protected function createRequestStackMock()
{
return $this->getMock('Symfony\Component\HttpFoundation\Request');
return $this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
}
}

0 comments on commit c63e038

Please sign in to comment.