Skip to content

Commit

Permalink
OXDEV-8893 Fix Twig v3.15.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
liulka-oxid authored and AshrafOxid committed Nov 27, 2024
1 parent 5076cf9 commit a44ad4c
Show file tree
Hide file tree
Showing 27 changed files with 337 additions and 443 deletions.
47 changes: 41 additions & 6 deletions src/Extensions/PhpFunctionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,54 @@ class PhpFunctionsExtension extends AbstractExtension
public function getFunctions(): array
{
return [
new TwigFunction('count', 'count', ['deprecated' => true, 'alternative' => 'length']),
new TwigFunction('empty', 'empty', ['deprecated' => true, 'alternative' => 'length']),
new TwigFunction('isset', [$this, 'twigIsset', ['deprecated' => true, 'alternative' => 'is defined']])
new TwigFunction(
'count',
'count',
[
'deprecated' => true,
'alternative' => 'length',
]
),
new TwigFunction(
'empty',
[
$this,
'emptyWrapper',
[
'deprecated' => true,
'alternative' => 'length',
],
]
),
new TwigFunction(
'isset',
[
$this,
'twigIsset',
[
'deprecated' => true,
'alternative' => 'is defined',
],
]
)
];
}

/**
* @param null $value
*
* @return bool
* isset wrapper, isset is a language construct and can't be called as a function in callback
* @link https://www.php.net/manual/en/functions.variable-functions.php
*/
public function twigIsset($value = null): bool
{
return isset($value);
}

/**
* empty is a language construct and can't be called as a function callback
* @link https://www.php.net/manual/en/functions.variable-functions.php
*/
public function emptyWrapper(mixed $value = null): bool
{
return empty($value);
}
}
12 changes: 0 additions & 12 deletions tests/Integration/Extensions/FormatDateExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ protected function setUp(): void
$this->extension = new FormatDateExtension(new FormatDateLogic());
}

/**
* @covers \OxidEsales\Twig\Extensions\Filters\FormatDateExtension::formatDate
*/
public function testFormDateWithDatetime(): void
{
$template = "{{ '01.08.2007 11.56.25'|format_date('datetime', true) }}";
Expand All @@ -32,9 +29,6 @@ public function testFormDateWithDatetime(): void
$this->assertEquals($expected, $this->getTemplate($template)->render([]));
}

/**
* @covers \OxidEsales\Twig\Extensions\Filters\FormatDateExtension::formatDate
*/
public function testFormDateWithTimestamp(): void
{
$template = "{{ '20070801115625'|format_date('timestamp', true) }}";
Expand All @@ -43,9 +37,6 @@ public function testFormDateWithTimestamp(): void
$this->assertEquals($expected, $this->getTemplate($template)->render([]));
}

/**
* @covers \OxidEsales\Twig\Extensions\Filters\FormatDateExtension::formatDate
*/
public function testFormDateWithDate(): void
{
$template = "{{ '2007-08-01 11:56:25'|format_date('date', true) }}";
Expand All @@ -54,9 +45,6 @@ public function testFormDateWithDate(): void
$this->assertEquals($expected, $this->getTemplate($template)->render([]));
}

/**
* @covers \OxidEsales\Twig\Extensions\Filters\FormatDateExtension::formatDate
*/
public function testFormDateUsingObject(): void
{
$template = "{{ field|format_date('datetime') }}";
Expand Down
3 changes: 0 additions & 3 deletions tests/Integration/Extensions/FormatPriceExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public static function priceProvider(): array
];
}

/**
* @covers \OxidEsales\Twig\Extensions\FormatPriceExtension::formatPrice
*/
#[DataProvider('priceProvider')]
public function testFormatPrice($template, $expected): void
{
Expand Down
6 changes: 0 additions & 6 deletions tests/Integration/Extensions/InputHelpExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public static function getIdentProvider(): array
];
}

/**
* @covers \OxidEsales\Twig\Extensions\InputHelpExtension::getHelpId
*/
#[DataProvider('getIdentProvider')]
public function testGetIdent(?string $params, int $iLang, bool $blAdmin, ?string $expected): void
{
Expand All @@ -54,9 +51,6 @@ public static function getHelpTextProvider(): array
];
}

