From 5b241c4e37cec9a4b516a002ae051c56ca584649 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 11 Oct 2025 19:36:42 -0700 Subject: [PATCH] tests wip --- tests/TestCase/Model/Table/CartsTableTest.php | 2 +- tests/bootstrap.php | 128 ++++++++++++++++++ tests/test_app/src/Application.php | 39 ++++++ .../test_app/src/Controller/AppController.php | 16 +++ tests/test_app/src/View/AppView.php | 11 ++ tests/test_app/templates/Error/error500.php | 44 ++++++ tests/test_app/templates/layout/ajax.php | 6 + tests/test_app/templates/layout/default.php | 6 + .../2c386086-f4c5-4093-bea5-ee9c29479f58.png | Bin 0 -> 943 bytes tests/test_app/webroot/images/cake_icon.png | Bin 0 -> 943 bytes 10 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 tests/bootstrap.php create mode 100644 tests/test_app/src/Application.php create mode 100644 tests/test_app/src/Controller/AppController.php create mode 100644 tests/test_app/src/View/AppView.php create mode 100644 tests/test_app/templates/Error/error500.php create mode 100644 tests/test_app/templates/layout/ajax.php create mode 100644 tests/test_app/templates/layout/default.php create mode 100644 tests/test_app/webroot/images/2c386086-f4c5-4093-bea5-ee9c29479f58.png create mode 100644 tests/test_app/webroot/images/cake_icon.png 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 0000000000000000000000000000000000000000..394fa42d5131cdc7b0b1246af93b92179f3c887e GIT binary patch literal 943 zcmV;g15o^lP)9q)cr7> zIGsQFGn3| zCzs2iP$-yfVPOGVTU&6sT(-5fwHb2tVsLP9#{Vr9Ct?R7q(rf?v2A5#W$OI=e1YUJ zQ1YRnA&iWSQ1XYAm__>aYb6XIhMiYVD+-z8_pYi6+CsH{*^m;vOjqvbr=H&DFkeqxHQBh$Scsoy0Glw(T zsaSG*ok62V;~yXYNgP*DUw;o98^+0@vGFb{HC+As}XJ=;xg=B7N_;-mKbHH{|lXs_o+aPcs5~J?s%^P2Odb)Uz z$GvY6^!N9(C2-h?28B$qx7%_yHnt2eU%nQ0qThbl6a_+b)EirjBgQ`g1_07Fr&6R? RzIgxu002ovPDHLkV1mdlwUYn< literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..394fa42d5131cdc7b0b1246af93b92179f3c887e GIT binary patch literal 943 zcmV;g15o^lP)9q)cr7> zIGsQFGn3| zCzs2iP$-yfVPOGVTU&6sT(-5fwHb2tVsLP9#{Vr9Ct?R7q(rf?v2A5#W$OI=e1YUJ zQ1YRnA&iWSQ1XYAm__>aYb6XIhMiYVD+-z8_pYi6+CsH{*^m;vOjqvbr=H&DFkeqxHQBh$Scsoy0Glw(T zsaSG*ok62V;~yXYNgP*DUw;o98^+0@vGFb{HC+As}XJ=;xg=B7N_;-mKbHH{|lXs_o+aPcs5~J?s%^P2Odb)Uz z$GvY6^!N9(C2-h?28B$qx7%_yHnt2eU%nQ0qThbl6a_+b)EirjBgQ`g1_07Fr&6R? RzIgxu002ovPDHLkV1mdlwUYn< literal 0 HcmV?d00001