mirror of
https://github.com/e107inc/e107.git
synced 2025-07-28 18:30:53 +02:00
Issue #5444 Initial working dynamic plugin test detection.
This commit is contained in:
@@ -1,57 +1,66 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Codeception\Util\Autoload;
|
use Codeception\Util\Autoload;
|
||||||
use Codeception\Configuration;
|
use Codeception\Configuration;
|
||||||
|
|
||||||
|
// Load unit tests namespace
|
||||||
Autoload::addNamespace('', codecept_root_dir() . '/tests/unit');
|
Autoload::addNamespace('', codecept_root_dir() . '/tests/unit');
|
||||||
|
|
||||||
|
// Load parameters
|
||||||
define('PARAMS_GENERATOR', realpath(codecept_root_dir() . "/lib/config.php"));
|
define('PARAMS_GENERATOR', realpath(codecept_root_dir() . "/lib/config.php"));
|
||||||
$params = include(PARAMS_GENERATOR);
|
$params = include(PARAMS_GENERATOR);
|
||||||
|
|
||||||
|
// Define APP_PATH
|
||||||
$app_path = $params['app_path'] ?: codecept_root_dir() . "/e107";
|
$app_path = $params['app_path'] ?: codecept_root_dir() . "/e107";
|
||||||
if(substr($app_path, 0, 1) !== '/')
|
if (substr($app_path, 0, 1) !== '/') {
|
||||||
{
|
|
||||||
$app_path = codecept_root_dir() . "/{$app_path}";
|
$app_path = codecept_root_dir() . "/{$app_path}";
|
||||||
}
|
}
|
||||||
define('APP_PATH', realpath($app_path));
|
define('APP_PATH', realpath($app_path));
|
||||||
define('PARAMS_SERIALIZED', serialize($params));
|
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';
|
$logFile = codecept_output_dir() . '/bootstrap.log';
|
||||||
file_put_contents($logFile, '');
|
file_put_contents($logFile, '');
|
||||||
file_put_contents($logFile, "Time: " . date(DATE_ATOM) . "\n", FILE_APPEND);
|
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, "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);
|
file_put_contents($logFile, "Plugins Dir: $pluginsDir\n", FILE_APPEND);
|
||||||
|
|
||||||
if($pluginsDir && is_dir($pluginsDir))
|
if ($pluginsDir && is_dir($pluginsDir)) {
|
||||||
{
|
|
||||||
$dirs = glob($pluginsDir . '/*/tests', GLOB_ONLYDIR);
|
$dirs = glob($pluginsDir . '/*/tests', GLOB_ONLYDIR);
|
||||||
file_put_contents($logFile, "Glob Pattern: $pluginsDir/*/tests\n", FILE_APPEND);
|
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);
|
file_put_contents($logFile, "Found Dirs: " . (empty($dirs) ? 'None' : implode(', ', $dirs)) . "\n", FILE_APPEND);
|
||||||
foreach($dirs as $testDir)
|
foreach ($dirs as $testDir) {
|
||||||
{
|
|
||||||
$pluginName = basename(dirname($testDir));
|
$pluginName = basename(dirname($testDir));
|
||||||
$relativePath = '../e107_plugins/' . $pluginName . '/tests';
|
$relativePath = '../e107_plugins/' . $pluginName . '/tests';
|
||||||
$pluginTestDirs[] = $relativePath; // Just paths, no array
|
$pluginTestDirs[] = $relativePath;
|
||||||
|
Autoload::addNamespace("Tests\\" . ucfirst($pluginName), $testDir);
|
||||||
|
file_put_contents($logFile, "Added namespace: Tests\\" . ucfirst($pluginName) . " => $testDir\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
file_put_contents($logFile, "Plugins Dir not found or not a directory\n", FILE_APPEND);
|
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, "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))
|
// Skip Configuration::append to avoid config errors
|
||||||
{
|
// if (!empty($pluginTestDirs)) {
|
||||||
Configuration::append(['include' => $pluginTestDirs]);
|
// Configuration::append(['include' => $pluginTestDirs]);
|
||||||
codecept_debug("Dynamic includes added: " . json_encode($pluginTestDirs));
|
// codecept_debug("Dynamic includes added: " . json_encode($pluginTestDirs));
|
||||||
}
|
// } else {
|
||||||
else
|
// codecept_debug("No plugin test directories found");
|
||||||
{
|
// }
|
||||||
codecept_debug("No plugin test directories found");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Include required e107 file
|
||||||
include(codecept_root_dir() . "/lib/PriorityCallbacks.php");
|
include(codecept_root_dir() . "/lib/PriorityCallbacks.php");
|
@@ -3,7 +3,6 @@
|
|||||||
# Suite for unit or integration tests.
|
# Suite for unit or integration tests.
|
||||||
|
|
||||||
actor: UnitTester
|
actor: UnitTester
|
||||||
shuffle: true
|
|
||||||
modules:
|
modules:
|
||||||
enabled:
|
enabled:
|
||||||
- Asserts
|
- Asserts
|
||||||
|
@@ -823,13 +823,34 @@ EOF;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function prepareResults(string $file, string $sql)
|
||||||
public function testPrepareResults()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$fileData = array();
|
$fileData = array();
|
||||||
$sqlData = 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,
|
$sql = "`schedule_id` int(10) unsigned NOT NULL auto_increment,
|
||||||
`schedule_user_id` int(11) NOT NULL,
|
`schedule_user_id` int(11) NOT NULL,
|
||||||
`schedule_invoice_id` int(11) NOT NULL,
|
`schedule_invoice_id` int(11) NOT NULL,
|
||||||
@@ -853,20 +874,9 @@ EOF;
|
|||||||
KEY `schedule_invoice_id` (`schedule_invoice_id`)
|
KEY `schedule_invoice_id` (`schedule_invoice_id`)
|
||||||
";
|
";
|
||||||
|
|
||||||
|
$result = $this->prepareResults($file,$sql);
|
||||||
|
|
||||||
$fileData['field'] = $this->dbv->getFields($file);
|
$this->dbv->prepareResults('schedule', 'myplugin', $result['sqlData'], $result['fileData']);
|
||||||
$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);
|
|
||||||
|
|
||||||
$resultFields = $this->dbv->getResults();
|
$resultFields = $this->dbv->getResults();
|
||||||
$expected = array(
|
$expected = array(
|
||||||
@@ -987,10 +997,10 @@ EOF;
|
|||||||
|
|
||||||
self::assertEquals($expected, $resultIndices);
|
self::assertEquals($expected, $resultIndices);
|
||||||
|
|
||||||
$fileData['charset'] = "utf8mb4";
|
$result['fileData']['charset'] = "utf8mb4";
|
||||||
$sqlData['charset'] = "utf8";
|
$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();
|
$resultFields = $this->dbv->getErrors();
|
||||||
$expected = array (
|
$expected = array (
|
||||||
'schedule' =>
|
'schedule' =>
|
||||||
@@ -1004,6 +1014,36 @@ EOF;
|
|||||||
self::assertSame($expected, $resultFields);
|
self::assertSame($expected, $resultFields);
|
||||||
self::assertSame(1, $this->dbv->errors());
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user