/**
* @covers \OxidEsales\Twig\Extensions\InputHelpExtension::getHelpText
*/
#[DataProvider('getHelpTextProvider')]
public function testGetHelpText(?string $params, int $iLang, bool $blAdmin, ?string $expected): void
{
Expand Down
12 changes: 5 additions & 7 deletions tests/Integration/Extensions/PhpFunctionsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

final class PhpFunctionsExtensionTest extends AbstractExtensionTestCase
{
/** @var PhpFunctionsExtension */
protected \Twig\Extension\AbstractExtension $extension;

protected function setUp(): void
{
parent::setUp();
Expand All @@ -26,10 +23,11 @@ protected function setUp(): void
public static function dummyTemplateProvider(): array
{
return [
["{{ count({0:0, 1:1, 2:2}) }}", 3],
["{{ empty({0:0, 1:1}) }}", false],
["{{ empty({}) }}", true],
["{{ isset(foo) }}", false],
['{{ count({0:0, 1:1, 2:2}) }}', 3],
['{{ empty({0:0, 1:1}) }}', false],
['{{ empty({}) }}', true],
['{{ empty() }}', true],
['{{ isset(foo) }}', false],
["{% set foo = 'bar' %} {{ isset(foo) }}", true],
];
}
Expand Down
3 changes: 0 additions & 3 deletions tests/Integration/Extensions/ScriptExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ protected function setUp(): void
$this->extension = new ScriptExtension(new ScriptLogic());
}

/**
* @covers \OxidEsales\Twig\Extensions\ScriptExtension::script
*/
#[DataProvider('getScriptTests')]
public function testScript(string $template, string $expected): void
{
Expand Down
3 changes: 0 additions & 3 deletions tests/Integration/Extensions/TranslateExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public static function dataProvider(): array
];
}

/**
* @covers \OxidEsales\Twig\Extensions\TranslateExtension::translate
*/
#[DataProvider('dataProvider')]
public function testTranslate(array $params, string $expectedTranslation): void
{
Expand Down
5 changes: 1 addition & 4 deletions tests/Unit/Extensions/CaptureExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ protected function setUp(): void
parent::setUp();
}

/**
* @covers \OxidEsales\Twig\Extensions\CaptureExtension::getTokenParsers
*/
public function testGetTokenParsers()
public function testGetTokenParsers(): void
{
$tokenParser = $this->CaptureExtension->getTokenParsers();
$this->assertInstanceOf(CaptureTokenParser::class, $tokenParser[0]);
Expand Down
8 changes: 3 additions & 5 deletions tests/Unit/Extensions/Filters/CatExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

final class CatExtensionTest extends TestCase
{
/**
* @covers \OxidEsales\Twig\Extensions\Filters\CatExtension::cat
*/
public function testCat(): void
{
$catFilter = new CatExtension();
$string = 'foo';
$cat = 'bar';
$actual = $catFilter->cat($string, $cat);

$actual = (new CatExtension())->cat($string, $cat);

$this->assertEquals($string . $cat, $actual);
}
}
6 changes: 1 addition & 5 deletions tests/Unit/Extensions/Filters/DateFormatExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ protected function setUp(): void
public static function provider(): array
{
return [

//dummy data
['', '', '', null],
['foo', '', '', null],
Expand All @@ -49,11 +48,8 @@ public static function provider(): array
];
}

/**
* @covers \OxidEsales\Twig\Extensions\Filters\DateFormatExtension::dateFormat
*/
#[DataProvider('provider')]
public function testDateFormat($string, string $format, string $default_date, string $expectedDate): void
public function testDateFormat($string, $format, $default_date, $expectedDate): void
{
$actualDate = $this->dateFormatExtension->dateFormat($string, $format, $default_date);
$this->assertEquals($expectedDate, $actualDate);
Expand Down
19 changes: 5 additions & 14 deletions tests/Unit/Extensions/Filters/EncloseFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@

final class EncloseFilterTest extends TestCase
{
/**
* @covers \OxidEsales\Twig\Extensions\Filters\EncloseExtension::enclose
*/
public function testEnclose(): void
{
$string = "foo";
$encloser = "*";
$encloseFilter = new EncloseExtension();
$enclosedString = $encloseFilter->enclose($string, $encloser);
$enclosedString = (new EncloseExtension())->enclose('foo', '*');

$this->assertEquals('*foo*', $enclosedString);
}

/**
* @covers \OxidEsales\Twig\Extensions\Filters\EncloseExtension::enclose
*/
public function testEncloseNoEncloder(): void
public function testEncloseNoEncloser(): void
{
$string = "foo";
$encloseFilter = new EncloseExtension();
$enclosedString = $encloseFilter->enclose($string);
$enclosedString = (new EncloseExtension())->enclose('foo');

$this->assertEquals('foo', $enclosedString);
}
}
6 changes: 1 addition & 5 deletions tests/Unit/Extensions/Filters/FileSizeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ public static function provider(): array
];
}

/**
*
* @covers \OxidEsales\Twig\Extensions\Filters\FileSizeExtension::fileSize
*/
#[DataProvider('provider')]
public function testFileSize(string $fileSize, string $expectedFileSize): void
public function testFileSize($fileSize, $expectedFileSize): void
{
$fileSizeLogic = new FileSizeLogic();
$fileSizeExtension = new FileSizeExtension($fileSizeLogic);
Expand Down
3 changes: 0 additions & 3 deletions tests/Unit/Extensions/Filters/SmartWordwrapExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ public static function provider(): array
];
}

