diff --git a/tests/TestCase/Model/Table/CartsTableTest.php b/tests/TestCase/Model/Table/CartsTableTest.php index 8631546..0dcad8f 100644 --- a/tests/TestCase/Model/Table/CartsTableTest.php +++ b/tests/TestCase/Model/Table/CartsTableTest.php @@ -25,7 +25,7 @@ class CartsTableTest extends TestCase */ protected array $fixtures = [ 'plugin.CakeCarts.Carts', - 'plugin.CakeCarts.Users', +// 'plugin.CakeCarts.Users', 'plugin.CakeCarts.CartItems', ]; diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..27f464e --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,128 @@ + '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']); diff --git a/tests/test_app/src/Application.php b/tests/test_app/src/Application.php new file mode 100644 index 0000000..e94ee2a --- /dev/null +++ b/tests/test_app/src/Application.php @@ -0,0 +1,39 @@ +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(); + }); + } + +} diff --git a/tests/test_app/src/Controller/AppController.php b/tests/test_app/src/Controller/AppController.php new file mode 100644 index 0000000..7387589 --- /dev/null +++ b/tests/test_app/src/Controller/AppController.php @@ -0,0 +1,16 @@ +loadComponent('Flash'); + } +} diff --git a/tests/test_app/src/View/AppView.php b/tests/test_app/src/View/AppView.php new file mode 100644 index 0000000..e885cc1 --- /dev/null +++ b/tests/test_app/src/View/AppView.php @@ -0,0 +1,11 @@ +layout = 'error'; + +if (Configure::read('debug')): + $this->layout = 'dev_error'; + + $this->assign('title', $message); + $this->assign('templateName', 'error500.ctp'); + + $this->start('file'); +?> +queryString)) : ?> +

+ SQL Query: + queryString) ?> +

+ +params)) : ?> + SQL Query Params: + params) ?> + + + Error in: + getFile()), $error->getLine()) ?> + +element('auto_table_warning'); + + if (extension_loaded('xdebug')): + xdebug_print_function_stack(); + endif; + + $this->end(); +endif; +?> +

+

+ : + +

diff --git a/tests/test_app/templates/layout/ajax.php b/tests/test_app/templates/layout/ajax.php new file mode 100644 index 0000000..13b3dea --- /dev/null +++ b/tests/test_app/templates/layout/ajax.php @@ -0,0 +1,6 @@ + +fetch('content') ?> diff --git a/tests/test_app/templates/layout/default.php b/tests/test_app/templates/layout/default.php new file mode 100644 index 0000000..13b3dea --- /dev/null +++ b/tests/test_app/templates/layout/default.php @@ -0,0 +1,6 @@ + +fetch('content') ?> diff --git a/tests/test_app/webroot/images/2c386086-f4c5-4093-bea5-ee9c29479f58.png b/tests/test_app/webroot/images/2c386086-f4c5-4093-bea5-ee9c29479f58.png new file mode 100644 index 0000000..394fa42 Binary files /dev/null and b/tests/test_app/webroot/images/2c386086-f4c5-4093-bea5-ee9c29479f58.png differ diff --git a/tests/test_app/webroot/images/cake_icon.png b/tests/test_app/webroot/images/cake_icon.png new file mode 100644 index 0000000..394fa42 Binary files /dev/null and b/tests/test_app/webroot/images/cake_icon.png differ