Skip to content

Commit

Permalink
EWPP-1146: Update test coverage for template prefixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra committed Jun 7, 2021
1 parent b64a65b commit 551b211
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/Loader/EuropaComponentLibraryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ class EuropaComponentLibraryLoader extends \Twig_Loader_Filesystem
* List of ECL admissible namespaces, without leading '@'.
* @param array|string $paths
* A path or an array of paths where to look for templates.
* @param null|string $root
* @param string|null $root
* The root path common to all relative paths (null for getcwd())
* @param string $prefix
* Component name prefix, defaults to "ec-component-".
* @param string $templatePrefix
* ECL template name prefix, defaults to "ecl-".
* @param string $extension
* @param string $prefix
* Component name prefix, defaults to "twig-component-".
* @param string $templatePrefix
* ECL template name prefix, defaults to no prefix.
* @param string $extension
* Twig extension, defaults to ".html.twig".
*/
public function __construct($namespaces, $paths = [], $root = null, $prefix = 'twig-component-', $templatePrefix = '', $extension = '.html.twig')
public function __construct($namespaces, $paths = [], string $root = null, string $prefix = 'twig-component-', string $templatePrefix = '', string $extension = '.html.twig')
{
parent::__construct($paths, $root);
$this->namespaces = $namespaces;
Expand Down
26 changes: 15 additions & 11 deletions tests/EuropaComponentLibraryLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class EuropaComponentLibraryLoaderTest extends TestCase
*
* @param string $name
* @param string $expected
* @param string $prefix
* @param string $templatePrefix
*
* @dataProvider dataProvider
*/
public function testLoader($name, $expected, $prefix)
public function testLoader(string $name, string $expected, string $prefix, string $templatePrefix)
{
$namespaces = ['namespace1', 'namespace2'];
$paths = ['tests/fixtures/components'];
$loader = new EuropaComponentLibraryLoader($namespaces, $paths, null, $prefix);
$loader = new EuropaComponentLibraryLoader($namespaces, $paths, null, $prefix, $templatePrefix);
$twig = new Twig_Environment($loader);
$actual = $twig->loadTemplate($name)->render([]);
$actual = str_replace("\n", ' ', trim($actual));
Expand All @@ -41,19 +43,21 @@ public function dataProvider()
{
return [
// Test without prefix.
['@namespace1/component1', 'component1', ''],
['@namespace1/component1', 'component1', '', ''],
// Test without prefix and with inclusions.
['@namespace2/component2', 'component2 component1', ''],
['@namespace2/component3', 'component3 component2 component1', ''],
['@namespace2/component2', 'component2 component1', '', ''],
['@namespace2/component3', 'component3 component2 component1', '', ''],
// Test without prefix and sub component.
['@namespace2/component4/sub-component1', 'component4 sub-component1', ''],
// Test with prefix.
['@namespace1/component5', 'component5', 'ecl-'],
['@namespace1/component5/sub-component1', 'component5 sub-component1', 'ecl-'],
['@namespace2/component4/sub-component1', 'component4 sub-component1', '', ''],
// Test with component prefix.
['@namespace1/component5', 'component5', 'ecl-', ''],
['@namespace1/component5/sub-component1', 'component5 sub-component1', 'ecl-', ''],
// Test with prefix and with relative loading.
['@namespace1/component6', 'component6 component5', 'ecl-'],
['@namespace1/component6', 'component6 component5', 'ecl-', ''],
// Test when using full name.
['@namespace1/ec-component-full-name/ecl-full-name.html.twig', 'full-name', 'ec-component-'],
['@namespace1/ec-component-full-name/ecl-full-name.html.twig', 'full-name', 'ec-component-', ''],
// Test when using template prefix.
['@namespace1/component7', 'component7', '', 'ecl-'],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
component7

0 comments on commit 551b211

Please sign in to comment.