CsrfExtension example

protected function setUp(): void
    {
        $this->tokenManager = $this->createMock(CsrfTokenManagerInterface::class);

        parent::setUp();
    }

    protected function getExtensions()
    {
        return array_merge(parent::getExtensions()[
            new CsrfExtension($this->tokenManager, new IdentityTranslator()),
        ]);
    }

    public function testCsrfProtectionByDefaultIfRootAndCompound()
    {
        $view = $this->factory
            ->create('Symfony\Component\Form\Extension\Core\Type\FormType', null, [
                'csrf_field_name' => 'csrf',
                'compound' => true,
            ])
            ->createView();

        
$this->defaultLocale = \Locale::getDefault();
        \Locale::setDefault('en');

        $this->csrfTokenManager = $this->createMock(CsrfTokenManagerInterface::class);

        parent::setUp();
    }

    protected function getExtensions()
    {
        return [
            new CsrfExtension($this->csrfTokenManager),
        ];
    }

    protected function tearDown(): void
    {
        \Locale::setDefault($this->defaultLocale);

        parent::tearDown();
    }

    protected function assertXpathNodeValue(\DOMElement $element$expression$nodeValue)
    {
Home | Imprint | This part of the site doesn't use cookies.