Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@..

Decoded Output download

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Bridge\Twig\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\HtmlSanitizerExtension;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerInterface;
use Twig\Environment;
use Twig\Loader\ArrayLoader;

class HtmlSanitizerExtensionTest extends TestCase
{
    public function testSanitizeHtml()
    {
        $loader = new ArrayLoader([
            'foo' => '{{ "foobar"|sanitize_html }}',
            'bar' => '{{ "foobar"|sanitize_html("bar") }}',
        ]);

        $twig = new Environment($loader, ['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);

        $fooSanitizer = $this->createMock(HtmlSanitizerInterface::class);
        $fooSanitizer->expects($this->once())
            ->method('sanitize')
            ->with('foobar')
            ->willReturn('foo');

        $barSanitizer = $this->createMock(HtmlSanitizerInterface::class);
        $barSanitizer->expects($this->once())
            ->method('sanitize')
            ->with('foobar')
            ->willReturn('bar');

        $twig->addExtension(new HtmlSanitizerExtension(new ServiceLocator([
            'foo' => fn () => $fooSanitizer,
            'bar' => fn () => $barSanitizer,
        ]), 'foo'));

        $this->assertSame('foo', $twig->render('foo'));
        $this->assertSame('bar', $twig->render('bar'));
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Bridge\Twig\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Extension\HtmlSanitizerExtension;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerInterface;
use Twig\Environment;
use Twig\Loader\ArrayLoader;

class HtmlSanitizerExtensionTest extends TestCase
{
    public function testSanitizeHtml()
    {
        $loader = new ArrayLoader([
            'foo' => '{{ "foobar"|sanitize_html }}',
            'bar' => '{{ "foobar"|sanitize_html("bar") }}',
        ]);

        $twig = new Environment($loader, ['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);

        $fooSanitizer = $this->createMock(HtmlSanitizerInterface::class);
        $fooSanitizer->expects($this->once())
            ->method('sanitize')
            ->with('foobar')
            ->willReturn('foo');

        $barSanitizer = $this->createMock(HtmlSanitizerInterface::class);
        $barSanitizer->expects($this->once())
            ->method('sanitize')
            ->with('foobar')
            ->willReturn('bar');

        $twig->addExtension(new HtmlSanitizerExtension(new ServiceLocator([
            'foo' => fn () => $fooSanitizer,
            'bar' => fn () => $barSanitizer,
        ]), 'foo'));

        $this->assertSame('foo', $twig->render('foo'));
        $this->assertSame('bar', $twig->render('bar'));
    }
}

Function Calls

None

Variables

None

Stats

MD5 d8f49a964745b42e9832d8f26fe8f90e
Eval Count 0
Decode Time 124 ms