"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core-bundle/tests/Contao/TemplateLoaderTest.php" between
contao-4.8.1.tar.gz and contao-4.8.2.tar.gz

About: Contao (fka TYPOlight) is a content management system (CMS). Latest release.

TemplateLoaderTest.php  (contao-4.8.1):TemplateLoaderTest.php  (contao-4.8.2)
skipping to change at line 15 skipping to change at line 15
/* /*
* This file is part of Contao. * This file is part of Contao.
* *
* (c) Leo Feyer * (c) Leo Feyer
* *
* @license LGPL-3.0-or-later * @license LGPL-3.0-or-later
*/ */
namespace Contao\CoreBundle\Tests\Contao; namespace Contao\CoreBundle\Tests\Contao;
use Contao\ContentText;
use Contao\Controller; use Contao\Controller;
use Contao\CoreBundle\Tests\TestCase; use Contao\CoreBundle\Tests\TestCase;
use Contao\FormTextField;
use Contao\ModuleArticleList;
use Contao\System; use Contao\System;
use Contao\TemplateLoader; use Contao\TemplateLoader;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
class TemplateLoaderTest extends TestCase class TemplateLoaderTest extends TestCase
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$fs = new Filesystem(); $fs = new Filesystem();
$fs->mkdir($this->getFixturesDir().'/templates'); $fs->mkdir($this->getFixturesDir().'/templates');
$fs->touch($this->getFixturesDir().'/templates/mod_article_custom.html5'
); $GLOBALS['TL_CTE'] = [
$fs->touch($this->getFixturesDir().'/templates/mod_article_list_custom.h 'texts' => [
tml5'); 'text' => ContentText::class,
],
];
$GLOBALS['TL_FFL'] = [
'text' => FormTextField::class,
];
$GLOBALS['FE_MOD'] = [
'miscellaneous' => [
'article_list' => ModuleArticleList::class,
],
];
$GLOBALS['TL_LANG']['MSC']['global'] = 'global'; $GLOBALS['TL_LANG']['MSC']['global'] = 'global';
System::setContainer($this->getContainerWithContaoConfiguration($this->g etFixturesDir())); System::setContainer($this->getContainerWithContaoConfiguration($this->g etFixturesDir()));
TemplateLoader::addFile('mod_article', 'src/Resources/contao/templates/m
odules');
TemplateLoader::addFile('mod_article_list', 'src/Resources/contao/templa
tes/modules');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function tearDown(): void protected function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
$fs = new Filesystem(); $fs = new Filesystem();
$fs->remove($this->getFixturesDir().'/templates'); $fs->remove($this->getFixturesDir().'/templates');
unset($GLOBALS['TL_LANG']); unset($GLOBALS['TL_LANG'], $GLOBALS['TL_CTE'], $GLOBALS['TL_FFL'], $GLOB ALS['FE_MOD']);
} }
public function testReturnsAllTemplatesOfAGroup(): void public function testReturnsACustomTemplateInTemplates(): void
{ {
$fs = new Filesystem();
$fs->touch($this->getFixturesDir().'/templates/mod_article_custom.html5'
);
TemplateLoader::addFile('mod_article', 'core-bundle/src/Resources/contao
/templates/modules');
$this->assertSame( $this->assertSame(
[ [
'mod_article' => 'mod_article', 'mod_article' => 'mod_article',
'mod_article_custom' => 'mod_article_custom (global)', 'mod_article_custom' => 'mod_article_custom (global)',
'mod_article_list' => 'mod_article_list',
'mod_article_list_custom' => 'mod_article_list_custom (global)',
], ],
Controller::getTemplateGroup('mod_') Controller::getTemplateGroup('mod_article')
); );
$this->assertSame(
[
'mod_article_custom' => 'mod_article_custom (global)',
],
Controller::getTemplateGroup('mod_article_')
);
$fs->remove($this->getFixturesDir().'/templates/mod_article_custom.html5
');
TemplateLoader::reset();
} }
public function testReturnsTheCustomTemplatesForAGivenTemplate(): void public function testReturnsACustomTemplateInContaoTemplates(): void
{ {
TemplateLoader::addFile('mod_article', 'core-bundle/src/Resources/contao
/templates/modules');
TemplateLoader::addFile('mod_article_custom', 'contao/templates');
$this->assertSame( $this->assertSame(
[ [
'mod_article_custom' => 'mod_article_custom (global)', 'mod_article' => 'mod_article',
'mod_article_custom' => 'mod_article_custom',
],
Controller::getTemplateGroup('mod_article')
);
$this->assertSame(
[
'mod_article_custom' => 'mod_article_custom',
], ],
Controller::getTemplateGroup('mod_article_') Controller::getTemplateGroup('mod_article_')
); );
TemplateLoader::reset();
}
public function testReturnsACustomTemplateInAnotherBundle(): void
{
TemplateLoader::addFile('mod_article', 'core-bundle/src/Resources/contao
/templates/modules');
TemplateLoader::addFile('mod_article_custom', 'article-bundle/src/Resour
ces/contao/templates/modules');
$this->assertSame( $this->assertSame(
[ [
'mod_article_list_custom' => 'mod_article_list_custom (global)', 'mod_article' => 'mod_article',
'mod_article_custom' => 'mod_article_custom',
], ],
Controller::getTemplateGroup('mod_article_list_') Controller::getTemplateGroup('mod_article')
); );
$this->assertSame(
[
'mod_article_custom' => 'mod_article_custom',
],
Controller::getTemplateGroup('mod_article_')
);
TemplateLoader::reset();
} }
public function testIncludesTheTempateItselfIfThereIsNoTrailingUnderscore(): void public function testReturnsMultipleRootTemplatesWithTheSamePrefix(): void
{ {
TemplateLoader::addFile('ctlg_views', 'catalog-manager/src/Resources/con
tao/templates');
TemplateLoader::addFile('ctlg_view_master', 'catalog-manager/src/Resourc
es/contao/templates');
TemplateLoader::addFile('ctlg_view_teaser', 'catalog-manager/src/Resourc
es/contao/templates');
$this->assertSame(
[
'ctlg_view_master' => 'ctlg_view_master',
'ctlg_view_teaser' => 'ctlg_view_teaser',
],
Controller::getTemplateGroup('ctlg_view')
);
$this->assertSame(
[
'ctlg_view_master' => 'ctlg_view_master',
'ctlg_view_teaser' => 'ctlg_view_teaser',
],
Controller::getTemplateGroup('ctlg_view_')
);
TemplateLoader::reset();
}
public function testReturnsATemplateGroup(): void
{
$fs = new Filesystem();
$fs->touch($this->getFixturesDir().'/templates/mod_article_custom.html5'
);
$fs->touch($this->getFixturesDir().'/templates/mod_article_list_custom.h
tml5');
TemplateLoader::addFile('mod_article', 'core-bundle/src/Resources/contao
/templates/modules');
TemplateLoader::addFile('mod_article_list', 'core-bundle/src/Resources/c
ontao/templates/modules');
TemplateLoader::addFile('mod_article_foo', 'article-bundle/src/Resources
/contao/templates/modules');
TemplateLoader::addFile('mod_article_bar', 'contao/templates');
$this->assertSame(
[
'mod_article' => 'mod_article',
'mod_article_bar' => 'mod_article_bar',
'mod_article_custom' => 'mod_article_custom (global)',
'mod_article_foo' => 'mod_article_foo',
],
Controller::getTemplateGroup('mod_article')
);
$this->assertSame(
[
'mod_article_bar' => 'mod_article_bar',
'mod_article_custom' => 'mod_article_custom (global)',
'mod_article_foo' => 'mod_article_foo',
],
Controller::getTemplateGroup('mod_article_')
);
$this->assertSame( $this->assertSame(
[ [
'mod_article_list' => 'mod_article_list', 'mod_article_list' => 'mod_article_list',
'mod_article_list_custom' => 'mod_article_list_custom (global)', 'mod_article_list_custom' => 'mod_article_list_custom (global)',
], ],
Controller::getTemplateGroup('mod_article_list') Controller::getTemplateGroup('mod_article_list')
); );
$this->assertSame(
[
'mod_article_list_custom' => 'mod_article_list_custom (global)',
],
Controller::getTemplateGroup('mod_article_list_')
);
$fs->remove($this->getFixturesDir().'/templates/mod_article_custom.html5
');
$fs->remove($this->getFixturesDir().'/templates/mod_article_list_custom.
html5');
TemplateLoader::reset();
}
public function testSupportsAdditionalMappers(): void
{
$GLOBALS['CTLG'] = [
'view' => 'Ctlg\View',
'view_details' => 'Ctlg\ViewDetails',
];
TemplateLoader::addFile('ctlg_view', 'catalog-manager/src/Resources/cont
ao/templates');
TemplateLoader::addFile('ctlg_view_details', 'catalog-manager/src/Resour
ces/contao/templates');
$this->assertSame(
[
'ctlg_view' => 'ctlg_view',
'ctlg_view_details' => 'ctlg_view_details',
],
Controller::getTemplateGroup('ctlg_view')
);
$this->assertSame(
[
'ctlg_view' => 'ctlg_view',
],
Controller::getTemplateGroup('ctlg_view', ['ctlg' => array_keys($GLO
BALS['CTLG'])])
);
unset($GLOBALS['CTLG']);
} }
} }
 End of changes. 20 change blocks. 
19 lines changed or deleted 184 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)