-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a twig function for generating twig hooks names
- Loading branch information
1 parent
ad06837
commit 878f4d9
Showing
4 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,5 +65,10 @@ | |
"symfony/runtime": true | ||
}, | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"symfony": { | ||
"require": "6.4.*" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/TwigHooks/tests/Integration/Twig/Runtime/HooksRuntimeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\TwigHooks\Integration\Twig\Runtime; | ||
|
||
use Sylius\TwigHooks\Twig\Runtime\HooksRuntime; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
final class HooksRuntimeTest extends KernelTestCase | ||
{ | ||
/** | ||
* @dataProvider getHookNameConversionData | ||
*/ | ||
public function testItConvertsStringsToHookNames(string $input, string $expectedOutput, array $suffix = []): void | ||
{ | ||
$this->assertSame($expectedOutput, $this->getTestSubject()->createHookName($input, ...$suffix)); | ||
} | ||
|
||
public function testItReturnsHookableData(): void | ||
{ | ||
$context = [ | ||
'hookable_data' => ['foo' => 'bar'], | ||
'other' => 'data', | ||
]; | ||
|
||
$this->assertSame( | ||
['foo' => 'bar'], | ||
$this->getTestSubject()->getHookableData($context) | ||
); | ||
} | ||
|
||
public function testItReturnsHookableConfiguration(): void | ||
{ | ||
$context = [ | ||
'hookable_configuration' => ['foo' => 'bar'], | ||
'other' => 'data', | ||
]; | ||
|
||
$this->assertSame( | ||
['foo' => 'bar'], | ||
$this->getTestSubject()->getHookableConfiguration($context) | ||
); | ||
} | ||
|
||
public function testItRendersHook(): void | ||
{ | ||
$this->markTestSkipped('Not implemented yet.'); | ||
} | ||
|
||
public function testItRendersHookable(): void | ||
{ | ||
$this->markTestSkipped('Not implemented yet.'); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHookNameConversionData(): array | ||
{ | ||
return [ | ||
'simple' => ['@SyliusShop/_product.html.twig', 'sylius_shop.product'], | ||
'with slash' => ['@SyliusShop/_product/variant.html.twig', 'sylius_shop.product.variant'], | ||
'with camel case' => ['@SyliusShop/_product/variant/optionValue.html.twig', 'sylius_shop.product.variant.option_value'], | ||
'without bundle prefix' => ['some_template.html.twig', 'some_template'], | ||
'with single suffix part' => ['@SyliusShop/_product.html.twig', 'sylius_shop.product.suffix', ['suffix']], | ||
'with multiple suffix parts' => ['@SyliusShop/_product.html.twig', 'sylius_shop.product.suffix.part', ['suffix', 'part']], | ||
]; | ||
} | ||
|
||
private function getTestSubject(): HooksRuntime | ||
{ | ||
return $this->getContainer()->get(HooksRuntime::class); | ||
} | ||
} |