1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-22 06:03:27 +02:00

Preparation for merge with e107 repository

Moved all test files to e107_tests subdirectory
This commit is contained in:
Deltik
2019-11-27 11:18:53 -06:00
parent a07bc04280
commit e49ee50d31
206 changed files with 5 additions and 10 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends E107Base
{
protected $deployer_components = ['db', 'fs'];
protected function writeLocalE107Config()
{
// Noop
// Acceptance tests will install the app themselves
}
public function unlinkE107ConfigFromTestEnvironment()
{
$this->deployer->unlinkAppFile("e107_config.php");
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Helper;
include_once(codecept_root_dir() . "lib/deployers/DeployerFactory.php");
// here you can define custom actions
// all public methods declared in helper class will be available in $I
abstract class Base extends \Codeception\Module
{
protected $deployer;
protected $deployer_components = ['db', 'fs'];
public function getDbModule()
{
return $this->getModule('\Helper\DelayedDb');
}
public function getBrowserModule()
{
return $this->getModule('PhpBrowser');
}
public function _beforeSuite($settings = array())
{
$this->deployer = \DeployerFactory::create();
$this->deployer->setComponents($this->deployer_components);
$this->deployer->start();
$this->_callbackDeployerStarted();
foreach ($this->getModules() as $module)
{
if (!$module instanceof $this)
{
$module->_beforeSuite();
}
}
}
public function _afterSuite()
{
$this->deployer->stop();
}
protected function _callbackDeployerStarted()
{
foreach ($this->deployer_components as $component)
{
$method = "reconfigure_${component}";
if (method_exists($this->deployer, $method))
{
$this->deployer->$method($this);
}
}
}
public function _before(\Codeception\TestCase $test = null)
{
$this->_callbackDeployerStarted();
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class DelayedDb extends \Codeception\Module\Db
{
protected $requiredFields = [];
public function _initialize()
{
// Noop
}
public function _delayedInitialize()
{
return parent::_initialize();
}
public function _getDbHostname()
{
$matches = [];
$matched = preg_match('~host=([^;]+)~s', $this->config['dsn'], $matches);
if (!$matched)
{
return false;
}
return $matches[1];
}
public function _getDbName()
{
$matches = [];
$matched = preg_match('~dbname=([^;]+)~s', $this->config['dsn'], $matches);
if (!$matched)
{
return false;
}
return $matches[1];
}
public function _getDbUsername()
{
return $this->config['user'];
}
public function _getDbPassword()
{
return $this->config['password'];
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Helper;
include_once(codecept_root_dir() . "lib/preparers/PreparerFactory.php");
// here you can define custom actions
// all public methods declared in helper class will be available in $I
use Codeception\Lib\ModuleContainer;
use PreparerFactory;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
abstract class E107Base extends Base
{
const APP_PATH_E107_CONFIG = APP_PATH."/e107_config.php";
const E107_MYSQL_PREFIX = 'e107_';
protected $preparer = null;
public function __construct(ModuleContainer $moduleContainer, $config = null)
{
parent::__construct($moduleContainer, $config);
$this->preparer = PreparerFactory::create();
}
public function _beforeSuite($settings = array())
{
$this->backupLocalE107Config();
$this->preparer->snapshot();
parent::_beforeSuite($settings);
$this->writeLocalE107Config();
}
protected function backupLocalE107Config()
{
if(file_exists(self::APP_PATH_E107_CONFIG))
{
rename(self::APP_PATH_E107_CONFIG, APP_PATH.'/e107_config.php.bak');
}
}
protected function writeLocalE107Config()
{
$twig_loader = new ArrayLoader([
'e107_config.php' => file_get_contents(codecept_data_dir()."/e107_config.php.sample")
]);
$twig = new Environment($twig_loader);
$db = $this->getModule('\Helper\DelayedDb');
$e107_config = [];
$e107_config['mySQLserver'] = $db->_getDbHostname();
$e107_config['mySQLuser'] = $db->_getDbUsername();
$e107_config['mySQLpassword'] = $db->_getDbPassword();
$e107_config['mySQLdefaultdb'] = $db->_getDbName();
$e107_config['mySQLprefix'] = self::E107_MYSQL_PREFIX;
$e107_config_contents = $twig->render('e107_config.php', $e107_config);
file_put_contents(self::APP_PATH_E107_CONFIG, $e107_config_contents);
}
public function _afterSuite()
{
parent::_afterSuite();
$this->revokeLocalE107Config();
$this->preparer->rollback();
$this->restoreLocalE107Config();
}
protected function revokeLocalE107Config()
{
if (file_exists(self::APP_PATH_E107_CONFIG))
unlink(self::APP_PATH_E107_CONFIG);
}
protected function restoreLocalE107Config()
{
if(file_exists(APP_PATH."/e107_config.php.bak"))
{
rename(APP_PATH.'/e107_config.php.bak', self::APP_PATH_E107_CONFIG);
}
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends E107Base
{
protected $deployer_components = ['db'];
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends E107Base
{
protected $deployer_components = ['db'];
public function _beforeSuite($settings = array())
{
parent::_beforeSuite($settings);
global $_E107;
$_E107 = array();
$_E107['cli'] = true;
$_E107['phpunit'] = true;
#$_E107['debug'] = true;
codecept_debug("Loading ".APP_PATH."/class2.php…");
define('E107_DBG_BASIC', true);
require_once(APP_PATH."/class2.php");
$create_dir = array(e_MEDIA,e_MEDIA_IMAGE,e_MEDIA_ICON,e_SYSTEM,e_CACHE,e_CACHE_CONTENT,e_CACHE_IMAGE, e_CACHE_DB, e_LOG, e_BACKUP, e_CACHE_URL, e_TEMP, e_IMPORT);
foreach($create_dir as $dr)
{
if(!is_dir($dr))
{
if(mkdir($dr, 0755))
{
// echo "\n(Creating ".$dr.")";
}
}
}
}
}