|
| 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