mirror of
https://github.com/smarty-php/smarty.git
synced 2026-07-05 16:00:55 +02:00
ff2ef3b0cb
* Redirect test temp dirs to system temp directory. Fixes #1178 Move all test-generated output (compiled templates, cache files, and temporary template sources) from per-test-directory folders inside the working tree to a parallel structure under sys_get_temp_dir()/smarty-tests/. This removes 215 boilerplate .gitignore files from the repo and ensures running the test suite leaves zero uncommitted files in the working tree. All 2296 tests continue to pass with identical behavior. * Isolate each test class in a unique temp directory getTempDir() now appends a per-class uniqid token to the temp path, so concurrent or sequential test runs never share compiled/cached output. The token is generated lazily on first use and reset in tearDownAfterClass(), giving every test class a fresh isolated directory. As a result, the Bootstrap.php pre-run cleanup of smarty-tests/ is no longer needed for correctness (stale paths are unreachable) and was harmful to concurrent runs, so it has been removed. * Remove individualFolders dead code and spurious assertTrue from cleanDirs() - Remove the never-active individualFolders code path from setUpSmarty() (the constant was always true, making the branch unreachable) - Remove define('individualFolders') from Config.php and the constructor - Remove $this->assertTrue(true) from cleanDirs(): it existed solely to make testInit() count as a passing test; now that cleanDirs() is called from setUpSmarty() and from test methods directly, the assertion was spuriously inflating assertion counts - Add tests/**/templates_c/, cache/, templates_tmp/ to .gitignore to prevent stale test output from appearing as untracked files * Clean up each test class's unique temp dir in tearDownAfterClass() Add a private static removeDir() helper and call it from tearDownAfterClass() to recursively delete the per-class unique temp directory after each test class finishes. Cleanup failures are silently ignored (@ suppression) so they never cause test failures. Set KEEP_SMARTY_TEST_ARTIFACTS=1 in the environment to skip cleanup and keep the artifacts on disk for debugging. * cleanup of unused template files, non-shared files stored in __shared folder, no longer required calls to add template folders et cetera * fixed the unit tests * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove useless resetting of static properties in tearDownAfterClass * changed an incorrect doc and formatted some code. * add changelog --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
140 lines
5.4 KiB
PHP
140 lines
5.4 KiB
PHP
<?php
|
|
/**
|
|
* Smarty PHPUnit tests demo resource plugin extendsall
|
|
*
|
|
|
|
* @author Uwe Tews
|
|
*/
|
|
|
|
require_once __DIR__ . '/resources/resource.extendsall.php';
|
|
|
|
/**
|
|
* class for demo resource plugin extendsall tests
|
|
*
|
|
*
|
|
* @preserveGlobalState disabled
|
|
*
|
|
*/
|
|
class ResourceExtendsAllPluginTest extends PHPUnit_Smarty
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
$this->setUpSmarty(__DIR__);
|
|
}
|
|
|
|
|
|
/**
|
|
* test extendsall
|
|
*/
|
|
public function testResourcePluginExtendsall()
|
|
{
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('root' => './templates', './templates_2', './templates_3',
|
|
'./templates_4',));
|
|
|
|
$expected = "templatestemplates_3templatestemplates_4";
|
|
$this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test extendsall
|
|
* changed tepmplate_setting
|
|
*/
|
|
|
|
public function testResourcePluginExtendsall2()
|
|
{
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setMergeCompiledIncludes(true);
|
|
$this->smarty->setTemplateDir(array('./templates_3', './templates_4',));
|
|
|
|
$expected = "templates_3templates_3templates_3templates_4";
|
|
$this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall.tpl'));
|
|
}
|
|
|
|
public function testResourcePluginExtendsallOne()
|
|
{
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('root' => './templates', './templates_2', './templates_3',
|
|
'./templates_4',));
|
|
|
|
$expected = "templatestemplates";
|
|
$this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall2.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test extendsall special application
|
|
*/
|
|
public function testResourcePluginExtendsallSpecialApplication()
|
|
{
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('./templates_2', './templates_1',));
|
|
$this->smarty->setDefaultResourceType('extendsall');
|
|
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>',
|
|
$this->smarty->fetch('template.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test extendsall special application
|
|
*/
|
|
public function testResourcePluginExtendsallSpecialApplication2()
|
|
{
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',));
|
|
$this->smarty->setDefaultResourceType('extendsall');
|
|
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>',
|
|
$this->smarty->fetch('template.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test extendsall special application
|
|
*/
|
|
public function testResourcePluginExtendsallSpecialApplication3()
|
|
{
|
|
$this->smarty->setMergeCompiledIncludes(true);
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('./templates_2', './templates_1',));
|
|
$this->smarty->setDefaultResourceType('extendsall');
|
|
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>',
|
|
$this->smarty->fetch('template.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test extendsall special application
|
|
*/
|
|
public function testResourcePluginExtendsallSpecialApplication4()
|
|
{
|
|
$this->smarty->setMergeCompiledIncludes(true);
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('./templates_2', './templates_1',));
|
|
$this->smarty->setDefaultResourceType('extendsall');
|
|
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates2</p><p>data2 from templates1</p>',
|
|
$this->smarty->fetch('template.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test extendsall special application
|
|
*/
|
|
public function testResourcePluginExtendsallSpecialApplication5()
|
|
{
|
|
$this->smarty->setMergeCompiledIncludes(true);
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',));
|
|
$this->smarty->setDefaultResourceType('extendsall');
|
|
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>',
|
|
$this->smarty->fetch('template.tpl'));
|
|
}
|
|
|
|
/**
|
|
* test extendsall special application
|
|
*/
|
|
public function testResourcePluginExtendsallSpecialApplication6()
|
|
{
|
|
$this->smarty->setMergeCompiledIncludes(true);
|
|
$this->smarty->registerResource('extendsall', new My_Resource_Extendsall());
|
|
$this->smarty->setTemplateDir(array('./templates_3', './templates_2', './templates_1',));
|
|
$this->smarty->setDefaultResourceType('extendsall');
|
|
$this->assertEquals('<p>data1 from templates1</p><p>data1 from templates3</p><p>data1 from templates2</p><p>data2 from templates1</p>',
|
|
$this->smarty->fetch('template.tpl'));
|
|
}
|
|
}
|