1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-25 00:41:52 +02:00

Issue #5444 Initial working dynamic plugin test detection.

This commit is contained in:
camer0n
2025-03-16 11:43:30 -07:00
parent baca43b023
commit ffec694673
3 changed files with 99 additions and 51 deletions

View File

@@ -1,57 +1,66 @@
<?php
use Codeception\Util\Autoload;
use Codeception\Configuration;
// Load unit tests namespace
Autoload::addNamespace('', codecept_root_dir() . '/tests/unit');
// Load parameters
define('PARAMS_GENERATOR', realpath(codecept_root_dir() . "/lib/config.php"));
$params = include(PARAMS_GENERATOR);
// Define APP_PATH
$app_path = $params['app_path'] ?: codecept_root_dir() . "/e107";
if(substr($app_path, 0, 1) !== '/')
{
$app_path = codecept_root_dir() . "/{$app_path}";
if (substr($app_path, 0, 1) !== '/') {
$app_path = codecept_root_dir() . "/{$app_path}";
}
define('APP_PATH', realpath($app_path));
define('PARAMS_SERIALIZED', serialize($params));
// define('e_PLUGIN', APP_PATH . '/e107_plugins/');
$pluginsDir = realpath(codecept_root_dir() . '/../e107_plugins/');
$pluginTestDirs = [];
// Debug logging
$logFile = codecept_output_dir() . '/bootstrap.log';
file_put_contents($logFile, '');
file_put_contents($logFile, "Time: " . date(DATE_ATOM) . "\n", FILE_APPEND);
file_put_contents($logFile, "Root Dir: " . codecept_root_dir() . "\n", FILE_APPEND);
file_put_contents($logFile, "App Path: " . APP_PATH . "\n", FILE_APPEND);
if (defined('e_PLUGIN')) {
file_put_contents($logFile, "e_PLUGIN already defined as: " . e_PLUGIN . "\n", FILE_APPEND);
} else {
file_put_contents($logFile, "e_PLUGIN not defined yet\n", FILE_APPEND);
// Let e107 define e_PLUGIN later; avoid redefinition
// define('e_PLUGIN', APP_PATH . '/e107_plugins/');
}
// Dynamic plugin test autoloading
$pluginsDir = realpath(codecept_root_dir() . '/../e107_plugins/');
$pluginTestDirs = [];
file_put_contents($logFile, "Plugins Dir: $pluginsDir\n", FILE_APPEND);
if($pluginsDir && is_dir($pluginsDir))
{
$dirs = glob($pluginsDir . '/*/tests', GLOB_ONLYDIR);
file_put_contents($logFile, "Glob Pattern: $pluginsDir/*/tests\n", FILE_APPEND);
file_put_contents($logFile, "Found Dirs: " . (empty($dirs) ? 'None' : implode(', ', $dirs)) . "\n", FILE_APPEND);
foreach($dirs as $testDir)
{
$pluginName = basename(dirname($testDir));
$relativePath = '../e107_plugins/' . $pluginName . '/tests';
$pluginTestDirs[] = $relativePath; // Just paths, no array
}
}
else
{
file_put_contents($logFile, "Plugins Dir not found or not a directory\n", FILE_APPEND);
if ($pluginsDir && is_dir($pluginsDir)) {
$dirs = glob($pluginsDir . '/*/tests', GLOB_ONLYDIR);
file_put_contents($logFile, "Glob Pattern: $pluginsDir/*/tests\n", FILE_APPEND);
file_put_contents($logFile, "Found Dirs: " . (empty($dirs) ? 'None' : implode(', ', $dirs)) . "\n", FILE_APPEND);
foreach ($dirs as $testDir) {
$pluginName = basename(dirname($testDir));
$relativePath = '../e107_plugins/' . $pluginName . '/tests';
$pluginTestDirs[] = $relativePath;
Autoload::addNamespace("Tests\\" . ucfirst($pluginName), $testDir);
file_put_contents($logFile, "Added namespace: Tests\\" . ucfirst($pluginName) . " => $testDir\n", FILE_APPEND);
}
} else {
file_put_contents($logFile, "Plugins Dir not found or not a directory\n", FILE_APPEND);
}
file_put_contents($logFile, "Included: " . json_encode($pluginTestDirs, JSON_PRETTY_PRINT) . "\n", FILE_APPEND);
file_put_contents($logFile, "e_PLUGIN after scan: " . (defined('e_PLUGIN') ? e_PLUGIN : 'not defined') . "\n", FILE_APPEND);
if(!empty($pluginTestDirs))
{
Configuration::append(['include' => $pluginTestDirs]);
codecept_debug("Dynamic includes added: " . json_encode($pluginTestDirs));
}
else
{
codecept_debug("No plugin test directories found");
}
// Skip Configuration::append to avoid config errors
// if (!empty($pluginTestDirs)) {
// Configuration::append(['include' => $pluginTestDirs]);
// codecept_debug("Dynamic includes added: " . json_encode($pluginTestDirs));
// } else {
// codecept_debug("No plugin test directories found");
// }
// Include required e107 file
include(codecept_root_dir() . "/lib/PriorityCallbacks.php");

View File

@@ -3,7 +3,6 @@
# Suite for unit or integration tests.
actor: UnitTester
shuffle: true
modules:
enabled:
- Asserts

View File

@@ -823,13 +823,34 @@ EOF;
}
public function testPrepareResults()
private function prepareResults(string $file, string $sql)
{
$fileData = array();
$sqlData = array();
$fileData['field'] = $this->dbv->getFields($file);
$sqlData['field'] = $this->dbv->getFields($sql);
$fileData['index'] = $this->dbv->getIndex($file);
$sqlData['index'] = $this->dbv->getIndex($sql);
$fileData['engine'] = $this->dbv->getIntendedStorageEngine("InnoDB");
$sqlData['engine'] = $this->dbv->getCanonicalStorageEngine("InnoDB");
$fileData['charset'] = $this->dbv->getIntendedCharset("utf8mb4");
$sqlData['charset'] = $this->dbv->getCanonicalCharset("utf8mb4");
return ['fileData' => $fileData, 'sqlData' => $sqlData];
}
public function testPrepareResults()
{
$sql = "`schedule_id` int(10) unsigned NOT NULL auto_increment,
`schedule_user_id` int(11) NOT NULL,
`schedule_invoice_id` int(11) NOT NULL,
@@ -853,20 +874,9 @@ EOF;
KEY `schedule_invoice_id` (`schedule_invoice_id`)
";
$result = $this->prepareResults($file,$sql);
$fileData['field'] = $this->dbv->getFields($file);
$sqlData['field'] = $this->dbv->getFields($sql);
$fileData['index'] = $this->dbv->getIndex($file);
$sqlData['index'] = $this->dbv->getIndex($sql);
$fileData['engine'] = $this->dbv->getIntendedStorageEngine("InnoDB");
$sqlData['engine'] = $this->dbv->getCanonicalStorageEngine("InnoDB");
$fileData['charset'] = $this->dbv->getIntendedCharset("utf8mb4");
$sqlData['charset'] = $this->dbv->getCanonicalCharset("utf8mb4");
$this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData);
$this->dbv->prepareResults('schedule', 'myplugin', $result['sqlData'], $result['fileData']);
$resultFields = $this->dbv->getResults();
$expected = array(
@@ -987,10 +997,10 @@ EOF;
self::assertEquals($expected, $resultIndices);
$fileData['charset'] = "utf8mb4";
$sqlData['charset'] = "utf8";
$result['fileData']['charset'] = "utf8mb4";
$result['sqlData']['charset'] = "utf8";
$result = $this->dbv->prepareResults('schedule', 'myplugin', $sqlData, $fileData);
$result = $this->dbv->prepareResults('schedule', 'myplugin', $result['sqlData'], $result['fileData']);
$resultFields = $this->dbv->getErrors();
$expected = array (
'schedule' =>
@@ -1004,6 +1014,36 @@ EOF;
self::assertSame($expected, $resultFields);
self::assertSame(1, $this->dbv->errors());
}
public function testSyntaxCheck()
{
$file = "`affiliate_id` int(10) unsigned NOT NULL auto_increment,
`affiliate_code` varchar(10) NOT NULL DEFAULT '',
`affiliate_name` varchar(30) NOT NULL DEFAULT '',
'affiliate_email` varchar(50) NOT NULL DEFAULT '',
'affiliate_phone` varchar(16) NOT NULL DEFAULT '',
`affiliate_sef` varchar(30) NOT NULL DEFAULT '',
`affiliate_schema` varchar(30) NOT NULL DEFAULT '',
`affiliate_cust_id` int(11) NOT NULL,
`affiliate_user_id` int(11) NOT NULL,
`affiliate_date` int(11) NOT NULL,
`affiliate_discount` DECIMAL(6,2) NOT NULL DEFAULT '0.00',
`affiliate_expires` int(11) NOT NULL,
`affiliate_earned` int(6) NOT NULL,
`affiliate_spent` int(6) NOT NULL,
`affiliate_balance` int(6) NOT NULL,
`affiliate_history` text,
`affiliate_assignee` INT(3) NOT NULL DEFAULT 0,
PRIMARY KEY (`affiliate_id`),
UNIQUE KEY `affiliate_code` (`affiliate_code`)";
$result = $this->dbv->hasSyntaxIssue($file);
var_export($result);
}