CakeContactUs/tests/bootstrap.php

163 lines
4.6 KiB
PHP
Raw Permalink Normal View History

2025-01-10 07:47:18 +00:00
<?php
declare(strict_types=1);
2025-11-11 06:26:52 +00:00
use Cake\Cache\Cache;
use Cake\Chronos\Chronos;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Database\Connection;
use Cake\Datasource\ConnectionManager;
2025-11-11 07:51:18 +00:00
use Cake\Mailer\Mailer;
use Cake\Mailer\Transport\DebugTransport;
use Cake\Mailer\TransportFactory;
2025-11-11 06:26:52 +00:00
use Cake\TestSuite\Fixture\SchemaLoader;
use CakeContactUs\CakeContactUsPlugin;
use Migrations\TestSuite\Migrator;
use TestApp\Controller\AppController;
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);
}
}
2025-01-10 07:47:18 +00:00
2025-11-11 06:26:52 +00:00
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);
2025-01-10 07:47:18 +00:00
2025-11-11 06:26:52 +00:00
define('WWW_ROOT', PLUGIN_ROOT . DS . 'webroot' . DS);
define('TESTS', __DIR__ . DS);
define('CONFIG', TESTS . 'config' . DS);
2025-01-10 07:47:18 +00:00
2025-11-11 06:26:52 +00:00
ini_set('intl.default_locale', 'de-DE');
2025-01-10 07:47:18 +00:00
2025-11-11 06:26:52 +00:00
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,
],
],
]);
2025-01-10 07:47:18 +00:00
2025-11-11 06:26:52 +00:00
Configure::write('debug', true);
Configure::write('ContactUs', [
'fields' => [
'captcha' => false,
2025-11-11 10:22:01 +00:00
'email' => true,
],
'email' => [
'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions',
'confirmation' => false, // true or false
'backend' => [ // array with enabled and the to/cc/bcc/ fields as strings or arrays
'enabled' => false,
'to' => 'test@example.com',
2025-11-11 06:26:52 +00:00
],
],
]);
2025-11-11 07:51:18 +00:00
Configure::write('EmailTransport', [
'default' => [
'className' => DebugTransport::class,
]
]);
TransportFactory::setConfig('default', [
'className' => DebugTransport::class,
]);
Configure::write('Email', [
/*
* Email delivery profiles
*
* Delivery profiles allow you to predefine various properties about email
* messages from your application and give the settings a name. This saves
* duplication across your application and makes maintenance and development
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
* for more information.
*/
'default' => [
'transport' => 'default',
'from' => 'test@example.com',
/*
* Will by default be set to config value of App.encoding, if that exists otherwise to UTF-8.
*/
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
]);
2025-11-11 06:26:52 +00:00
$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);
2025-11-11 07:51:18 +00:00
Mailer::setConfig(Configure::consume('Email'));
2025-11-11 06:26:52 +00:00
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:');
2025-01-10 07:47:18 +00:00
}
2025-11-11 06:26:52 +00:00
ConnectionManager::setConfig('test', [
'className' => Connection::class,
'url' => getenv('DB_URL') ?: null,
'timezone' => 'UTC',
'quoteIdentifiers' => false,
'cacheMetadata' => true,
]);
2025-01-10 07:47:18 +00:00
/**
* Load schema from a SQL dump file.
*
* If your plugin does not use database fixtures you can
* safely delete this.
*
* If you want to support multiple databases, consider
* using migrations to provide schema for your plugin,
* and using \Migrations\TestSuite\Migrator to load schema.
*/
// Load a schema dump file.
2025-11-11 06:26:52 +00:00
//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
$migrator = new Migrator();
$migrator->run(['plugin' => 'CakeContactUs']);