mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 03:16:34 +00:00
Fix merge conflict resolution
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Twig\Tests\Extension;
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\SyntaxError;
|
||||
@@ -839,12 +840,10 @@ EOF
|
||||
return $twig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
#[IgnoreDeprecations]
|
||||
public function testSandboxSourcePolicyEnableReturningFalse()
|
||||
{
|
||||
$this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
$this->expectUserDeprecationMessage('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
|
||||
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class implements SourcePolicyInterface {
|
||||
public function enableSandbox(Source $source): bool
|
||||
@@ -855,12 +854,10 @@ EOF
|
||||
$this->assertEquals('FOO', $twig->load('1_basic')->render(self::$params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
#[IgnoreDeprecations]
|
||||
public function testSandboxSourcePolicyEnableReturningTrue()
|
||||
{
|
||||
$this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
$this->expectUserDeprecationMessage('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
|
||||
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class implements SourcePolicyInterface {
|
||||
public function enableSandbox(Source $source): bool
|
||||
@@ -872,12 +869,10 @@ EOF
|
||||
$twig->load('1_basic')->render([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
#[IgnoreDeprecations]
|
||||
public function testSandboxSourcePolicyFalseDoesntOverrideOtherEnables()
|
||||
{
|
||||
$this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
$this->expectUserDeprecationMessage('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
|
||||
$twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], [], new class implements SourcePolicyInterface {
|
||||
public function enableSandbox(Source $source): bool
|
||||
@@ -889,46 +884,10 @@ EOF
|
||||
$twig->load('1_basic')->render([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*
|
||||
* @dataProvider provideSourcePolicyArrowBlockedTemplates
|
||||
*/
|
||||
public function testSourcePolicyBlocksNonClosureCallableInArrow(string $template)
|
||||
{
|
||||
$this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
|
||||
$sourcePolicy = new class implements SourcePolicyInterface {
|
||||
public function enableSandbox(Source $source): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
$twig = $this->getEnvironment(false, [], ['1_basic' => $template], [], ['sort', 'filter', 'map', 'reduce', 'find', 'join'], [], [], [], $sourcePolicy);
|
||||
|
||||
$this->expectException(RuntimeError::class);
|
||||
$this->expectExceptionMessageMatches('/must be a Closure in sandbox mode/');
|
||||
$twig->load('1_basic')->render([]);
|
||||
}
|
||||
|
||||
public static function provideSourcePolicyArrowBlockedTemplates(): iterable
|
||||
{
|
||||
yield 'sort' => ['{{ ["a","b"]|sort("strnatcasecmp")|join }}'];
|
||||
yield 'filter' => ['{{ ["a","b"]|filter("is_string")|join }}'];
|
||||
yield 'map' => ['{{ ["a","b"]|map("strtoupper")|join }}'];
|
||||
yield 'reduce' => ['{{ [1,2]|reduce("intval") }}'];
|
||||
yield 'find' => ['{{ ["a","b"]|find("is_string") }}'];
|
||||
yield 'has some' => ['{{ [1,2] has some "is_string" ? "yes" : "no" }}'];
|
||||
yield 'has every' => ['{{ [1,2] has every "is_int" ? "yes" : "no" }}'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
#[IgnoreDeprecations]
|
||||
public function testSourcePolicyAllowsClosureInArrow()
|
||||
{
|
||||
$this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
$this->expectUserDeprecationMessage('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
|
||||
$sourcePolicy = new class implements SourcePolicyInterface {
|
||||
public function enableSandbox(Source $source): bool
|
||||
@@ -941,25 +900,6 @@ EOF
|
||||
$this->assertSame('a,b', $twig->load('1_basic')->render([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testNonSandboxedSourcePolicyAllowsNonClosureCallable()
|
||||
{
|
||||
$this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
$this->expectDeprecation('Since twig/twig 3.15: Passing a callable that is not a PHP \Closure as an argument to the "sort" filter is deprecated.');
|
||||
|
||||
$sourcePolicy = new class implements SourcePolicyInterface {
|
||||
public function enableSandbox(Source $source): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
$twig = $this->getEnvironment(false, [], ['1_basic' => '{{ ["b","a"]|sort("strnatcasecmp")|join(",") }}'], [], ['sort', 'join'], [], [], [], $sourcePolicy);
|
||||
$this->assertSame('a,b', $twig->load('1_basic')->render([]));
|
||||
}
|
||||
|
||||
public function testNeedsIsSandboxedFilterReceivesTrueWhenSandboxed()
|
||||
{
|
||||
$twig = $this->getEnvironment(true, [], ['index' => '{{ "foo"|sandbox_aware }}'], [], ['sandbox_aware']);
|
||||
@@ -980,12 +920,10 @@ EOF
|
||||
$this->assertSame('foo:off', $twig->load('index')->render([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
#[IgnoreDeprecations]
|
||||
public function testNeedsIsSandboxedFilterFollowsSourcePolicy()
|
||||
{
|
||||
$this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
$this->expectUserDeprecationMessage('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".');
|
||||
|
||||
$twig = $this->getEnvironment(false, [], [
|
||||
'in' => '{{ "foo"|sandbox_aware }}',
|
||||
|
||||
Reference in New Issue
Block a user