-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for OctoberCMS / WinterCMS (#27)
* Update Configuration.php Add support for hint paths configuration * Update ComponentTokenParser.php Is enabled hint path support, prepare the hint path * update hint param handle style, add test * update readme for OctoberCMS and WinterCMS * update readme for OctoberCMS and WinterCMS * update readme for OctoberCMS and WinterCMS * fixes --------- Co-authored-by: Giorgio Pogliani <giorgiopogliani94@gmail.com>
- Loading branch information
1 parent
c25a903
commit 66d0409
Showing
4 changed files
with
104 additions
and
4 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
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
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,50 @@ | ||
<?php | ||
|
||
namespace Performing\TwigComponents\Tests; | ||
|
||
use Performing\TwigComponents\Configuration; | ||
use Performing\TwigComponents\TokenParser\ComponentTokenParser; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ComponentTokenParserTest extends TestCase | ||
{ | ||
public function testGetComponentPathWithHintPath() | ||
{ | ||
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates'); | ||
$twig = new \Twig\Environment($loader); | ||
|
||
$config = Configuration::make($twig) | ||
->setTemplatesPath('mynamespace.myplugin::components', hint: true) | ||
->setTemplatesExtension('twig') | ||
->useCustomTags(); | ||
|
||
$this->assertTrue($config->getNeedsHintPath()); | ||
$this->assertEquals($config->getTemplatesPath(), 'mynamespace.myplugin::components'); | ||
$this->assertEquals($config->getTemplatesExtension(), 'twig'); | ||
|
||
$parser = new ComponentTokenParser($config); | ||
$componentPath = $parser->getComponentPath('test/component'); | ||
$this->assertEquals('mynamespace.myplugin::components.test.component', $componentPath); | ||
} | ||
|
||
public function testGetComponentPathWithoutHintPath() | ||
{ | ||
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates'); | ||
$twig = new \Twig\Environment($loader); | ||
|
||
$config = Configuration::make($twig) | ||
->setTemplatesPath('_components', hint: false) | ||
->setTemplatesExtension('twig') | ||
->useCustomTags(); | ||
|
||
$this->assertFalse($config->getNeedsHintPath()); | ||
$this->assertEquals($config->getTemplatesPath(), '_components'); | ||
$this->assertEquals($config->getTemplatesExtension(), 'twig'); | ||
|
||
$parser = new ComponentTokenParser($config); | ||
|
||
$componentPath = $parser->getComponentPath('test/component'); | ||
|
||
$this->assertEquals('_components/test/component.twig', $componentPath); | ||
} | ||
} |