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

Issue #5444 - Support for plugin tests.

This commit is contained in:
camer0n
2025-03-16 13:49:46 -07:00
parent 52041d406f
commit d7c69a8d81
4 changed files with 348 additions and 234 deletions

View File

@@ -1,6 +1,6 @@
<?php
namespace Tests\Unit\_blank;
namespace E107\Plugins\_blank\Tests\Unit;
use Codeception\Test\Unit;
/* To use, run these commands from the root directory of e107 in CLI:

View File

@@ -3,16 +3,16 @@
"description": "Test harness for e107",
"license": "GPL-3.0-or-later",
"require": {
"php": "^8.1 || ^8.2 || ^8.3 || ^8.4"
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4"
},
"require-dev": {
"twig/twig": "^3.12",
"codeception/codeception": "^5.2.1",
"codeception/module-asserts": "^3.0",
"codeception/module-db": "^3.1",
"codeception/module-phpbrowser": "^3.0",
"codeception/module-filesystem": "^3.0",
"codeception/module-webdriver": "^4.0"
"twig/twig": "^3.0",
"codeception/codeception": "^5.0.11 || ^4.2.2",
"codeception/module-asserts": "^3.0 || ^1.3",
"codeception/module-db": "^3.1 || ^1.2",
"codeception/module-phpbrowser": "^3.0 || ^1.1",
"codeception/module-filesystem": "^3.0 || ^1.1",
"codeception/module-webdriver": "^4.0 || ^1.4"
},
"config": {
"optimize-autoloader": true,
@@ -22,8 +22,7 @@
"autoload-dev": {
"psr-4": {
"Helper\\": "tests/_support/Helper/",
"Tests\\Unit\\": "tests/unit/",
"Tests\\": "../e107_plugins/"
"Tests\\Unit\\": "tests/unit/"
}
}
}

532
e107_tests/composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
use Codeception\Util\Autoload;
use Codeception\Configuration;
class E107TestSuiteBootstrap
{
const ENABLE_LOGGING = false; // Toggle logging (set to true to enable)
@@ -37,14 +38,12 @@ class E107TestSuiteBootstrap
$this->log("Root Dir: " . codecept_root_dir());
// Load core unit tests namespace (e107_tests/tests/unit/)
Autoload::addNamespace('Tests\Unit', codecept_root_dir() . '/tests/unit');
$this->log("Added core unit namespace: Tests\\Unit => " . codecept_root_dir() . '/tests/unit');
Autoload::addNamespace('', codecept_root_dir() . '/tests/unit');
$this->log("Added core unit namespace: '' => " . 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) !== '/')
{
@@ -53,10 +52,9 @@ class E107TestSuiteBootstrap
define('APP_PATH', realpath($app_path));
define('PARAMS_SERIALIZED', serialize($params));
// Log App Path after definition
$this->log("App Path: " . APP_PATH);
// e_PLUGIN status
if (defined('e_PLUGIN'))
{
$this->log("e_PLUGIN already defined as: " . e_PLUGIN);
@@ -66,7 +64,6 @@ class E107TestSuiteBootstrap
$this->log("e_PLUGIN not defined yet");
}
// Set plugins directory once
$this->pluginsDir = realpath(codecept_root_dir() . '/../e107_plugins/');
$this->log("Plugins Dir: $this->pluginsDir");
@@ -74,7 +71,6 @@ class E107TestSuiteBootstrap
$this->loadUnitTests();
$this->loadAcceptanceTests();
// Include required e107 file
include(codecept_root_dir() . "/lib/PriorityCallbacks.php");
$this->log("e_PLUGIN after initialization: " . (defined('e_PLUGIN') ? e_PLUGIN : 'not defined'));
@@ -87,7 +83,7 @@ class E107TestSuiteBootstrap
if ($this->pluginsDir && is_dir($this->pluginsDir))
{
$unitDirs = glob($this->pluginsDir . '/*/tests/unit', GLOB_ONLYDIR);
$separator = DIRECTORY_SEPARATOR; // \ on Windows, / on Linux
$separator = DIRECTORY_SEPARATOR;
$unitGlobPattern = str_replace('/', $separator, $this->pluginsDir . '/*/tests/unit');
$this->log("Unit Glob Pattern: $unitGlobPattern");
$this->log("Found Unit Dirs: " . (empty($unitDirs) ? 'None' : ''));
@@ -100,11 +96,12 @@ class E107TestSuiteBootstrap
}
foreach ($unitDirs as $testDir)
{
$pluginName = basename(dirname($testDir, 2)); // Two levels up from /unit
$pluginName = basename(dirname($testDir, 2));
$relativePath = '../e107_plugins/' . $pluginName . '/tests/unit';
$pluginUnitDirs[] = $relativePath;
Autoload::addNamespace("Tests\\Unit\\" . ucfirst($pluginName), $testDir);
$this->log("Added unit namespace: Tests\\Unit\\" . ucfirst($pluginName) . " => $testDir");
$namespace = "E107\\Plugins\\" . ucfirst($pluginName) . "\\Tests\\Unit";
Autoload::addNamespace($namespace, $testDir);
$this->log("Added unit namespace: $namespace => $testDir");
}
}
else
@@ -121,7 +118,7 @@ class E107TestSuiteBootstrap
if ($this->pluginsDir && is_dir($this->pluginsDir))
{
$acceptanceDirs = glob($this->pluginsDir . '/*/tests/acceptance', GLOB_ONLYDIR);
$separator = DIRECTORY_SEPARATOR; // \ on Windows, / on Linux
$separator = DIRECTORY_SEPARATOR;
$acceptanceGlobPattern = str_replace('/', $separator, $this->pluginsDir . '/*/tests/acceptance');
$this->log("Acceptance Glob Pattern: $acceptanceGlobPattern");
$this->log("Found Acceptance Dirs: " . (empty($acceptanceDirs) ? 'None' : ''));
@@ -137,8 +134,9 @@ class E107TestSuiteBootstrap
$pluginName = basename(dirname($testDir, 2));
$relativePath = '../e107_plugins/' . $pluginName . '/tests/acceptance';
$pluginAcceptanceDirs[] = $relativePath;
Autoload::addNamespace("Tests\\Acceptance\\" . ucfirst($pluginName), $testDir);
$this->log("Added acceptance namespace: Tests\\Acceptance\\" . ucfirst($pluginName) . " => $testDir");
$namespace = "E107\\Plugins\\" . ucfirst($pluginName) . "\\Tests\\Acceptance";
Autoload::addNamespace($namespace, $testDir);
$this->log("Added acceptance namespace: $namespace => $testDir");
}
}
else
@@ -149,5 +147,4 @@ class E107TestSuiteBootstrap
}
}
new E107TestSuiteBootstrap;