tests wip
This commit is contained in:
parent
48df5db468
commit
5b241c4e37
|
|
@ -25,7 +25,7 @@ class CartsTableTest extends TestCase
|
||||||
*/
|
*/
|
||||||
protected array $fixtures = [
|
protected array $fixtures = [
|
||||||
'plugin.CakeCarts.Carts',
|
'plugin.CakeCarts.Carts',
|
||||||
'plugin.CakeCarts.Users',
|
// 'plugin.CakeCarts.Users',
|
||||||
'plugin.CakeCarts.CartItems',
|
'plugin.CakeCarts.CartItems',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
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 CakeProducts\CakeProductsPlugin;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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('CakeCarts', [
|
||||||
|
'Carts' => [
|
||||||
|
'table' => 'CakeCarts.Carts',
|
||||||
|
],
|
||||||
|
'CartItems' => [
|
||||||
|
'requirePricing' => false,
|
||||||
|
],
|
||||||
|
'Users' => [
|
||||||
|
'user_id' => 'uuid', // integer or uuid
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$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 \CakeCarts\CakeCartsPlugin());
|
||||||
|
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
|
||||||
|
|
||||||
|
|
||||||
|
$migrator = new Migrator();
|
||||||
|
$migrator->run(['plugin' => 'CakeCarts']);
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TestApp;
|
||||||
|
|
||||||
|
use Cake\Http\BaseApplication;
|
||||||
|
use Cake\Http\MiddlewareQueue;
|
||||||
|
use Cake\Routing\Middleware\RoutingMiddleware;
|
||||||
|
use Cake\Routing\Route\DashedRoute;
|
||||||
|
use Cake\Routing\RouteBuilder;
|
||||||
|
|
||||||
|
class Application extends BaseApplication {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function bootstrap(): void {
|
||||||
|
$this->addPlugin('CakeCarts');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue {
|
||||||
|
$middleware->add(new RoutingMiddleware($this));
|
||||||
|
|
||||||
|
return $middleware;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function routes(RouteBuilder $routes): void
|
||||||
|
{
|
||||||
|
parent::routes($routes); // TODO: Change the autogenerated stub
|
||||||
|
$routes->setRouteClass(DashedRoute::class);
|
||||||
|
|
||||||
|
$routes->plugin('CakeCarts', ['path' => '/cake-carts'], function (RouteBuilder $pluginRoutes):void {
|
||||||
|
$pluginRoutes->fallbacks();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TestApp\Controller;
|
||||||
|
|
||||||
|
use Cake\Controller\Controller;
|
||||||
|
|
||||||
|
class AppController extends Controller {
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function initialize(): void {
|
||||||
|
parent::initialize();
|
||||||
|
|
||||||
|
$this->loadComponent('Flash');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TestApp\View;
|
||||||
|
|
||||||
|
use Cake\View\View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property \TinyAuth\View\Helper\AuthUserHelper $AuthUser
|
||||||
|
*/
|
||||||
|
class AppView extends View {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Cake\Core\Configure;
|
||||||
|
use Cake\Error\Debugger;
|
||||||
|
|
||||||
|
$this->layout = 'error';
|
||||||
|
|
||||||
|
if (Configure::read('debug')):
|
||||||
|
$this->layout = 'dev_error';
|
||||||
|
|
||||||
|
$this->assign('title', $message);
|
||||||
|
$this->assign('templateName', 'error500.ctp');
|
||||||
|
|
||||||
|
$this->start('file');
|
||||||
|
?>
|
||||||
|
<?php if (!empty($error->queryString)) : ?>
|
||||||
|
<p class="notice">
|
||||||
|
<strong>SQL Query: </strong>
|
||||||
|
<?= h($error->queryString) ?>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if (!empty($error->params)) : ?>
|
||||||
|
<strong>SQL Query Params: </strong>
|
||||||
|
<?php Debugger::dump($error->params) ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error instanceof Error) : ?>
|
||||||
|
<strong>Error in: </strong>
|
||||||
|
<?= sprintf('%s, line %s', str_replace(ROOT, 'ROOT', $error->getFile()), $error->getLine()) ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php
|
||||||
|
echo $this->element('auto_table_warning');
|
||||||
|
|
||||||
|
if (extension_loaded('xdebug')):
|
||||||
|
xdebug_print_function_stack();
|
||||||
|
endif;
|
||||||
|
|
||||||
|
$this->end();
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
<h2><?= __d('cake', 'An Internal Error Has Occurred') ?></h2>
|
||||||
|
<p class="error">
|
||||||
|
<strong><?= __d('cake', 'Error') ?>: </strong>
|
||||||
|
<?= h($message) ?>
|
||||||
|
</p>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var \App\View\AppView $this
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<?= $this->fetch('content') ?>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var \App\View\AppView $this
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<?= $this->fetch('content') ?>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 943 B |
Binary file not shown.
|
After Width: | Height: | Size: 943 B |
Loading…
Reference in New Issue