From edcdbee523ae69d1e0ae2fb9bdd1fe81eb0d05de Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 25 Apr 2022 09:52:13 +0900 Subject: [PATCH] phpunit tests update for acl login, db io, fix smarty extended class --- 4dev/tests/CoreLibsACLLoginTest.php | 61 ++++++++++++++++++++-- 4dev/tests/CoreLibsDBIOTest.php | 2 +- 4dev/tests/phpunit_flow_check.php | 58 -------------------- www/lib/CoreLibs/Template/SmartyExtend.php | 10 +++- 4 files changed, 67 insertions(+), 64 deletions(-) delete mode 100644 4dev/tests/phpunit_flow_check.php diff --git a/4dev/tests/CoreLibsACLLoginTest.php b/4dev/tests/CoreLibsACLLoginTest.php index fe967e53..5fc53bc4 100644 --- a/4dev/tests/CoreLibsACLLoginTest.php +++ b/4dev/tests/CoreLibsACLLoginTest.php @@ -13,18 +13,73 @@ use PHPUnit\Framework\TestCase; */ final class CoreLibsACLLoginTest extends TestCase { + private static $db; + private static $log; + /** - * Undocumented function + * start DB conneciton, setup DB, etc * * @return void */ - protected function setUp(): void + public static function setUpBeforeClass(): void { if (!extension_loaded('pgsql')) { - $this->markTestSkipped( + self::markTestSkipped( 'The PgSQL extension is not available.' ); } + // logger is always needed + // define basic connection set valid and one invalid + self::$log = new \CoreLibs\Debug\Logging([ + // 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log', + 'log_folder' => DIRECTORY_SEPARATOR . 'tmp', + 'file_id' => 'CoreLibs-ACL-Login-Test', + 'debug_all' => false, + 'echo_all' => false, + 'print_all' => false, + ]); + // if we do have pgsql, we need to create a test DB or check that one + // exists and clean the table to zero state + self::$db = new \CoreLibs\DB\IO( + [ + 'db_name' => 'corelibs_acl_login_test', + 'db_user' => 'corelibs_acl_login_test', + 'db_pass' => 'corelibs_acl_login_test', + 'db_host' => 'localhost', + 'db_port' => 5432, + 'db_schema' => 'public', + 'db_type' => 'pgsql', + 'db_encoding' => '', + 'db_ssl' => 'allow', // allow, disable, require, prefer + 'db_debug' => true, + ], + self::$log + ); + if (!self::$db->dbGetConnectionStatus()) { + self::markTestSkipped( + 'Cannot connect to valid Test DB for ACL\Login test.' + ); + } + /* + // check if they already exist, drop them + if ($db->dbShowTableMetaData('table_with_primary_key') !== false) { + $db->dbExec("DROP TABLE table_with_primary_key"); + $db->dbExec("DROP TABLE table_without_primary_key"); + $db->dbExec("DROP TABLE test_meta"); + } + */ + } + + /** + * close db + * + * @return void + */ + public static function tearDownAfterClass(): void + { + if (self::$db->dbGetConnectionStatus()) { + self::$db->dbClose(); + } } /** diff --git a/4dev/tests/CoreLibsDBIOTest.php b/4dev/tests/CoreLibsDBIOTest.php index cf80906d..5a1c4676 100644 --- a/4dev/tests/CoreLibsDBIOTest.php +++ b/4dev/tests/CoreLibsDBIOTest.php @@ -145,7 +145,7 @@ final class CoreLibsDBIOTest extends TestCase ); if (!$db->dbGetConnectionStatus()) { self::markTestSkipped( - 'Cannot connect to valid Test DB.' + 'Cannot connect to valid Test DB for DB\IO test.' ); } // check if they already exist, drop them diff --git a/4dev/tests/phpunit_flow_check.php b/4dev/tests/phpunit_flow_check.php deleted file mode 100644 index bbe2d5da..00000000 --- a/4dev/tests/phpunit_flow_check.php +++ /dev/null @@ -1,58 +0,0 @@ -assertTrue(true); - } - - public function testTwo(): void - { - fwrite(STDOUT, __METHOD__ . "\n"); - $this->assertTrue(false); - } - - protected function assertPostConditions(): void - { - fwrite(STDOUT, __METHOD__ . "\n"); - } - - protected function tearDown(): void - { - fwrite(STDOUT, __METHOD__ . "\n"); - } - - public static function tearDownAfterClass(): void - { - fwrite(STDOUT, __METHOD__ . "\n"); - } - - protected function onNotSuccessfulTest(\Throwable $t): void - { - fwrite(STDOUT, __METHOD__ . "\n"); - throw $t; - } -} diff --git a/www/lib/CoreLibs/Template/SmartyExtend.php b/www/lib/CoreLibs/Template/SmartyExtend.php index af2de46f..475290e1 100644 --- a/www/lib/CoreLibs/Template/SmartyExtend.php +++ b/www/lib/CoreLibs/Template/SmartyExtend.php @@ -319,9 +319,15 @@ class SmartyExtend extends \Smarty // if .tpl, put before .tpl // if not .tpl, add _<$this->lang>.tpl if (strpos($this->TEMPLATE_TRANSLATE, '.tpl')) { - $this->TEMPLATE_TRANSLATE = str_replace('.tpl', '_' . $this->lang . '.tpl', $this->TEMPLATE_TRANSLATE); + $this->TEMPLATE_TRANSLATE = str_replace( + '.tpl', + '-' . $this->lang . '.' . $this->encoding . '.tpl', + $this->TEMPLATE_TRANSLATE + ); } else { - $this->TEMPLATE_TRANSLATE .= '_' . $this->lang . '.tpl'; + $this->TEMPLATE_TRANSLATE .= '_' + . $this->lang . '.' . $this->encoding + . '.tpl'; } } // if we can't find it, dump it