Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit 1d93b80

Browse files
committed
Configuration cleanup
1 parent 9e722ca commit 1d93b80

3 files changed

Lines changed: 112 additions & 1 deletion

File tree

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private function addServiceDefinitionConfiguration(ArrayNodeDefinition $node) {
7171
$node
7272
->children()
7373
->arrayNode('service_definition')
74-
->arrayPrototype()
74+
->prototype('array')
7575
->children()
7676
->scalarNode('service_name')->isRequired()->end()
7777
->arrayNode('options')

tests/DependencyInjection/EWZRecaptchaExtensionTest.php

100644100755
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ public function testSimpleConfiguration()
5959
);
6060
}
6161

62+
public function testSimpleV3Configuration()
63+
{
64+
$this->configuration = new ContainerBuilder();
65+
$loader = new EWZRecaptchaExtension();
66+
$config = $this->getSimpleConfig();
67+
$loader->load([$config], $this->configuration);
68+
69+
$this->assertParameter(true, 'ewz_recaptcha.enabled');
70+
$this->assertParameter('foo_public_key', 'ewz_recaptcha.public_key');
71+
$this->assertParameter('bar_private_key', 'ewz_recaptcha.private_key');
72+
73+
$this->assertHasDefinition('ewz_recaptcha.v3.form.type');
74+
$this->assertHasDefinition('ewz_recaptcha.validator.v3.true');
75+
$this->assertHasDefinition('ewz_recaptcha.recaptcha');
76+
77+
}
78+
6279
public function testFullConfiguration()
6380
{
6481
$this->configuration = new ContainerBuilder();
@@ -140,6 +157,11 @@ private function assertHasDefinition($id)
140157
$this->assertTrue(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id)));
141158
}
142159

160+
private function assertNotHasDefinition($id)
161+
{
162+
$this->assertFalse(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id)));
163+
}
164+
143165
private function assertDefinitionHasReferenceArgument($id, $index, $expectedArgumentValue)
144166
{
145167
$definition = $this->configuration->getDefinition($id);
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace EWZ\Tests\Bundle\RecaptchaBundle\Form\Type;
4+
5+
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
6+
use PHPUnit\Framework\TestCase;
7+
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
8+
use Symfony\Component\Form\Extension\Core\Type\TextType;
9+
use Symfony\Component\Form\FormInterface;
10+
use Symfony\Component\Form\FormView;
11+
use Symfony\Component\HttpFoundation\RequestStack;
12+
use Symfony\Component\OptionsResolver\OptionsResolver;
13+
14+
class EWZRecaptchaV3TypeTest extends TestCase
15+
{
16+
/** @var EWZRecaptchaV3Type */
17+
protected $type;
18+
19+
protected function setUp()
20+
{
21+
$requestStack = $this->createMock(RequestStack::class);
22+
$this->type = new EWZRecaptchaV3Type('key', true, true, 'www.google.com');
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function buildView()
29+
{
30+
$view = new FormView();
31+
32+
/** @var FormInterface $form */
33+
$form = $this->createMock(FormInterface::class);
34+
35+
$this->assertArrayNotHasKey('ewz_recaptcha_enabled', $view->vars);
36+
$this->assertArrayNotHasKey('ewz_recaptcha_hide_badge', $view->vars);
37+
38+
$this->type->buildView($view, $form, array());
39+
40+
$this->assertTrue($view->vars['ewz_recaptcha_enabled']);
41+
$this->assertTrue($view->vars['ewz_recaptcha_hide_badge']);
42+
}
43+
44+
/**
45+
* @test
46+
*/
47+
public function getParent()
48+
{
49+
$this->assertSame(HiddenType::class, $this->type->getParent());
50+
}
51+
52+
/**
53+
* @test
54+
*/
55+
public function getPublicKey()
56+
{
57+
$this->assertSame('key', $this->type->getPublicKey());
58+
}
59+
60+
/**
61+
* @test
62+
*/
63+
public function configureOptions()
64+
{
65+
$optionsResolver = new OptionsResolver();
66+
67+
$this->type->configureOptions($optionsResolver);
68+
69+
$options = $optionsResolver->resolve();
70+
71+
$expected = array(
72+
'label' => false,
73+
'mapped' => false,
74+
'validation_groups' => [ 'Default' ],
75+
'script_nonce_csp' => '',
76+
'action_name' => 'form',
77+
);
78+
79+
$this->assertSame($expected, $options);
80+
}
81+
82+
/**
83+
* @test
84+
*/
85+
public function getBlockPrefix()
86+
{
87+
$this->assertEquals('ewz_recaptcha', $this->type->getBlockPrefix());
88+
}
89+
}

0 commit comments

Comments
 (0)