1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Issue #5465 Support for array language files.

This commit is contained in:
camer0n
2025-04-04 13:42:14 -07:00
parent 93c301bdb8
commit c46b7b1d36
3 changed files with 1002 additions and 633 deletions

View File

@@ -2363,7 +2363,7 @@ class e107
* within a single request. The variant that has been passed first is used; different variant names in subsequent
* calls are ignored.
*
* @return array|boolean
* @return array|boolean|null
* - In case of 'detect': An associative array containing registered information for the library specified by
* $name, or FALSE if the library $name is not registered.
* - In case of 'load': An associative array of the library information.
@@ -2924,7 +2924,7 @@ class e107
* @param string $pluginName e.g. faq, page
* @param string $addonName eg. e_cron, e_url, e_module
* @param mixed $className [optional] true - use default name, false - no object is returned (include only), any string will be used as class name
* @return object
* @return object|null
*/
public static function getAddon($pluginName, $addonName, $className = true)
{
@@ -3653,7 +3653,7 @@ class e107
* @param string $path
* @param boolean $info
* @param boolean $noWrapper
* @return string|array
* @return string|array|false
*/
public static function _getTemplate($id, $key, $reg_path, $path, $info = false, $noWrapper = false)
{
@@ -3713,15 +3713,26 @@ class e107
return ($ret && is_array($ret) && isset($ret[$key])) ? $ret[$key] : false;
}
/**
* Load language file, replacement of include_lan()
* @outdated use e107::lan() or e107::coreLan(), e107::plugLan(), e107::themeLan()
* @param string $path
* @param boolean $force
* @return string
* Load a language file, serving as a replacement for the legacy include_lan() function.
*
* This method includes a language file and processes it based on its return type. For old-style files using define(),
* it returns the result of the include operation (typically 1 for success). For new-style files returning an array,
* it defines constants from the array and applies an English fallback if the current language is not English.
*
* For modern language loading, consider using e107::lan(), e107::coreLan(), e107::plugLan(), or e107::themeLan()
* as they provide more structured and maintainable options.
*
* @param string $path The full path to the language file (e.g., 'e107_languages/English/lan_admin.php' or 'folder/Spanish/Spanish_global.php').
* @param bool $force [optional] If true, forces inclusion with include() instead of include_once(). Defaults to false.
* @param string $lang [optional] The language of the file (e.g., 'English', 'Spanish'). If empty, uses e_LANGUAGE or defaults to 'English'.
* @return bool|int|string Returns:
* - false if the file is not readable or no fallback is available,
* - int (typically 1) for successful inclusion of old-style files,
* - true for successful processing of new-style array-based files,
* - string (empty '') if the include result is unset for old-style files.
*/
public static function includeLan($path, $force = false)
public static function includeLan($path, $force = false, $lang = '')
{
if (!is_readable($path))
{
@@ -3751,9 +3762,86 @@ class e107
}
$ret = ($force) ? include($path) : include_once($path);
// Determine the language: use $lang if provided, otherwise fall back to e_LANGUAGE or 'English'
$effectiveLang = $lang ?: (defined('e_LANGUAGE') ? e_LANGUAGE : 'English');
// If the included file returns an array, process it with the new system
if (is_array($ret))
{
self::includeLanArray($ret, $path, $effectiveLang);
return true; // New-style success indicator
}
// Old-style behavior: return the include result or empty string if unset
return (isset($ret)) ? $ret : "";
}
/**
* Helper method to process array-based language files and apply English fallback.
*
* Defines constants from the provided terms array and, for non-English languages, ensures all English
* constants are defined as a fallback for any missing terms.
*
* @param array $terms The array of language constants returned by the included file (e.g., ['LAN_FOO' => 'Bar']).
* @param string $path The path to the language file, used to determine the English fallback path.
* @param string $lang The language of the current file (e.g., 'Spanish'), used to decide if English fallback is needed.
* @return void
*/
private static function includeLanArray($terms, $path, $lang)
{
// Use basename of the path as a cache key (e.g., "Spanish_global.php")
$file_key = basename($path);
static $english_terms = []; // Cache English terms by file key
// Define constants from the current languages array first
foreach ($terms as $const => $value)
{
if (!defined($const))
{
define($const, $value);
}
}
// Load English fallback if not cached and not already English
if ($lang !== 'English' && !isset($english_terms[$file_key]))
{
$english_path = preg_replace(
"#/{$lang}/([^/]+)$#i",
'/English/$1',
$path
);
if (file_exists($english_path))
{
$english_terms[$file_key] = include($english_path);
if (!is_array($english_terms[$file_key]))
{
$english_terms[$file_key] = [];
}
}
else
{
self::getDebug()->log("No English fallback found for: " . $english_path);
$english_terms[$file_key] = [];
}
}
// For non-English, define English constants only if not already defined
if ($lang !== 'English' && !empty($english_terms[$file_key]))
{
foreach ($english_terms[$file_key] as $const => $english_value)
{
if (!defined($const))
{
define($const, $english_value);
}
}
}
}
/**
* Simplify importing of core Language files.
* All inputs are sanitized.
@@ -3829,7 +3917,7 @@ class e107
* @param string|bool|null $fname filename without the extension part (e.g. 'common')
* @param boolean $flat false (default, preferred) Language folder structure; true - prepend Language to file name
* @param boolean $returnPath When true, returns the path, but does not include the file or set the registry.
* @return bool|null
* @return bool|null|string
*/
public static function plugLan($plugin, $fname = '', $flat = false, $returnPath = false)
{
@@ -4236,7 +4324,7 @@ class e107
* 'fragment' => '', // A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character
* 'legacy' => false, // When true, legacy URLs will be generated regardless of mod_rewrite status
* ]
* @return string The SEF URL with HTML special characters escaped
* @return string|false The SEF URL with HTML special characters escaped
* (equivalent to the htmlspecialchars() output)
*/
public static function url($plugin = '', $key = null, $row = array(), $options = array())
@@ -4466,7 +4554,7 @@ class e107
/**
* Getter/Setter for schema. eg. Google structured data etc.
* @param string $json
* @return string|bool
* @return string|bool|null
*/
public static function schema($json = null)
{
@@ -4828,7 +4916,7 @@ class e107
* @param string $key array key
* @param string $type array type _SESSION, _GET etc.
* @param bool $base64
* @return bool|null
* @return bool|null|string
*/
public static function filter_request($input,$key,$type,$base64=FALSE)
{

View File

@@ -254,7 +254,7 @@ class language{
/**
* Converts iso to language-name and visa-versa.
* @param string $data
* @return string
* @return string|false
*/
function convert($data){
@@ -404,7 +404,7 @@ class language{
* @example type = english: array(0=>'English', 1=>'French' ...)
* @example type = native: array('English'=>'English', 'French'=>'Francais'...)
* @example type = abbr: array('en'=>'English, 'fr'=>'French' ... )
* @return array
* @return array|int
*/
function installed($type='english')
{

View File

@@ -12,6 +12,7 @@
class e107Test extends \Codeception\Test\Unit
{
protected $tempFiles = [];
/** @var e107 */
private $e107;
@@ -29,6 +30,20 @@ class e107Test extends \Codeception\Test\Unit
}
protected function _after()
{
// Clean up temporary files
foreach($this->tempFiles as $file)
{
if(file_exists($file))
{
unlink($file);
}
}
$this->tempFiles = [];
}
public function testGetInstance()
{
@@ -37,7 +52,7 @@ class e107Test extends \Codeception\Test\Unit
// $this::assertTrue($res);
}
public function testInitCore()
/*public function testInitCore()
{
//$res = null;
@@ -51,7 +66,7 @@ class e107Test extends \Codeception\Test\Unit
$this::assertEquals('/', e_HTTP);
}
}*/
public function testRenderLayout()
{
@@ -292,6 +307,7 @@ class e107Test extends \Codeception\Test\Unit
*/
public function testGetSingleton()
{
$e107 = $this->e107;
// test with path.
@@ -747,6 +763,7 @@ class e107Test extends \Codeception\Test\Unit
*/
public function testLibrary()
{
$e107 = $this->e107;
$expected = array(
@@ -798,6 +815,7 @@ class e107Test extends \Codeception\Test\Unit
$this::assertSame($expected, $result);
}
/*
public function testGetJs()
{
@@ -903,8 +921,8 @@ class e107Test extends \Codeception\Test\Unit
$this::assertSame($expected, $result['contact/index']);
}
/*
public function testGetThemeInfo()
{
@@ -1079,7 +1097,7 @@ class e107Test extends \Codeception\Test\Unit
{
if(!isset($legacyList[$key]))
{
$this->fail("Remove {$key} FROM admin_icons_template");
$this::fail("Remove $key FROM admin_icons_template");
}
$this::assertSame($legacyList[$key], $val, $key . " should equal: " . $legacyList[$key]);
@@ -1089,7 +1107,7 @@ class e107Test extends \Codeception\Test\Unit
{
if(!isset($new[$key]))
{
$this->fail("{$key} is missing from admin_icons_template");
$this::fail("$key is missing from admin_icons_template");
}
}
@@ -1111,6 +1129,7 @@ class e107Test extends \Codeception\Test\Unit
public function testGetCoreTemplate()
{
$e107 = $this->e107;
$templates = scandir(e_CORE . "templates");
@@ -1196,12 +1215,13 @@ class e107Test extends \Codeception\Test\Unit
public function testGetTemplateOverride()
{
// Loads e107_themes/bootstrap3/templates/gallery/gallery_template.php
$template = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true)
$template = e107::getTemplate('gallery'); // true & false default, loads theme (override true) e107::getTemplate('gallery', null, null, true, false)
$this::assertEquals("My Gallery", $template['list']['caption']);
// Duplicate to load registry
$template2 = e107::getTemplate('gallery', null, null, true, false); // true & false default, loads theme (override true)
$template2 = e107::getTemplate('gallery'); // true & false default, loads theme (override true) ie. e107::getTemplate('gallery', null, null, true, false)
$this::assertEquals("My Gallery", $template2['list']['caption']);
$this::assertSame($template, $template2);
@@ -1211,6 +1231,7 @@ class e107Test extends \Codeception\Test\Unit
public function testGetTemplateOverrideMerge()
{
// Loads e107_plugins/gallery/templates/gallery_template.php then overwrites it with e107_themes/bootstrap3/templates/gallery/gallery_template.php
$template = e107::getTemplate('gallery', null, null, true, true); // theme override is enabled, and theme merge is enabled.
$this::assertArrayHasKey('merged-example', $template);
@@ -1249,12 +1270,13 @@ class e107Test extends \Codeception\Test\Unit
*/
public function testGetTemplate()
{
// Loads e107_plugins/gallery/templates/gallery_template.php
$template = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled.
$template = e107::getTemplate('gallery', null, null, false); // theme override is disabled.
$this::assertEquals("Gallery", $template['list']['caption']);
// Duplicate to load registry.
$template2 = e107::getTemplate('gallery', null, null, false, false); // theme override is disabled.
$template2 = e107::getTemplate('gallery', null, null, false); // theme override is disabled.
$this::assertEquals("Gallery", $template2['list']['caption']);
$this::assertSame($template, $template2);
@@ -1302,6 +1324,10 @@ class e107Test extends \Codeception\Test\Unit
$res = null;
$this::assertTrue($res);
}
*/
/**
* @runInSeparateProcess
* @return void
*/
public function testPlugLan()
{
@@ -1348,14 +1374,11 @@ class e107Test extends \Codeception\Test\Unit
}*/
}
function testDetectRoute()
{
e107::getPlugin()->install('forum');
$tests = array(
@@ -1385,9 +1408,6 @@ class e107Test extends \Codeception\Test\Unit
}
e107::getPlugin()->uninstall('forum');
}
@@ -1455,7 +1475,7 @@ class e107Test extends \Codeception\Test\Unit
private function generateExpected($string, $rows)
{
$search = array('&');;
$search = array('&');
$replace = array('&');
foreach($rows as $k => $v)
@@ -1471,6 +1491,7 @@ class e107Test extends \Codeception\Test\Unit
public function testCanonical()
{
$e107 = $this->e107;
$e107::canonical('_RESET_');
$e107::canonical('news');
@@ -1521,7 +1542,6 @@ class e107Test extends \Codeception\Test\Unit
}
$tests = array();
$all = e107::getAddonConfig('e_url');
@@ -1567,12 +1587,11 @@ class e107Test extends \Codeception\Test\Unit
}
}
public function testUrlDomain()
{
// e107 v2.4 - test for custom domain
$obj = $this->e107;
@@ -1717,6 +1736,7 @@ class e107Test extends \Codeception\Test\Unit
/**
* Save the url_config preference
*
* @param array $newConfig
*/
private function setUrlConfig($newConfig = array())
@@ -1837,6 +1857,7 @@ class e107Test extends \Codeception\Test\Unit
public function testWysiwyg()
{
// Simulate editors being installed.
$editors = array(
'tinymce4' => 'TinyMce4',
@@ -1907,8 +1928,9 @@ class e107Test extends \Codeception\Test\Unit
public function testInAdminDir()
{
return null; // FIXME
$this->markTestSkipped("Skipped until admin-area conflict can be resolved."); // FIXME
$this::markTestSkipped("Skipped until admin-area conflict can be resolved."); // FIXME
$tests = array(
0 => array('path' => 'thumb.php', 'plugdir' => false, 'expected' => false),
1 => array('path' => 'index.php', 'plugdir' => false, 'expected' => false),
@@ -2008,6 +2030,7 @@ class e107Test extends \Codeception\Test\Unit
*/
public function testSet_request()
{
$tests = array(
'mode=main&action=create' => 'mode=main&action=create',
@@ -2027,6 +2050,7 @@ class e107Test extends \Codeception\Test\Unit
}
/*
public function testCanCache()
{
@@ -2087,6 +2111,7 @@ class e107Test extends \Codeception\Test\Unit
public function testIsCompatible()
{
// version => expected
$testPlugin = array(
'1' => false, // assumed incompatible.
@@ -2178,7 +2203,7 @@ class e107Test extends \Codeception\Test\Unit
foreach($testCases as $scenario => $testCase)
{
$result = $method->invoke($this->e107, $testCase['allowedHosts'], $testCase['httpHost']);
$this::assertSame($testCase['expected'], $result, "Failed scenario: {$scenario}");
$this::assertSame($testCase['expected'], $result, "Failed scenario: $scenario");
}
}
@@ -2224,4 +2249,260 @@ class e107Test extends \Codeception\Test\Unit
*/
/// -----START -------
/**
* Test old-style language file with define()
*
* @runInSeparateProcess
*/
public function testIncludeLanOldStyle()
{
$file_content = <<<PHP
<?php
define('TEST_LAN_OLD', 'Old Style Test');
define('TEST_LAN_ANOTHER', 'Another Value');
PHP;
$path = $this->createTempLanguageFile($file_content, 'English', 'lan_test_old');
$result = e107::includeLan($path, false, 'English');
self::assertEquals(1, $result, 'includeLan should return 1 for successful old-style file inclusion');
self::assertTrue(defined('TEST_LAN_OLD'), 'TEST_LAN_OLD should be defined');
self::assertEquals('Old Style Test', constant('TEST_LAN_OLD'), 'TEST_LAN_OLD should have correct value');
self::assertTrue(defined('TEST_LAN_ANOTHER'), 'TEST_LAN_ANOTHER should be defined');
self::assertEquals('Another Value', constant('TEST_LAN_ANOTHER'), 'TEST_LAN_ANOTHER should have correct value');
}
/**
* Test missing file
*
* @runInSeparateProcess
*/
public function testIncludeLanMissingFile()
{
$result = e107::includeLan(sys_get_temp_dir() . '/e107_test_languages/NonExistent/lan_missing.php', false, 'English');
self::assertFalse($result, 'includeLan should return false for missing file');
}
/**
* Test new-style language file with array return
*/
public function testIncludeLanNewStyle()
{
$file_content = <<<PHP
<?php
return [
'TEST_LAN_NEW_STYLE' => 'New Style Test',
'TEST_LAN_ANOTHER_NEW' => 'Another New Value'
];
PHP;
$path = $this->createTempLanguageFile($file_content, 'English', 'lan_test_new');
$result = e107::includeLan($path, true, 'English');
self::assertTrue($result, 'includeLan should return true for new-style file');
self::assertTrue(defined('TEST_LAN_NEW_STYLE'), 'TEST_LAN_NEW_STYLE should be defined');
self::assertEquals('New Style Test', constant('TEST_LAN_NEW_STYLE'), 'TEST_LAN_NEW_STYLE should have correct value');
self::assertTrue(defined('TEST_LAN_ANOTHER_NEW'), 'TEST_LAN_ANOTHER_NEW should be defined');
self::assertEquals('Another New Value', constant('TEST_LAN_ANOTHER_NEW'), 'TEST_LAN_ANOTHER_NEW should have correct value');
}
/**
* Test non-English new-style file with English fallback (plugin-style path)
*
* @runInSeparateProcess
*/
public function testIncludeLanNonEnglishWithFallback()
{
$english_content = <<<PHP
<?php
return [
'TEST_LAN_FALLBACK' => 'English Fallback',
'TEST_LAN_SHARED' => 'Shared Value',
'TEST_LAN_ENGLISH_ONLY' => 'English Only'
];
PHP;
$english_path = $this->createTempLanguageFile($english_content, 'English', 'lan_test_fallback', 'e107_plugins/testplugin/languages/');
$spanish_content = <<<PHP
<?php
return [
'TEST_LAN_FALLBACK' => 'Spanish Override',
'TEST_LAN_SHARED' => 'Spanish Shared'
// TEST_LAN_ENGLISH_ONLY missing
];
PHP;
$spanish_path = $this->createTempLanguageFile($spanish_content, 'Spanish', 'lan_test_fallback', 'e107_plugins/testplugin/languages/');
// Load Spanish first to define constants, then English as fallback
$result = e107::includeLan($spanish_path, true, 'Spanish');
e107::includeLan($english_path, true, 'English');
self::assertTrue($result, 'includeLan should return true for Spanish file');
self::assertTrue(defined('TEST_LAN_FALLBACK'), 'TEST_LAN_FALLBACK should be defined');
self::assertEquals('Spanish Override', constant('TEST_LAN_FALLBACK'), 'TEST_LAN_FALLBACK should use Spanish value');
self::assertTrue(defined('TEST_LAN_SHARED'), 'TEST_LAN_SHARED should be defined');
self::assertEquals('Spanish Shared', constant('TEST_LAN_SHARED'), 'TEST_LAN_SHARED should use Spanish value');
self::assertTrue(defined('TEST_LAN_ENGLISH_ONLY'), 'TEST_LAN_ENGLISH_ONLY should be defined');
self::assertEquals('English Only', constant('TEST_LAN_ENGLISH_ONLY'), 'TEST_LAN_ENGLISH_ONLY should fall back to English');
}
/**
* Test non-English new-style file with English fallback (custom path)
*
* @runInSeparateProcess
*/
public function testIncludeLanCustomPathWithFallback()
{
$english_content = <<<PHP
<?php
return [
'TEST_LAN_CUSTOM' => 'English Custom',
'TEST_LAN_SHARED_CUSTOM' => 'Shared Custom',
'TEST_LAN_ENGLISH_ONLY_CUSTOM' => 'English Only Custom'
];
PHP;
$english_path = $this->createTempLanguageFile($english_content, 'English', 'Spanish_global', 'folder/');
$spanish_content = <<<PHP
<?php
return [
'TEST_LAN_CUSTOM' => 'Spanish Custom Override',
'TEST_LAN_SHARED_CUSTOM' => 'Spanish Shared Custom'
// TEST_LAN_ENGLISH_ONLY_CUSTOM missing
];
PHP;
$spanish_path = $this->createTempLanguageFile($spanish_content, 'Spanish', 'Spanish_global', 'folder/');
// Load Spanish first to define constants, then English as fallback
$result = e107::includeLan($spanish_path, true, 'Spanish');
e107::includeLan($english_path, true, 'English');
self::assertTrue($result, 'includeLan should return true for Spanish file with custom path');
self::assertTrue(defined('TEST_LAN_CUSTOM'), 'TEST_LAN_CUSTOM should be defined');
self::assertEquals('Spanish Custom Override', constant('TEST_LAN_CUSTOM'), 'TEST_LAN_CUSTOM should use Spanish value');
self::assertTrue(defined('TEST_LAN_SHARED_CUSTOM'), 'TEST_LAN_SHARED_CUSTOM should be defined');
self::assertEquals('Spanish Shared Custom', constant('TEST_LAN_SHARED_CUSTOM'), 'TEST_LAN_SHARED_CUSTOM should use Spanish value');
self::assertTrue(defined('TEST_LAN_ENGLISH_ONLY_CUSTOM'), 'TEST_LAN_ENGLISH_ONLY_CUSTOM should be defined');
self::assertEquals('English Only Custom', constant('TEST_LAN_ENGLISH_ONLY_CUSTOM'), 'TEST_LAN_ENGLISH_ONLY_CUSTOM should fall back to English');
}
/**
* Test includeLanArray directly with reflection
*
* @runInSeparateProcess
*/
public function testIncludeLanArrayDirectly()
{
$english_content = <<<PHP
<?php
return [
'TEST_LAN_DIRECT' => 'English Direct',
'TEST_LAN_SHARED_DIRECT' => 'Shared Direct',
'TEST_LAN_ENGLISH_ONLY_DIRECT' => 'English Only Direct'
];
PHP;
$english_path = $this->createTempLanguageFile($english_content, 'English', 'lan_test_direct', 'e107_plugins/testplugin/languages/');
$spanish_content = <<<PHP
<?php
return [
'TEST_LAN_DIRECT' => 'Spanish Direct Override',
'TEST_LAN_SHARED_DIRECT' => 'Spanish Shared Direct'
// TEST_LAN_ENGLISH_ONLY_DIRECT missing
];
PHP;
$spanish_path = $this->createTempLanguageFile($spanish_content, 'Spanish', 'lan_test_direct', 'e107_plugins/testplugin/languages/');
// Use ReflectionClass to access private static method
$reflection = new ReflectionClass('e107');
$method = $reflection->getMethod('includeLanArray');
$method->setAccessible(true);
// Load Spanish first, then English as fallback
$spanish_terms = require($spanish_path);
$method->invoke(null, $spanish_terms, $spanish_path, 'Spanish');
$english_terms = require($english_path);
$method->invoke(null, $english_terms, $english_path, 'English');
self::assertTrue(defined('TEST_LAN_DIRECT'), 'TEST_LAN_DIRECT should be defined');
self::assertEquals('Spanish Direct Override', constant('TEST_LAN_DIRECT'), 'TEST_LAN_DIRECT should use Spanish value');
self::assertTrue(defined('TEST_LAN_SHARED_DIRECT'), 'TEST_LAN_SHARED_DIRECT should be defined');
self::assertEquals('Spanish Shared Direct', constant('TEST_LAN_SHARED_DIRECT'), 'TEST_LAN_SHARED_DIRECT should use Spanish value');
self::assertTrue(defined('TEST_LAN_ENGLISH_ONLY_DIRECT'), 'TEST_LAN_ENGLISH_ONLY_DIRECT should be defined');
self::assertEquals('English Only Direct', constant('TEST_LAN_ENGLISH_ONLY_DIRECT'), 'TEST_LAN_ENGLISH_ONLY_DIRECT should fall back to English');
}
/**
* Test Spanish old-style language file with English array fallback
*/
public function testIncludeLanSpanishOldStyleWithEnglishArrayFallback()
{
$english_content = <<<PHP
<?php
return [
'TEST_LAN_SPANISH_ENGLISH_FALLBACK_EN' => 'English Fallback',
'TEST_LAN_SHARED_SPANISH_ENGLISH_EN' => 'Shared English Value',
'TEST_LAN_ENGLISH_ONLY_SPANISH_ENGLISH' => 'English Only'
];
PHP;
$english_path = $this->createTempLanguageFile($english_content, 'English', 'lan_test_spanish_fallback', 'e107_plugins/testplugin/languages/');
$spanish_content = <<<PHP
<?php
define('TEST_LAN_SPANISH_ENGLISH_FALLBACK_ES', 'Spanish Override');
define('TEST_LAN_SHARED_SPANISH_ENGLISH_ES', 'Spanish Shared');
// TEST_LAN_ENGLISH_ONLY_SPANISH_ENGLISH not defined
PHP;
$spanish_path = $this->createTempLanguageFile($spanish_content, 'Spanish', 'lan_test_spanish_fallback', 'e107_plugins/testplugin/languages/');
// Load Spanish first (old-style), then English as fallback (array)
$result = e107::includeLan($spanish_path, true, 'Spanish');
e107::includeLan($english_path, true, 'English');
self::assertEquals(1, $result, 'includeLan should return 1 for successful old-style Spanish file inclusion');
self::assertTrue(defined('TEST_LAN_SPANISH_ENGLISH_FALLBACK_ES'), 'TEST_LAN_SPANISH_ENGLISH_FALLBACK_ES should be defined');
self::assertEquals('Spanish Override', constant('TEST_LAN_SPANISH_ENGLISH_FALLBACK_ES'), 'TEST_LAN_SPANISH_ENGLISH_FALLBACK_ES should use Spanish value');
self::assertTrue(defined('TEST_LAN_SHARED_SPANISH_ENGLISH_ES'), 'TEST_LAN_SHARED_SPANISH_ENGLISH_ES should be defined');
self::assertEquals('Spanish Shared', constant('TEST_LAN_SHARED_SPANISH_ENGLISH_ES'), 'TEST_LAN_SHARED_SPANISH_ENGLISH_ES should use Spanish value');
self::assertTrue(defined('TEST_LAN_ENGLISH_ONLY_SPANISH_ENGLISH'), 'TEST_LAN_ENGLISH_ONLY_SPANISH_ENGLISH should be defined');
self::assertEquals('English Only', constant('TEST_LAN_ENGLISH_ONLY_SPANISH_ENGLISH'), 'TEST_LAN_ENGLISH_ONLY_SPANISH_ENGLISH should fall back to English');
}
/**
* Helper to create a temporary language file
*/
private function createTempLanguageFile($content, $lang, $file, $prefix = 'e107_test_languages/')
{
$dir = sys_get_temp_dir() . "/$prefix$lang/";
if(!is_dir($dir))
{
mkdir($dir, 0777, true);
}
$path = tempnam($dir, $file); // Creates unique file with prefix
file_put_contents($path, $content);
$this->tempFiles[] = $path; // Track for cleanup
return $path;
}
/// ------ END --------
}