tests
This commit is contained in:
@@ -1,43 +1,112 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Test suite bootstrap for CakeContactUs.
|
||||
*
|
||||
* This function is used to find the location of CakePHP whether CakePHP
|
||||
* has been installed as a dependency of the plugin, or the plugin is itself
|
||||
* installed as a dependency of an application.
|
||||
*/
|
||||
$findRoot = function ($root) {
|
||||
do {
|
||||
$lastRoot = $root;
|
||||
$root = dirname($root);
|
||||
if (is_dir($root . '/vendor/cakephp/cakephp')) {
|
||||
return $root;
|
||||
}
|
||||
} while ($root !== $lastRoot);
|
||||
use Cake\Cache\Cache;
|
||||
use Cake\Chronos\Chronos;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Core\Plugin;
|
||||
use Cake\Database\Connection;
|
||||
use Cake\Datasource\ConnectionManager;
|
||||
use Cake\TestSuite\Fixture\SchemaLoader;
|
||||
use CakeContactUs\CakeContactUsPlugin;
|
||||
use Migrations\TestSuite\Migrator;
|
||||
use TestApp\Controller\AppController;
|
||||
|
||||
throw new Exception('Cannot find the root of the application, unable to run tests');
|
||||
};
|
||||
$root = $findRoot(__FILE__);
|
||||
unset($findRoot);
|
||||
|
||||
chdir($root);
|
||||
|
||||
require_once $root . '/vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* Define fallback values for required constants and configuration.
|
||||
* To customize constants and configuration remove this require
|
||||
* and define the data required by your plugin here.
|
||||
*/
|
||||
require_once $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';
|
||||
|
||||
if (file_exists($root . '/config/bootstrap.php')) {
|
||||
require $root . '/config/bootstrap.php';
|
||||
|
||||
return;
|
||||
if (!defined('DS')) {
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('WINDOWS')) {
|
||||
if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
|
||||
define('WINDOWS', true);
|
||||
} else {
|
||||
define('WINDOWS', false);
|
||||
}
|
||||
}
|
||||
|
||||
define('PLUGIN_ROOT', dirname(__DIR__));
|
||||
define('ROOT', PLUGIN_ROOT . DS . 'tests' . DS . 'test_app');
|
||||
define('TMP', PLUGIN_ROOT . DS . 'tmp' . DS);
|
||||
define('LOGS', TMP . 'logs' . DS);
|
||||
define('CACHE', TMP . 'cache' . DS);
|
||||
define('APP', ROOT . DS . 'src' . DS);
|
||||
define('APP_DIR', 'src');
|
||||
define('CAKE_CORE_INCLUDE_PATH', PLUGIN_ROOT . '/vendor/cakephp/cakephp');
|
||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||
define('CAKE', CORE_PATH . APP_DIR . DS);
|
||||
|
||||
define('WWW_ROOT', PLUGIN_ROOT . DS . 'webroot' . DS);
|
||||
define('TESTS', __DIR__ . DS);
|
||||
define('CONFIG', TESTS . 'config' . DS);
|
||||
|
||||
ini_set('intl.default_locale', 'de-DE');
|
||||
|
||||
require PLUGIN_ROOT . '/vendor/autoload.php';
|
||||
require CORE_PATH . 'config/bootstrap.php';
|
||||
require CAKE . 'functions.php';
|
||||
|
||||
Configure::write('App', [
|
||||
'namespace' => 'TestApp',
|
||||
'encoding' => 'UTF-8',
|
||||
'paths' => [
|
||||
'testWebroot' => PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS,
|
||||
'webroot' => PLUGIN_ROOT . DS . 'webroot' . DS,
|
||||
'templates' => [
|
||||
PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'templates' . DS,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
Configure::write('debug', true);
|
||||
Configure::write('ContactUs', [
|
||||
'fields' => [
|
||||
'captcha' => false,
|
||||
'email' => [
|
||||
'confirmation' => false,
|
||||
'backend' => false,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$cache = [
|
||||
'default' => [
|
||||
'engine' => 'File',
|
||||
'path' => CACHE,
|
||||
],
|
||||
'_cake_translations_' => [
|
||||
'className' => 'File',
|
||||
'prefix' => 'crud_myapp_cake_core_',
|
||||
'path' => CACHE . 'persistent/',
|
||||
'serialize' => true,
|
||||
'duration' => '+10 seconds',
|
||||
],
|
||||
'_cake_model_' => [
|
||||
'className' => 'File',
|
||||
'prefix' => 'crud_my_app_cake_model_',
|
||||
'path' => CACHE . 'models/',
|
||||
'serialize' => 'File',
|
||||
'duration' => '+10 seconds',
|
||||
],
|
||||
];
|
||||
|
||||
Cache::setConfig($cache);
|
||||
|
||||
class_alias(AppController::class, 'App\Controller\AppController');
|
||||
|
||||
Plugin::getCollection()->add(new CakeContactUsPlugin());
|
||||
|
||||
Chronos::setTestNow(Chronos::now());
|
||||
|
||||
if (!getenv('DB_URL')) {
|
||||
putenv('DB_URL=sqlite:///:memory:');
|
||||
}
|
||||
|
||||
ConnectionManager::setConfig('test', [
|
||||
'className' => Connection::class,
|
||||
'url' => getenv('DB_URL') ?: null,
|
||||
'timezone' => 'UTC',
|
||||
'quoteIdentifiers' => false,
|
||||
'cacheMetadata' => true,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Load schema from a SQL dump file.
|
||||
@@ -49,7 +118,9 @@ if (file_exists($root . '/config/bootstrap.php')) {
|
||||
* using migrations to provide schema for your plugin,
|
||||
* and using \Migrations\TestSuite\Migrator to load schema.
|
||||
*/
|
||||
use Cake\TestSuite\Fixture\SchemaLoader;
|
||||
|
||||
// Load a schema dump file.
|
||||
(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
|
||||
//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
|
||||
|
||||
|
||||
$migrator = new Migrator();
|
||||
$migrator->run(['plugin' => 'CakeContactUs']);
|
||||
|
||||
Reference in New Issue
Block a user