diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index e9ec7c6f0..ca809b954 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -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,46 +3713,134 @@ class e107 return ($ret && is_array($ret) && isset($ret[$key])) ? $ret[$key] : false; } +/** + * 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, $lang = '') +{ + if (!is_readable($path)) + { + if ((e_LANGUAGE === 'English') || self::getPref('noLanguageSubs')) + { + return 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 - */ - public static function includeLan($path, $force = false) - { - if (!is_readable($path)) - { - if ((e_LANGUAGE === 'English') || self::getPref('noLanguageSubs')) - { - return false; - } + self::getDebug()->log("Couldn't load language file: " . $path); - self::getDebug()->log("Couldn't load language file: " . $path); + $path = str_replace(e_LANGUAGE, 'English', $path); - $path = str_replace(e_LANGUAGE, 'English', $path); + self::getDebug()->log("Attempts to load default language file: " . $path); - self::getDebug()->log("Attempts to load default language file: " . $path); + if (!is_readable($path)) + { + self::getDebug()->log("Couldn't load default language file: " . $path); + return false; + } + } - if(!is_readable($path)) - { - self::getDebug()->log("Couldn't load default language file: " . $path); - return false; - } - } + $adminLanguage = self::getPref('adminlanguage'); - $adminLanguage = self::getPref('adminlanguage'); + if (e_ADMIN_AREA && vartrue($adminLanguage)) + { + $path = str_replace(e_LANGUAGE, $adminLanguage, $path); + } + + $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 language’s 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); + } + } + } +} - if(e_ADMIN_AREA && vartrue($adminLanguage)) - { - $path = str_replace(e_LANGUAGE, $adminLanguage, $path); - } - $ret = ($force) ? include($path) : include_once($path); - return (isset($ret)) ? $ret : ""; - } /** * Simplify importing of core Language files. @@ -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) { diff --git a/e107_handlers/language_class.php b/e107_handlers/language_class.php index 3910bbdae..bf4c9db4b 100644 --- a/e107_handlers/language_class.php +++ b/e107_handlers/language_class.php @@ -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') { diff --git a/e107_tests/tests/unit/e107Test.php b/e107_tests/tests/unit/e107Test.php index 95811d403..51adec212 100644 --- a/e107_tests/tests/unit/e107Test.php +++ b/e107_tests/tests/unit/e107Test.php @@ -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,12 +66,12 @@ class e107Test extends \Codeception\Test\Unit $this::assertEquals('/', e_HTTP); - } + }*/ public function testRenderLayout() { - $opts = array ( + $opts = array( 'magicSC' => array( '{---HEADER---}' => '

MY HEADER

', '{---FOOTER---}' => '

MY FOOTER

', @@ -171,7 +186,7 @@ class e107Test extends \Codeception\Test\Unit $this::assertStringContainsString('', $result); $this::assertStringNotContainsString('{BOOTSTRAP_BRANDING}', $result); - // var_export($result); + // var_export($result); } @@ -290,140 +305,141 @@ class e107Test extends \Codeception\Test\Unit $this::assertTrue($res); } */ - public function testGetSingleton() - { - $e107 = $this->e107; + public function testGetSingleton() + { - // test with path. - $result = $e107::getSingleton('override', e_HANDLER . 'override_class.php'); + $e107 = $this->e107; - $this::assertNotEmpty($result, 'Override class not loaded'); + // test with path. + $result = $e107::getSingleton('override', e_HANDLER . 'override_class.php'); - $exists = method_exists($result, 'override_check'); + $this::assertNotEmpty($result, 'Override class not loaded'); - $this::assertTrue($exists, 'Failed to load override class singleton'); + $exists = method_exists($result, 'override_check'); - // Test without path. - $result2 = $e107::getOverride(); - $exists2 = method_exists($result2, 'override_check'); - $this::assertTrue($exists2, 'Failed to load override class singleton'); + $this::assertTrue($exists, 'Failed to load override class singleton'); - } + // Test without path. + $result2 = $e107::getOverride(); + $exists2 = method_exists($result2, 'override_check'); + $this::assertTrue($exists2, 'Failed to load override class singleton'); -/* - public function testGetObject() - { - $res = null; - $this::assertTrue($res); - } + } - public function testGetConfig() - { - $res = null; - $this::assertTrue($res); - } + /* + public function testGetObject() + { + $res = null; + $this::assertTrue($res); + } - public function testGetPref() - { - $res = null; - $this::assertTrue($res); - } + public function testGetConfig() + { + $res = null; + $this::assertTrue($res); + } - public function testFindPref() - { - $res = null; - $this::assertTrue($res); - } + public function testGetPref() + { + $res = null; + $this::assertTrue($res); + } - public function testGetPlugConfig() - { - $res = null; - $this::assertTrue($res); - } + public function testFindPref() + { + $res = null; + $this::assertTrue($res); + } - public function testGetPlugLan() - { - $res = null; - $this::assertTrue($res); - } + public function testGetPlugConfig() + { + $res = null; + $this::assertTrue($res); + } - public function testGetPlugPref() - { - $res = null; - $this::assertTrue($res); - } + public function testGetPlugLan() + { + $res = null; + $this::assertTrue($res); + } - public function testFindPlugPref() - { - $res = null; - $this::assertTrue($res); - } + public function testGetPlugPref() + { + $res = null; + $this::assertTrue($res); + } - public function testGetThemeConfig() - { - $res = null; - $this::assertTrue($res); - } + public function testFindPlugPref() + { + $res = null; + $this::assertTrue($res); + } - public function testGetThemePref() - { - $res = null; - $this::assertTrue($res); - } + public function testGetThemeConfig() + { + $res = null; + $this::assertTrue($res); + } - public function testSetThemePref() - { - $res = null; - $this::assertTrue($res); - } + public function testGetThemePref() + { + $res = null; + $this::assertTrue($res); + } - public function testGetThemeGlyphs() - { - $res = null; - $this::assertTrue($res); - } + public function testSetThemePref() + { + $res = null; + $this::assertTrue($res); + } - public function testGetParser() - { - $res = null; - $this::assertTrue($res); - } + public function testGetThemeGlyphs() + { + $res = null; + $this::assertTrue($res); + } - public function testGetScParser() - { - $res = null; - $this::assertTrue($res); - } + public function testGetParser() + { + $res = null; + $this::assertTrue($res); + } - public function testGetSecureImg() - { - $res = null; - $this::assertTrue($res); - } + public function testGetScParser() + { + $res = null; + $this::assertTrue($res); + } - public function testGetScBatch() - { - $res = null; - $this::assertTrue($res); - } + public function testGetSecureImg() + { + $res = null; + $this::assertTrue($res); + } - public function testGetDb() - { - $res = null; - $this::assertTrue($res); - } + public function testGetScBatch() + { + $res = null; + $this::assertTrue($res); + } - public function testGetCache() - { - $res = null; - $this::assertTrue($res); - } + public function testGetDb() + { + $res = null; + $this::assertTrue($res); + } - public function testGetBB() - { - $res = null; - $this::assertTrue($res); - }*/ + public function testGetCache() + { + $res = null; + $this::assertTrue($res); + } + + public function testGetBB() + { + $res = null; + $this::assertTrue($res); + }*/ public function testGetUserSession() @@ -747,19 +763,20 @@ class e107Test extends \Codeception\Test\Unit */ public function testLibrary() { + $e107 = $this->e107; - $expected = array ( - 'js' => - array ( - 0 => '{e_WEB}lib/font-awesome/5/js/all.min.js', - 1 => '{e_WEB}lib/font-awesome/5/js/v4-shims.min.js', - ), - 'css' => - array ( - 0 => '{e_WEB}lib/font-awesome/5/css/all.min.css', - 1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css', - ), + $expected = array( + 'js' => + array( + 0 => '{e_WEB}lib/font-awesome/5/js/all.min.js', + 1 => '{e_WEB}lib/font-awesome/5/js/v4-shims.min.js', + ), + 'css' => + array( + 0 => '{e_WEB}lib/font-awesome/5/css/all.min.css', + 1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css', + ), ); @@ -770,27 +787,27 @@ class e107Test extends \Codeception\Test\Unit // ------------------- // Expecting only the JS portion of the library. - $expected = array ( - 'js' => - array ( - 0 => '{e_WEB}lib/font-awesome/5/js/all.min.js', - 1 => '{e_WEB}lib/font-awesome/5/js/v4-shims.min.js', - ), + $expected = array( + 'js' => + array( + 0 => '{e_WEB}lib/font-awesome/5/js/all.min.js', + 1 => '{e_WEB}lib/font-awesome/5/js/v4-shims.min.js', + ), ); $result = $e107::library('files', 'fontawesome5', null, ['js']); $this::assertSame($expected, $result); // ------------------- - $expected = array ( - 'js' => - array ( - 0 => '{e_WEB}lib/bootstrap/5/js/bootstrap.bundle.min.js', - ), - 'css' => - array ( - 0 => '{e_WEB}lib/bootstrap/5/css/bootstrap.min.css', - ), + $expected = array( + 'js' => + array( + 0 => '{e_WEB}lib/bootstrap/5/js/bootstrap.bundle.min.js', + ), + 'css' => + array( + 0 => '{e_WEB}lib/bootstrap/5/css/bootstrap.min.css', + ), ); @@ -798,92 +815,93 @@ class e107Test extends \Codeception\Test\Unit $this::assertSame($expected, $result); } -/* - public function testGetJs() - { - $res = null; - $this::assertTrue($res); - } - public function testSet() - { - $res = null; - $this::assertTrue($res); - } + /* + public function testGetJs() + { + $res = null; + $this::assertTrue($res); + } - public function testJs() - { - $res = null; - $this::assertTrue($res); - } + public function testSet() + { + $res = null; + $this::assertTrue($res); + } - public function testLink() - { + public function testJs() + { + $res = null; + $this::assertTrue($res); + } + + public function testLink() + { - } + } - public function testCss() - { - $res = null; - $this::assertTrue($res); - } + public function testCss() + { + $res = null; + $this::assertTrue($res); + } - public function testDebug() - { - $res = null; - $this::assertTrue($res); - } + public function testDebug() + { + $res = null; + $this::assertTrue($res); + } - public function testGetJshelper() - { - $res = null; - $this::assertTrue($res); - } + public function testGetJshelper() + { + $res = null; + $this::assertTrue($res); + } - public function testMeta() - { - $res = null; - $this::assertTrue($res); - } + public function testMeta() + { + $res = null; + $this::assertTrue($res); + } - public function testGetAdminUI() - { - $res = null; - $this::assertTrue($res); - } + public function testGetAdminUI() + { + $res = null; + $this::assertTrue($res); + } - public function testGetAddon() - { - $res = null; - $this::assertTrue($res); - } + public function testGetAddon() + { + $res = null; + $this::assertTrue($res); + } - public function testGetAddonConfig() - { - $res = null; - $this::assertTrue($res); - } + public function testGetAddonConfig() + { + $res = null; + $this::assertTrue($res); + } - public function testCallMethod() - { - $res = null; - $this::assertTrue($res); - } -*/ + public function testCallMethod() + { + $res = null; + $this::assertTrue($res); + } + */ public function testGetUrlConfig() { - $expected = array ( - 'index' => - array ( - 'alias' => 'contact', - 'regex' => '^{alias}\\/?$', - 'sef' => '{alias}', - 'redirect' => '{e_BASE}contact.php', - ), - ); + $expected = array( + 'index' => + array( + 'alias' => 'contact', + 'regex' => '^{alias}\\/?$', + 'sef' => '{alias}', + 'redirect' => '{e_BASE}contact.php', + ), + ); $result = e107::getUrlConfig(); $this::assertNotEmpty($result['contact']); @@ -891,205 +909,205 @@ class e107Test extends \Codeception\Test\Unit // ---- - $expected = array ( - 'alias' => 'contact', - 'regex' => '^{alias}\\/?$', - 'sef' => '{alias}', - 'redirect' => '{e_BASE}contact.php', - ); + $expected = array( + 'alias' => 'contact', + 'regex' => '^{alias}\\/?$', + 'sef' => '{alias}', + 'redirect' => '{e_BASE}contact.php', + ); $result = e107::getUrlConfig('route'); $this::assertNotEmpty($result['contact/index']); $this::assertSame($expected, $result['contact/index']); - - } -/* - public function testGetThemeInfo() - { - $res = null; - $this::assertTrue($res); } - public function testCoreTemplatePath() - { - $res = null; - $this::assertTrue($res); - } + /* + public function testGetThemeInfo() + { + $res = null; + $this::assertTrue($res); + } - public function testTemplatePath() - { - $res = null; - $this::assertTrue($res); - } -*/ + public function testCoreTemplatePath() + { + $res = null; + $this::assertTrue($res); + } + + public function testTemplatePath() + { + $res = null; + $this::assertTrue($res); + } + */ public function testLoadAdminIcons() { $e107 = $this->e107; - $legacyList = array ( - 'E_16_FACEBOOK' => '\'\'', - 'E_16_TWITTER' => '\'\'', - 'E_16_GITHUB' => '\'\'', - 'E_16_E107' => '\'\'', - 'E_32_E107' => '\'\'', - 'E_32_ADMIN' => '', - 'E_32_ADPASS' => '', - 'E_32_BANLIST' => '', - 'E_32_CACHE' => ' ', - 'E_32_CREDITS' => '', - 'E_32_CRON' => ' ', - 'E_32_CUST' => ' ', - 'E_32_DATAB' => ' ', - 'E_32_DOCS' => ' ', - 'E_32_EMOTE' => ' ', - 'E_32_FILE' => ' ', - 'E_32_FORUM' => ' ', - 'E_32_FRONT' => ' ', - 'E_32_IMAGES' => ' ', - 'E_32_INSPECT' => ' ', - 'E_32_LINKS' => ' ', - 'E_32_WELCOME' => ' ', - 'E_32_MAIL' => ' ', - 'E_32_MAINTAIN' => ' ', - 'E_32_MENUS' => ' ', - 'E_32_META' => ' ', - 'E_32_NEWS' => ' ', - 'E_32_NEWSFEED' => ' ', - 'E_32_NOTIFY' => ' ', - 'E_32_PHP' => ' ', - 'E_32_POLLS' => ' ', - 'E_32_PREFS' => ' ', - 'E_32_SEARCH' => ' ', - 'E_32_UPLOADS' => ' ', - 'E_32_EURL' => ' ', - 'E_32_USER' => ' ', - 'E_32_USER_EXTENDED' => ' ', - 'E_32_USERCLASS' => ' ', - 'E_32_LANGUAGE' => ' ', - 'E_32_PLUGIN' => ' ', - 'E_32_PLUGMANAGER' => ' ', - 'E_32_MAIN' => ' ', - 'E_32_THEMEMANAGER' => ' ', - 'E_32_COMMENT' => ' ', - 'E_32_ADMINLOG' => ' ', - 'E_32_LOGOUT' => ' ', - 'E_32_MANAGE' => ' ', - 'E_32_CREATE' => ' ', - 'E_32_SETTINGS' => ' ', - 'E_32_SYSINFO' => ' ', - 'E_32_CAT_SETT' => ' ', - 'E_32_CAT_USER' => ' ', - 'E_32_CAT_CONT' => ' ', - 'E_32_CAT_FILE' => ' ', - 'E_32_CAT_TOOL' => ' ', - 'E_32_CAT_PLUG' => ' ', - 'E_32_CAT_MANAGE' => ' ', - 'E_32_CAT_MISC' => ' ', - 'E_32_CAT_ABOUT' => ' ', - 'E_32_NAV_MAIN' => ' ', - 'E_32_NAV_DOCS' => ' ', - 'E_32_NAV_LEAV' => ' ', - 'E_32_NAV_LGOT' => ' ', - 'E_32_NAV_ARROW' => ' ', - 'E_32_NAV_ARROW_OVER' => ' ', - 'E_16_ADMIN' => '', - 'E_16_ADPASS' => '', - 'E_16_BANLIST' => '', - 'E_16_CACHE' => '', - 'E_16_COMMENT' => '', - 'E_16_CREDITS' => '', - 'E_16_CRON' => '', - 'E_16_CUST' => '', - 'E_16_CUSTOMFIELD' => '', - 'E_16_DATAB' => '', - 'E_16_DOCS' => '', - 'E_16_EMOTE' => '', - 'E_16_FILE' => '', - 'E_16_FORUM' => '', - 'E_16_FRONT' => '', - 'E_16_IMAGES' => '', - 'E_16_INSPECT' => '', - 'E_16_LINKS' => '', - 'E_16_WELCOME' => '', - 'E_16_MAIL' => '', - 'E_16_MAINTAIN' => '', - 'E_16_MENUS' => '', - 'E_16_META' => '', - 'E_16_NEWS' => '', - 'E_16_NEWSFEED' => '', - 'E_16_NOTIFY' => '', - 'E_16_PHP' => '', - 'E_16_POLLS' => '', - 'E_16_PREFS' => '', - 'E_16_SEARCH' => '', - 'E_16_UPLOADS' => '', - 'E_16_EURL' => '', - 'E_16_USER' => '', - 'E_16_USER_EXTENDED' => '', - 'E_16_USERCLASS' => '', - 'E_16_LANGUAGE' => '', - 'E_16_PLUGIN' => '', - 'E_16_PLUGMANAGER' => '', - 'E_16_THEMEMANAGER' => '', - 'E_16_ADMINLOG' => '', - 'E_16_MANAGE' => '', - 'E_16_CREATE' => '', - 'E_16_SETTINGS' => '', - 'E_16_SYSINFO' => '', - 'E_16_FAILEDLOGIN' => '', - 'E_32_TRUE' => '', - 'ADMIN_CHILD_ICON' => '', - 'ADMIN_FILTER_ICON' => '', - 'ADMIN_TRUE_ICON' => '', - 'ADMIN_FALSE_ICON' => '', - 'ADMIN_WARNING_ICON' => '', - 'ADMIN_GRID_ICON' => '', - 'ADMIN_LIST_ICON' => '', - 'ADMIN_EDIT_ICON' => "", - 'ADMIN_DELETE_ICON' => "", - 'ADMIN_SORT_ICON' => "", - 'ADMIN_EXECUTE_ICON' => "", - 'ADMIN_PAGES_ICON' => "", - 'ADMIN_ADD_ICON' => '', - 'ADMIN_INFO_ICON' => '', - 'ADMIN_CONFIGURE_ICON' => "", - 'ADMIN_VIEW_ICON' => "", - 'ADMIN_URL_ICON' => '', - 'ADMIN_INSTALLPLUGIN_ICON' => '', - 'ADMIN_UNINSTALLPLUGIN_ICON' => "", - 'ADMIN_UPGRADEPLUGIN_ICON' => "", - 'ADMIN_REPAIRPLUGIN_ICON' => "", - 'ADMIN_UP_ICON' => "", - 'ADMIN_DOWN_ICON' => "", - 'ADMIN_EDIT_ICON_PATH' => '/e107_images/admin_images/edit_32.png', - 'ADMIN_DELETE_ICON_PATH' => '/e107_images/admin_images/delete_32.png', - 'ADMIN_WARNING_ICON_PATH' => '/e107_images/admin_images/warning_32.png', - 'E_24_PLUGIN' => " ", - 'E_16_UNDO' => "", - 'E_32_UNDO' => "" + $legacyList = array( + 'E_16_FACEBOOK' => '\'\'', + 'E_16_TWITTER' => '\'\'', + 'E_16_GITHUB' => '\'\'', + 'E_16_E107' => '\'\'', + 'E_32_E107' => '\'\'', + 'E_32_ADMIN' => '', + 'E_32_ADPASS' => '', + 'E_32_BANLIST' => '', + 'E_32_CACHE' => ' ', + 'E_32_CREDITS' => '', + 'E_32_CRON' => ' ', + 'E_32_CUST' => ' ', + 'E_32_DATAB' => ' ', + 'E_32_DOCS' => ' ', + 'E_32_EMOTE' => ' ', + 'E_32_FILE' => ' ', + 'E_32_FORUM' => ' ', + 'E_32_FRONT' => ' ', + 'E_32_IMAGES' => ' ', + 'E_32_INSPECT' => ' ', + 'E_32_LINKS' => ' ', + 'E_32_WELCOME' => ' ', + 'E_32_MAIL' => ' ', + 'E_32_MAINTAIN' => ' ', + 'E_32_MENUS' => ' ', + 'E_32_META' => ' ', + 'E_32_NEWS' => ' ', + 'E_32_NEWSFEED' => ' ', + 'E_32_NOTIFY' => ' ', + 'E_32_PHP' => ' ', + 'E_32_POLLS' => ' ', + 'E_32_PREFS' => ' ', + 'E_32_SEARCH' => ' ', + 'E_32_UPLOADS' => ' ', + 'E_32_EURL' => ' ', + 'E_32_USER' => ' ', + 'E_32_USER_EXTENDED' => ' ', + 'E_32_USERCLASS' => ' ', + 'E_32_LANGUAGE' => ' ', + 'E_32_PLUGIN' => ' ', + 'E_32_PLUGMANAGER' => ' ', + 'E_32_MAIN' => ' ', + 'E_32_THEMEMANAGER' => ' ', + 'E_32_COMMENT' => ' ', + 'E_32_ADMINLOG' => ' ', + 'E_32_LOGOUT' => ' ', + 'E_32_MANAGE' => ' ', + 'E_32_CREATE' => ' ', + 'E_32_SETTINGS' => ' ', + 'E_32_SYSINFO' => ' ', + 'E_32_CAT_SETT' => ' ', + 'E_32_CAT_USER' => ' ', + 'E_32_CAT_CONT' => ' ', + 'E_32_CAT_FILE' => ' ', + 'E_32_CAT_TOOL' => ' ', + 'E_32_CAT_PLUG' => ' ', + 'E_32_CAT_MANAGE' => ' ', + 'E_32_CAT_MISC' => ' ', + 'E_32_CAT_ABOUT' => ' ', + 'E_32_NAV_MAIN' => ' ', + 'E_32_NAV_DOCS' => ' ', + 'E_32_NAV_LEAV' => ' ', + 'E_32_NAV_LGOT' => ' ', + 'E_32_NAV_ARROW' => ' ', + 'E_32_NAV_ARROW_OVER' => ' ', + 'E_16_ADMIN' => '', + 'E_16_ADPASS' => '', + 'E_16_BANLIST' => '', + 'E_16_CACHE' => '', + 'E_16_COMMENT' => '', + 'E_16_CREDITS' => '', + 'E_16_CRON' => '', + 'E_16_CUST' => '', + 'E_16_CUSTOMFIELD' => '', + 'E_16_DATAB' => '', + 'E_16_DOCS' => '', + 'E_16_EMOTE' => '', + 'E_16_FILE' => '', + 'E_16_FORUM' => '', + 'E_16_FRONT' => '', + 'E_16_IMAGES' => '', + 'E_16_INSPECT' => '', + 'E_16_LINKS' => '', + 'E_16_WELCOME' => '', + 'E_16_MAIL' => '', + 'E_16_MAINTAIN' => '', + 'E_16_MENUS' => '', + 'E_16_META' => '', + 'E_16_NEWS' => '', + 'E_16_NEWSFEED' => '', + 'E_16_NOTIFY' => '', + 'E_16_PHP' => '', + 'E_16_POLLS' => '', + 'E_16_PREFS' => '', + 'E_16_SEARCH' => '', + 'E_16_UPLOADS' => '', + 'E_16_EURL' => '', + 'E_16_USER' => '', + 'E_16_USER_EXTENDED' => '', + 'E_16_USERCLASS' => '', + 'E_16_LANGUAGE' => '', + 'E_16_PLUGIN' => '', + 'E_16_PLUGMANAGER' => '', + 'E_16_THEMEMANAGER' => '', + 'E_16_ADMINLOG' => '', + 'E_16_MANAGE' => '', + 'E_16_CREATE' => '', + 'E_16_SETTINGS' => '', + 'E_16_SYSINFO' => '', + 'E_16_FAILEDLOGIN' => '', + 'E_32_TRUE' => '', + 'ADMIN_CHILD_ICON' => '', + 'ADMIN_FILTER_ICON' => '', + 'ADMIN_TRUE_ICON' => '', + 'ADMIN_FALSE_ICON' => '', + 'ADMIN_WARNING_ICON' => '', + 'ADMIN_GRID_ICON' => '', + 'ADMIN_LIST_ICON' => '', + 'ADMIN_EDIT_ICON' => "", + 'ADMIN_DELETE_ICON' => "", + 'ADMIN_SORT_ICON' => "", + 'ADMIN_EXECUTE_ICON' => "", + 'ADMIN_PAGES_ICON' => "", + 'ADMIN_ADD_ICON' => '', + 'ADMIN_INFO_ICON' => '', + 'ADMIN_CONFIGURE_ICON' => "", + 'ADMIN_VIEW_ICON' => "", + 'ADMIN_URL_ICON' => '', + 'ADMIN_INSTALLPLUGIN_ICON' => '', + 'ADMIN_UNINSTALLPLUGIN_ICON' => "", + 'ADMIN_UPGRADEPLUGIN_ICON' => "", + 'ADMIN_REPAIRPLUGIN_ICON' => "", + 'ADMIN_UP_ICON' => "", + 'ADMIN_DOWN_ICON' => "", + 'ADMIN_EDIT_ICON_PATH' => '/e107_images/admin_images/edit_32.png', + 'ADMIN_DELETE_ICON_PATH' => '/e107_images/admin_images/delete_32.png', + 'ADMIN_WARNING_ICON_PATH' => '/e107_images/admin_images/warning_32.png', + 'E_24_PLUGIN' => " ", + 'E_16_UNDO' => "", + 'E_32_UNDO' => "" ); $new = $e107::loadAdminIcons(); - foreach($new as $key=>$val) + foreach($new as $key => $val) { 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]); + $this::assertSame($legacyList[$key], $val, $key . " should equal: " . $legacyList[$key]); } - foreach($legacyList as $key=>$val) + foreach($legacyList as $key => $val) { if(!isset($new[$key])) { - $this->fail("{$key} is missing from admin_icons_template"); + $this::fail("$key is missing from admin_icons_template"); } } @@ -1098,7 +1116,7 @@ class e107Test extends \Codeception\Test\Unit $this::assertSame($new, $template2); - $range = range(1,10); + $range = range(1, 10); foreach($range as $t) { e107::loadAdminIcons(); @@ -1111,6 +1129,7 @@ class e107Test extends \Codeception\Test\Unit public function testGetCoreTemplate() { + $e107 = $this->e107; $templates = scandir(e_CORE . "templates"); @@ -1149,59 +1168,60 @@ class e107Test extends \Codeception\Test\Unit //$res = null; //$this::assertTrue($res); } -/* - private function clearRelatedRegistry($type) - { - $registry = e107::getRegistry('_all_'); - - $result = []; - foreach($registry as $reg => $v) + /* + private function clearRelatedRegistry($type) { - if(strpos($reg, $type) !== false) + $registry = e107::getRegistry('_all_'); + + $result = []; + foreach($registry as $reg => $v) { - e107::setRegistry($reg); - $result[] = $reg; + if(strpos($reg, $type) !== false) + { + e107::setRegistry($reg); + $result[] = $reg; + } + } + sort($result); + + return $result; + }*/ + /* + public function testGetTemplatePluginThemeMatch() + { + e107::plugLan('download', 'front', true); + + e107::getConfig()->set('sitetheme', 'bootstrap3'); + $template = e107::getTemplate('download', null, null); + var_export($template['header']); + echo "\n\n"; + + + e107::getConfig()->set('sitetheme', '_blank'); + $template = e107::getTemplate('download', null, null); + var_export($template['header']); + echo "\n\n"; + + e107::getConfig()->set('sitetheme', 'bootstrap3'); // doesn't have a download template, so fallback. + $template = e107::getTemplate('download', null, null); // theme override is enabled by default. + var_export($template['header']); + echo "\n\n"; + + e107::getConfig()->set('sitetheme', 'bootstrap3'); } - - sort($result); - - return $result; - }*/ -/* - public function testGetTemplatePluginThemeMatch() - { - e107::plugLan('download', 'front', true); - - e107::getConfig()->set('sitetheme', 'bootstrap3'); - $template = e107::getTemplate('download', null, null); - var_export($template['header']); - echo "\n\n"; - - - e107::getConfig()->set('sitetheme', '_blank'); - $template = e107::getTemplate('download', null, null); - var_export($template['header']); - echo "\n\n"; - - e107::getConfig()->set('sitetheme', 'bootstrap3'); // doesn't have a download template, so fallback. - $template = e107::getTemplate('download', null, null); // theme override is enabled by default. - var_export($template['header']); - echo "\n\n"; - - e107::getConfig()->set('sitetheme', 'bootstrap3'); - } -*/ + */ 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); @@ -1303,71 +1325,72 @@ class e107Test extends \Codeception\Test\Unit $this::assertTrue($res); } */ + /** + * @runInSeparateProcess + * @return void + */ public function testPlugLan() { $e107 = $this->e107; $tests = array( - // plug, param 1, param 2, expected - 0 => array('banner', '', false, 'e107_plugins/banner/languages/English_front.php'), - 1 => array('forum', 'front', true, 'e107_plugins/forum/languages/English/English_front.php'), - 2 => array('gallery', true, true, 'e107_plugins/gallery/languages/English/English_admin.php'), - 3 => array('forum', 'menu', true, 'e107_plugins/forum/languages/English/English_menu.php'), - 4 => array('banner', true, false, 'e107_plugins/banner/languages/English_admin.php'), - 5 => array('chatbox_menu', e_LANGUAGE, false, 'e107_plugins/chatbox_menu/languages/English/English.php'), - 6 => array('comment_menu', null, false, 'e107_plugins/comment_menu/languages/English.php'), - 7 => array('poll', null, false, 'e107_plugins/poll/languages/English.php'), - 8 => array('poll', null, false, 'e107_plugins/poll/languages/English.php'), + // plug, param 1, param 2, expected + 0 => array('banner', '', false, 'e107_plugins/banner/languages/English_front.php'), + 1 => array('forum', 'front', true, 'e107_plugins/forum/languages/English/English_front.php'), + 2 => array('gallery', true, true, 'e107_plugins/gallery/languages/English/English_admin.php'), + 3 => array('forum', 'menu', true, 'e107_plugins/forum/languages/English/English_menu.php'), + 4 => array('banner', true, false, 'e107_plugins/banner/languages/English_admin.php'), + 5 => array('chatbox_menu', e_LANGUAGE, false, 'e107_plugins/chatbox_menu/languages/English/English.php'), + 6 => array('comment_menu', null, false, 'e107_plugins/comment_menu/languages/English.php'), + 7 => array('poll', null, false, 'e107_plugins/poll/languages/English.php'), + 8 => array('poll', null, false, 'e107_plugins/poll/languages/English.php'), ); - foreach($tests as $plug=>$var) + foreach($tests as $plug => $var) { $result = $e107::plugLan($var[0], $var[1], $var[2], true); if(!isset($var[3])) { - echo $result."\n"; + echo $result . "\n"; continue; } $this::assertStringContainsString($var[3], $result); $e107::plugLan($var[0], $var[1], $var[2]); } -/* - $registry = $e107::getRegistry('_all_'); - - foreach($registry as $k=>$v) - { - if(strpos($k, 'core/e107/pluglan/') !== false) - { - echo $k."\n"; - - } - - - }*/ + /* + $registry = $e107::getRegistry('_all_'); + foreach($registry as $k=>$v) + { + if(strpos($k, 'core/e107/pluglan/') !== false) + { + echo $k."\n"; + } + }*/ } function testDetectRoute() { + e107::getPlugin()->install('forum'); $tests = array( 0 => array( - 'plugin' => 'forum', - 'uri' => '/e107_plugins/forum/forum.php?f=rules', - 'expected' => 'forum/rules', + 'plugin' => 'forum', + 'uri' => '/e107_plugins/forum/forum.php?f=rules', + 'expected' => 'forum/rules', ), 1 => array( - 'plugin' => 'forum', - 'uri' => '/e107_plugins/forum/forum_viewforum.php?id=543123', - 'expected' => 'forum/forum', + 'plugin' => 'forum', + 'uri' => '/e107_plugins/forum/forum_viewforum.php?id=543123', + 'expected' => 'forum/forum', ), ); @@ -1377,7 +1400,7 @@ class e107Test extends \Codeception\Test\Unit $result = e107::detectRoute($var['plugin'], $var['uri']); if(empty($var['expected'])) { - echo $result."\n"; + echo $result . "\n"; continue; } @@ -1385,19 +1408,16 @@ class e107Test extends \Codeception\Test\Unit } - - - e107::getPlugin()->uninstall('forum'); } -/* - public function testThemeLan() - { - $result = e107::themeLan(null, 'basic-light'); + /* + public function testThemeLan() + { + $result = e107::themeLan(null, 'basic-light'); - }*/ + }*/ /* public function testLan() { @@ -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'); @@ -1489,28 +1510,28 @@ class e107Test extends \Codeception\Test\Unit // Test FULL url option on Legacy url with new options['mode'] $tests = array( 0 => array( - 'plugin' => 'news/view/item', - 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), - 'row' => array(), - 'options' => ['mode' => 'full'], + 'plugin' => 'news/view/item', + 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), + 'row' => array(), + 'options' => ['mode' => 'full'], ), 1 => array( - 'plugin' => 'news/view/item', - 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), - 'row' => 'full=1&encode=0', - 'options' => ['mode' => 'full'], + 'plugin' => 'news/view/item', + 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), + 'row' => 'full=1&encode=0', + 'options' => ['mode' => 'full'], ), 2 => array( - 'plugin' => 'news/view/item', - 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), - 'row' => '', - 'options' => ['mode' => 'full'], + 'plugin' => 'news/view/item', + 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), + 'row' => '', + 'options' => ['mode' => 'full'], ), 3 => array( - 'plugin' => 'news/view/item', - 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), - 'row' => null, - 'options' => ['mode' => 'full'], + 'plugin' => 'news/view/item', + 'key' => array('news_id' => 1, 'news_sef' => 'my-news-item', 'category_sef' => 'my-category'), + 'row' => null, + 'options' => ['mode' => 'full'], ), ); @@ -1521,7 +1542,6 @@ class e107Test extends \Codeception\Test\Unit } - $tests = array(); $all = e107::getAddonConfig('e_url'); @@ -1562,23 +1582,22 @@ class e107Test extends \Codeception\Test\Unit echo $result . "\n"; continue; } - self::assertEquals($var['_expected_'], $result, 'Failed on test #'.$index); + self::assertEquals($var['_expected_'], $result, 'Failed on test #' . $index); // $this::assertEquals("https://localhost/e107/news", $result); } - - } public function testUrlDomain() { + // e107 v2.4 - test for custom domain $obj = $this->e107; e107::getPlugin()->install('_blank'); - $result = $obj::url('_blank', 'parked', null, ['mode'=>'full']); + $result = $obj::url('_blank', 'parked', null, ['mode' => 'full']); self::assertSame('https://parked-domain.com/custom', $result); e107::getPlugin()->uninstall('_blank'); @@ -1611,12 +1630,12 @@ class e107Test extends \Codeception\Test\Unit $oldConfig = e107::getPref('url_config'); $newConfig = array( - 'news' => 'core/sef_full', - 'page' => 'core/sef_chapters', - 'search' => 'core/rewrite', - 'system' => 'core/rewrite', - 'user' => 'core/rewrite', - // 'gallery' => 'plugin/rewrite' + 'news' => 'core/sef_full', + 'page' => 'core/sef_chapters', + 'search' => 'core/rewrite', + 'system' => 'core/rewrite', + 'user' => 'core/rewrite', + // 'gallery' => 'plugin/rewrite' ); @@ -1717,6 +1736,7 @@ class e107Test extends \Codeception\Test\Unit /** * Save the url_config preference + * * @param array $newConfig */ private function setUrlConfig($newConfig = array()) @@ -1837,10 +1857,11 @@ class e107Test extends \Codeception\Test\Unit public function testWysiwyg() { + // Simulate editors being installed. - $editors = array ( - 'tinymce4' => 'TinyMce4', - 'simplemde' => 'SimpleMDE', + $editors = array( + 'tinymce4' => 'TinyMce4', + 'simplemde' => 'SimpleMDE', ); e107::getConfig() @@ -1850,7 +1871,7 @@ class e107Test extends \Codeception\Test\Unit global $_E107; $_E107['phpunit'] = true; // make sure pref is re-loaded. - // $tinyMceInstalled = e107::isInstalled('tinymce4'); + // $tinyMceInstalled = e107::isInstalled('tinymce4'); $tests = array( //input => expected @@ -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), @@ -2006,70 +2028,72 @@ class e107Test extends \Codeception\Test\Unit $this::assertTrue($res); } */ - public function testSet_request() - { - $tests = array( + public function testSet_request() + { - 'mode=main&action=create' => 'mode=main&action=create', - '[debug=counts!]mode=pref_editor&type=vstore' => 'mode=pref_editor&type=vstore', - 'searchquery=šýá&mode=main' => 'searchquery=šýá&mode=main', - 'mode=main&action=custom&other[key]=1' => 'mode=main&action=custom&other[key]=1', - 'searchquery="two words"&mode=main' => 'searchquery=%22two words%22&mode=main', - "searchquery='two words'&mode=main" => "searchquery=%27two words%27&mode=main", - // - ); + $tests = array( - foreach($tests as $input => $expected) + 'mode=main&action=create' => 'mode=main&action=create', + '[debug=counts!]mode=pref_editor&type=vstore' => 'mode=pref_editor&type=vstore', + 'searchquery=šýá&mode=main' => 'searchquery=šýá&mode=main', + 'mode=main&action=custom&other[key]=1' => 'mode=main&action=custom&other[key]=1', + 'searchquery="two words"&mode=main' => 'searchquery=%22two words%22&mode=main', + "searchquery='two words'&mode=main" => "searchquery=%27two words%27&mode=main", + // + ); + + foreach($tests as $input => $expected) + { + $result = $this->e107->set_request(true, $input); + $this::assertSame($expected, $result); + } + + + } + + /* + public function testCanCache() { - $result = $this->e107->set_request(true, $input); - $this::assertSame($expected, $result); + $res = null; + $this::assertTrue($res); } + public function testIsSecure() + { + $res = null; + $this::assertTrue($res); + } - } -/* - public function testCanCache() - { - $res = null; - $this::assertTrue($res); - } + public function testGetip() + { + $res = null; + $this::assertTrue($res); + } - public function testIsSecure() - { - $res = null; - $this::assertTrue($res); - } + public function testIpEncode() + { + $res = null; + $this::assertTrue($res); + } - public function testGetip() - { - $res = null; - $this::assertTrue($res); - } + public function testIpdecode() + { + $res = null; + $this::assertTrue($res); + } - public function testIpEncode() - { - $res = null; - $this::assertTrue($res); - } + public function testGet_host_name() + { + $res = null; + $this::assertTrue($res); + } - public function testIpdecode() - { - $res = null; - $this::assertTrue($res); - } - - public function testGet_host_name() - { - $res = null; - $this::assertTrue($res); - } - - public function testParseMemorySize() - { - $res = null; - $this::assertTrue($res); - } - */ + public function testParseMemorySize() + { + $res = null; + $this::assertTrue($res); + } + */ public function testIsInstalled() { @@ -2087,8 +2111,9 @@ class e107Test extends \Codeception\Test\Unit public function testIsCompatible() { + // version => expected - $testPlugin = array ( + $testPlugin = array( '1' => false, // assumed incompatible. '1.2.3' => false, '1.2' => false, @@ -2107,13 +2132,13 @@ class e107Test extends \Codeception\Test\Unit $e107 = $this->e107; - foreach($testPlugin as $input=>$expected) + foreach($testPlugin as $input => $expected) { $result = $e107::isCompatible($input, 'plugin'); $this::assertSame($expected, $result); } - $testTheme = array ( + $testTheme = array( '1' => true, // assumed incompatible. '1.2.3' => true, '1.2' => true, @@ -2130,57 +2155,57 @@ class e107Test extends \Codeception\Test\Unit '3' => false, ); - foreach($testTheme as $input=>$expected) + foreach($testTheme as $input => $expected) { $result = $e107::isCompatible($input, 'theme'); $this::assertSame($expected, $result); - // $ret[$input] = $result; + // $ret[$input] = $result; } } - public function testIsAllowedHost(): void - { + public function testIsAllowedHost(): void + { - $reflection = new ReflectionClass($this->e107); - $method = $reflection->getMethod('isAllowedHost'); - $method->setAccessible(true); + $reflection = new ReflectionClass($this->e107); + $method = $reflection->getMethod('isAllowedHost'); + $method->setAccessible(true); - $testCases = [ - 'Empty allowed hosts should return true' => [ - 'allowedHosts' => [], - 'httpHost' => 'anyhost.com', - 'expected' => true - ], - 'Exact matching host should return true' => [ - 'allowedHosts' => ['example.com', 'testsite.org'], - 'httpHost' => 'example.com', - 'expected' => true - ], - 'Subdomain matching allowed host should return true' => [ - 'allowedHosts' => ['example.com'], - 'httpHost' => 'subdomain.example.com', - 'expected' => true - ], - 'Unrelated host should return false' => [ - 'allowedHosts' => ['example.com'], - 'httpHost' => 'unrelated.com', - 'expected' => false - ], - 'Similar but incorrect subdomain pattern should return false' => [ - 'allowedHosts' => ['example.com'], - 'httpHost' => 'subdomain-example.com', - 'expected' => false - ], - ]; + $testCases = [ + 'Empty allowed hosts should return true' => [ + 'allowedHosts' => [], + 'httpHost' => 'anyhost.com', + 'expected' => true + ], + 'Exact matching host should return true' => [ + 'allowedHosts' => ['example.com', 'testsite.org'], + 'httpHost' => 'example.com', + 'expected' => true + ], + 'Subdomain matching allowed host should return true' => [ + 'allowedHosts' => ['example.com'], + 'httpHost' => 'subdomain.example.com', + 'expected' => true + ], + 'Unrelated host should return false' => [ + 'allowedHosts' => ['example.com'], + 'httpHost' => 'unrelated.com', + 'expected' => false + ], + 'Similar but incorrect subdomain pattern should return false' => [ + 'allowedHosts' => ['example.com'], + 'httpHost' => 'subdomain-example.com', + 'expected' => false + ], + ]; - foreach ($testCases as $scenario => $testCase) - { - $result = $method->invoke($this->e107, $testCase['allowedHosts'], $testCase['httpHost']); - $this::assertSame($testCase['expected'], $result, "Failed scenario: {$scenario}"); - } - } + foreach($testCases as $scenario => $testCase) + { + $result = $method->invoke($this->e107, $testCase['allowedHosts'], $testCase['httpHost']); + $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 = <<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 = << '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 = << '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 = << '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 = << '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 = << '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 = << '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 = << '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 = << '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 = <<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 -------- + }