/**
* @covers \OxidEsales\Twig\Extensions\Filters\SmartWordwrapExtension::smartWordWrap
*/
#[DataProvider('provider')]
public function testSmartWordWrap(array $params, string $expectedString): void
{
Expand Down
5 changes: 1 addition & 4 deletions tests/Unit/Extensions/HasRightsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ protected function setUp(): void
parent::setUp();
}

/**
* @covers \OxidEsales\Twig\Extensions\HasRightsExtension::getTokenParsers
*/
public function testGetTokenParsers()
public function testGetTokenParsers(): void
{
$tokenParser = $this->hasRightsExtension->getTokenParsers();
$this->assertInstanceOf(HasRightsTokenParser::class, $tokenParser[0]);
Expand Down
6 changes: 0 additions & 6 deletions tests/Unit/Extensions/IncludeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public function setUp(): void
);
}

/**
* @covers \OxidEsales\Twig\Extensions\IncludeExtension::includeDynamicPrefix
*/
#[DataProvider('dataProviderTestIncludeDynamicPrefix')]
public function testIncludeDynamicPrefix(array $parameters, array $expected): void
{
Expand All @@ -54,9 +51,6 @@ public static function dataProviderTestIncludeDynamicPrefix(): array
];
}

/**
* @covers \OxidEsales\Twig\Extensions\IncludeExtension::renderForCache
*/
#[DataProvider('dataProviderTestRenderForCache')]
public function testRenderForCache(array $parameters, string $expected): void
{
Expand Down
18 changes: 7 additions & 11 deletions tests/Unit/Extensions/IncludeWidgetExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@

namespace OxidEsales\Twig\Tests\Unit\Extension;

use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\WidgetControl;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\TemplateLogic\IncludeWidgetLogic;
use OxidEsales\Twig\Extensions\IncludeWidgetExtension;
use PHPUnit\Framework\TestCase;

final class IncludeWidgetExtensionTest extends TestCase
{
/**
* @var IncludeWidgetExtension
*/
protected $includeWidgetExtension;
private IncludeWidgetExtension $includeWidgetExtension;

protected function setUp(): void
{
Expand All @@ -27,14 +26,11 @@ protected function setUp(): void
$this->includeWidgetExtension = new IncludeWidgetExtension($includeWidgetLogic);
}

/**
* @covers \OxidEsales\Twig\Extensions\IncludeWidgetExtension::includeWidget
*/
public function testIncludeWidget()
public function testIncludeWidget(): void
{
$widgetControl = $this->createMock(\OxidEsales\Eshop\Core\WidgetControl::class);
$widgetControl->expects($this->any())->method("start")->will($this->returnValue('html'));
\OxidEsales\Eshop\Core\Registry::set(\OxidEsales\Eshop\Core\WidgetControl::class, $widgetControl);
$widgetControl = $this->createMock(WidgetControl::class);
$widgetControl->method('start')->willReturn('html');
Registry::set(WidgetControl::class, $widgetControl);

$actual = $this->includeWidgetExtension->includeWidget(['cl' => 'oxwTagCloud', 'blShowTags' => 1]);
$this->assertEquals('html', $actual);
Expand Down
6 changes: 1 addition & 5 deletions tests/Unit/Extensions/StyleExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

final class StyleExtensionTest extends TestCase
{
/**
* @covers \OxidEsales\EshopCommunity\Internal\Transition\Adapter\TemplateLogic\StyleLogic::collectStyleSheets
*/
#[DataProvider('dataProvider')]
public function testCollectStyleSheets(array $params, bool $isDynamic): void
{
Expand All @@ -40,7 +37,6 @@ public static function dataProvider(): array

private function getTwigEnvironment($isDynamic): Environment
{
/** @var LoaderInterface $loader */
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
$env = new Environment($loader, []);
$env->addGlobal('__oxid_include_dynamic', $isDynamic);
Expand All @@ -49,10 +45,10 @@ private function getTwigEnvironment($isDynamic): Environment

private function getStyleExtensionMock(array $params, bool $isDynamic): StyleExtension
{
/** @var StyleLogic $styleLogic */
$styleLogic = $this->getMockBuilder(StyleLogic::class)->disableOriginalConstructor()->getMock();
$styleLogic->method('collectStyleSheets')->willReturn([]);
$styleLogic->expects($this->once())->method('collectStyleSheets')->with($params, $isDynamic);

return new StyleExtension($styleLogic);
}
}
Loading

0 comments on commit a44ad4c

Please sign in to comment.