not used to plugin testing - trying to get working but fixtures not working yet

This commit is contained in:
Brandon Shipley 2025-03-26 00:07:05 -07:00
parent 23147fc574
commit b17634c08a
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
21 changed files with 628 additions and 58 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
/config/Migrations/schema-dump-default.lock
/vendor/
/.idea/
tmp

View File

@ -5,6 +5,7 @@
"license": "AGPL-3.0-or-later",
"require": {
"php": ">=8.1",
"dereuromark/cakephp-tools": "^3.9",
"cakephp/cakephp": "^5.0.1"
},
"require-dev": {
@ -18,7 +19,8 @@
"autoload-dev": {
"psr-4": {
"CakeProducts\\Test\\": "tests/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
"TestApp\\": "tests/test_app/src/"
}
}
}

View File

@ -8,6 +8,7 @@
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
<env name="FIXTURE_SCHEMA_METADATA" value="tests/schema.php"/>
</php>
<!-- Add any additional test suites you want to run here -->

View File

@ -5,6 +5,7 @@ namespace CakeProducts\Controller;
use Cake\Log\Log;
use CakeProducts\Controller\AppController;
use CakeProducts\Service\InternalCatalogManagerService;
/**
* ExternalProductCatalogs Controller
@ -45,18 +46,24 @@ class ExternalProductCatalogsController extends AppController
*
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
*/
public function add()
public function add(InternalCatalogManagerService $catalogManagerService)
{
$externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity();
if ($this->request->is('post')) {
$externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData());
if ($this->ExternalProductCatalogs->save($externalProductCatalog)) {
$postData = $this->request->getData();
if ($this->request->getSession()->read('Auth.User.id')) {
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
}
$result = $catalogManagerService->createNewExternalCatalog($externalProductCatalog, $postData);
Log::debug(print_r('$result from createNewExternalCatalog', true));
Log::debug(print_r($result, true));
if ($result['result']) {
$this->Flash->success(__('The external product catalog has been saved.'));
return $this->redirect(['action' => 'index']);
}
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /add', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true));
// Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /add', true));
// Log::debug(print_r($externalProductCatalog->getErrors(), true));
$this->Flash->error(__('The external product catalog could not be saved. Please, try again.'));
}
$productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all();

View File

@ -97,8 +97,8 @@ class ProductsTable extends Table
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => '0']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => '1']);
$rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']);
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
return $rules;
}

View File

@ -10,6 +10,7 @@ use Cake\Log\Log;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\Table;
use Cake\Utility\Text;
use CakeProducts\Model\Entity\ExternalProductCatalog;
use CakeProducts\Model\Entity\ProductCategory;
use CakeProducts\Model\Table\ProductCatalogsTable;
@ -55,6 +56,40 @@ class InternalCatalogManagerService
return $this->ProductCatalogs->get($id, contain: $contain);
}
/**
* @param ExternalProductCatalog $externalProductCatalog external product catalog entity
* @param array $data data to save
*
* @return array
*/
public function createNewExternalCatalog(ExternalProductCatalog $externalProductCatalog, array $data = []): array
{
$now = Time::now();
$associated = [];
Log::info('posted data - adding new ExternalProductCatalog');
Log::info(print_r($data, true));
$saveOptions = [
'associated' => $associated,
];
$externalProductCatalog = $this->ProductCatalogs->ExternalProductCatalogs->patchEntity($externalProductCatalog, $data, $saveOptions);
if ($externalProductCatalog->getErrors()) {
Log::debug(print_r('$externalProductCatalog->getErrors() next - failed to save from create new external product catalog', true));
Log::debug(print_r($externalProductCatalog->getErrors(), true));
}
$returnData = [
'entity' => $externalProductCatalog,
'result' => $this->ProductCatalogs->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions),
'apiResults' => [],
];
if ($returnData['result'] && $this->externalCatalogManager) {
// $returnData['apiResults'] = $this->externalCatalogManager->newCatalogCreated($returnData['result']);
}
return $returnData;
}
/**
* @param string|null $id
*

View File

@ -10,6 +10,22 @@ use Cake\TestSuite\Fixture\TestFixture;
*/
class ExternalProductCatalogsFixture extends TestFixture
{
/**
* fields property
*
* @var array
*/
public array $fields = [
'id' => ['type' => 'integer'],
'product_catalog_id' => ['type' => 'uuid'],
'base_url' => ['type' => 'string', 'length' => 255, 'null' => false],
'api_url' => ['type' => 'string', 'length' => 255, 'null' => false],
'created' => ['type' => 'datetime', 'null' => false],
'deleted' => ['type' => 'datetime', 'null' => true],
'enabled' => ['type' => 'boolean', 'null' => true],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
];
/**
* Init method
*

View File

@ -10,6 +10,21 @@ use Cake\TestSuite\Fixture\TestFixture;
*/
class ProductsFixture extends TestFixture
{
public string $table = 'products';
/**
* fields property
*
* @var array
*/
public array $fields = [
'id' => ['type' => 'uuid'],
'name' => ['type' => 'string', 'length' => 255, 'null' => false],
'product_category_id' => ['type' => 'uuid'],
'product_type_id' => ['type' => 'integer', 'length' => 11, 'null' => false],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
];
/**
* Init method
*

View File

@ -9,6 +9,13 @@ class BaseControllerTest extends TestCase
{
use IntegrationTestTrait;
protected function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->loadPlugins(['CakeProducts']);
}
public function loginUserByRole(string $role = 'admin'): void
{
$this->session(['Auth.User.id' => 1]);

View File

@ -1,55 +1,105 @@
<?php
declare(strict_types=1);
/**
* Test suite bootstrap for CakeProducts.
*
* 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\Core\Configure;
use Cake\Core\Plugin;
use Cake\Database\Type\JsonType;
use Cake\Database\TypeFactory;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\Table;
use Cake\TestSuite\Fixture\SchemaLoader;
use Cake\Utility\Security;
use Cake\View\View;
use CakeProducts\CakeProductsPlugin;
use TestApp\Application;
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);
}
/**
* 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.
*/
use Cake\TestSuite\Fixture\SchemaLoader;
define('ROOT', dirname(__DIR__));
define('APP_DIR', 'src');
// Load a schema dump file.
(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
// Point app constants to the test app.
define('TEST_ROOT', ROOT . DS . 'tests' . DS . 'test_app' . DS);
define('APP', TEST_ROOT . APP_DIR . DS);
define('TMP', ROOT . DS . 'tmp' . DS);
if (!is_dir(TMP)) {
mkdir(TMP, 0770, true);
}
define('TESTS', ROOT . DS . 'tests' . DS);
define('CONFIG', TESTS . 'config' . DS);
define('LOGS', TMP . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . APP_DIR . DS);
require dirname(__DIR__) . '/vendor/autoload.php';
require CORE_PATH . 'config/bootstrap.php';
require CAKE_CORE_INCLUDE_PATH . '/src/functions.php';
Configure::write('App', [
'encoding' => 'utf-8',
'namespace' => 'App',
'paths' => [
'templates' => [TESTS . 'test_app' . DS . 'templates' . DS],
],
'fullBaseUrl' => 'http://localhost',
]);
Configure::write('debug', true);
$cache = [
'default' => [
'engine' => 'File',
],
'_cake_core_' => [
'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);
Security::setSalt('123');
TypeFactory::map('json', JsonType::class);
class_alias(Application::class, 'App\Application');
class_alias(AppController::class, 'App\Controller\AppController');
class_alias(Table::class, 'App\Model\Table\Table');
class_alias(View::class, 'App\View\AppView');
Plugin::getCollection()->add(new CakeProductsPlugin());
// Ensure default test connection is defined
if (!getenv('DB_URL')) {
putenv('DB_URL=sqlite:///:memory:');
}
ConnectionManager::setConfig('test', [
'url' => getenv('DB_URL') ?: null,
'timezone' => 'UTC',
'quoteIdentifiers' => true,
'cacheMetadata' => true,
]);
if (env('FIXTURE_SCHEMA_METADATA')) {
$loader = new SchemaLoader();
$loader->loadInternalFile(env('FIXTURE_SCHEMA_METADATA'));
}

View File

@ -0,0 +1 @@
<?php

1
tests/config/routes.php Normal file
View File

@ -0,0 +1 @@
<?php

43
tests/schema.php Normal file
View File

@ -0,0 +1,43 @@
<?php
/**
* Based entirely off of dereuromark's plugins as I was having trouble getting fixtures to load
* after moving the plugins outside of an existing cakephp app's plugins folder
*
* @link https://github.com/dereuromark/cakephp-tools/blob/master/tests/schema.php
*/
use Cake\Utility\Inflector;
$tables = [];
/**
* @var \DirectoryIterator<\DirectoryIterator> $iterator
*/
$iterator = new DirectoryIterator(__DIR__ . DS . 'Fixture');
foreach ($iterator as $file) {
if (!preg_match('/(\w+)Fixture.php$/', (string)$file, $matches)) {
continue;
}
$name = $matches[1];
$tableName = Inflector::underscore($name);
$class = 'CakeProducts\\Test\\Fixture\\' . $name . 'Fixture';
try {
$object = (new ReflectionClass($class))->getProperty('fields');
} catch (ReflectionException $e) {
continue;
}
$array = $object->getDefaultValue();
$constraints = $array['_constraints'] ?? [];
$indexes = $array['_indexes'] ?? [];
unset($array['_constraints'], $array['_indexes'], $array['_options']);
$table = [
'table' => $tableName,
'columns' => $array,
'constraints' => $constraints,
'indexes' => $indexes,
];
$tables[$tableName] = $table;
}
return $tables;

View File

@ -1 +1,204 @@
-- Test database schema for CakeProducts
/*!999999\- enable the sandbox mode */
-- MariaDB dump 10.19 Distrib 10.6.18-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: open_erp
-- ------------------------------------------------------
-- Server version 10.6.18-MariaDB-0ubuntu0.22.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `product_catalogs`
--
DROP TABLE IF EXISTS `product_catalogs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `product_catalogs` (
`id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`catalog_description` varchar(255) DEFAULT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `product_catalogs`
--
LOCK TABLES `product_catalogs` WRITE;
/*!40000 ALTER TABLE `product_catalogs` DISABLE KEYS */;
INSERT INTO `product_catalogs` VALUES ('115153f3-2f59-4234-8ff8-e1b205761428','Automotive','',1),('f56f3412-ed23-490b-be6e-016208c415d2','Software','',1);
/*!40000 ALTER TABLE `product_catalogs` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `product_categories`
--
DROP TABLE IF EXISTS `product_categories`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `product_categories` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`product_catalog_id` char(36) NOT NULL,
`internal_id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`category_description` text DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`lft` int(11) NOT NULL,
`rght` int(11) NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME_AND_CATALOG_ID` (`product_catalog_id`,`name`),
KEY `parent_id` (`parent_id`),
KEY `lft` (`lft`),
KEY `product_catalog_id` (`product_catalog_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `product_categories`
--
LOCK TABLES `product_categories` WRITE;
/*!40000 ALTER TABLE `product_categories` DISABLE KEYS */;
INSERT INTO `product_categories` VALUES (1,'115153f3-2f59-4234-8ff8-e1b205761428','db4b4273-eddc-46d4-93c8-45cf7c6e058e','Engine','',NULL,1,4,1),(2,'115153f3-2f59-4234-8ff8-e1b205761428','3c2377c5-b97c-4bc9-9660-8f77b4893d8b','Engine Internals','',1,2,3,1),(3,'115153f3-2f59-4234-8ff8-e1b205761428','fbee6709-396f-4bb4-b60b-e125b0bc4e83','Electrical','',NULL,5,8,1),(4,'115153f3-2f59-4234-8ff8-e1b205761428','6d223283-361b-4f9f-a7f1-c97aa0ca4c23','Wiring','',3,6,7,1),(5,'115153f3-2f59-4234-8ff8-e1b205761428','c447b6f4-0fb1-4d59-ba45-5613829a725a','Suspension','',NULL,9,12,1),(6,'115153f3-2f59-4234-8ff8-e1b205761428','1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e','Coilovers','',5,10,11,1),(7,'f56f3412-ed23-490b-be6e-016208c415d2','8c89a3ca-d56f-46bf-a738-7e85b3342b2a','Support','',NULL,1,2,1);
/*!40000 ALTER TABLE `product_categories` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `product_category_attributes`
--
DROP TABLE IF EXISTS `product_category_attributes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `product_category_attributes` (
`id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`product_category_id` char(36) DEFAULT NULL,
`attribute_type_id` int(11) NOT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE` (`name`,`product_category_id`),
KEY `BY_PRODUCT_CATEGORY_ID` (`product_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `product_category_attributes`
--
LOCK TABLES `product_category_attributes` WRITE;
/*!40000 ALTER TABLE `product_category_attributes` DISABLE KEYS */;
INSERT INTO `product_category_attributes` VALUES ('bffebec4-2533-45b9-8f4e-e9169f5143d4','AWG','4',1,1);
/*!40000 ALTER TABLE `product_category_attributes` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `product_category_attribute_options`
--
DROP TABLE IF EXISTS `product_category_attribute_options`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `product_category_attribute_options` (
`id` char(36) NOT NULL,
`product_category_attribute_id` char(36) NOT NULL,
`attribute_value` varchar(255) NOT NULL,
`attribute_label` varchar(255) NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
KEY `BY_PRODUCT_CATEGORY_ATTRIBUTE_ID` (`product_category_attribute_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `product_category_attribute_options`
--
LOCK TABLES `product_category_attribute_options` WRITE;
/*!40000 ALTER TABLE `product_category_attribute_options` DISABLE KEYS */;
INSERT INTO `product_category_attribute_options` VALUES ('0a19dbc8-b09b-4843-8955-3c1a9c94de27','bffebec4-2533-45b9-8f4e-e9169f5143d4','8','8',1),('1d7705d0-e4a8-4b88-ad86-b021493a6191','bffebec4-2533-45b9-8f4e-e9169f5143d4','10','10',1),('49d79d68-62ac-4dae-8757-4b4e31f00f26','bffebec4-2533-45b9-8f4e-e9169f5143d4','12','12',1),('6fb40b3d-ec9f-4ad0-b21a-26de0769e10c','bffebec4-2533-45b9-8f4e-e9169f5143d4','14','14',1),('871df26a-8d91-425c-8f94-ac450323674f','bffebec4-2533-45b9-8f4e-e9169f5143d4','4','4',1),('87a465f3-5c4c-4c1b-9dd2-d5c08831386d','bffebec4-2533-45b9-8f4e-e9169f5143d4','16','16',1),('9efa9fce-cdcd-43ae-a6cc-c8fb4076690e','bffebec4-2533-45b9-8f4e-e9169f5143d4','6','6',1),('bebc8041-4502-4a3e-a452-ee41a1c6890e','bffebec4-2533-45b9-8f4e-e9169f5143d4','20','20',1),('dd21c817-670b-4118-9dcb-e9e88ffc8c86','bffebec4-2533-45b9-8f4e-e9169f5143d4','18','18',1);
/*!40000 ALTER TABLE `product_category_attribute_options` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `products`
--
DROP TABLE IF EXISTS `products`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `products` (
`id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`product_category_id` char(36) NOT NULL,
`product_type_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME_AND_CATEGORY_ID` (`product_category_id`,`name`),
KEY `product_category_id` (`product_category_id`),
KEY `product_type_id` (`product_type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `products`
--
LOCK TABLES `products` WRITE;
/*!40000 ALTER TABLE `products` DISABLE KEYS */;
/*!40000 ALTER TABLE `products` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `external_product_catalogs`
--
DROP TABLE IF EXISTS `external_product_catalogs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `external_product_catalogs` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`product_catalog_id` char(36) NOT NULL,
`base_url` varchar(255) NOT NULL,
`api_url` varchar(255) NOT NULL,
`created` datetime NOT NULL,
`deleted` datetime DEFAULT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `BY_PRODUCT_CATALOG_ID` (`product_catalog_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `external_product_catalogs`
--
LOCK TABLES `external_product_catalogs` WRITE;
/*!40000 ALTER TABLE `external_product_catalogs` DISABLE KEYS */;
/*!40000 ALTER TABLE `external_product_catalogs` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2024-11-25 2:21:42

93
tests/schema2.sql Normal file
View File

@ -0,0 +1,93 @@
/*!999999\- enable the sandbox mode */
-- MariaDB dump 10.19 Distrib 10.6.18-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: open_erp
-- ------------------------------------------------------
-- Server version 10.6.18-MariaDB-0ubuntu0.22.04.1
DROP TABLE IF EXISTS `product_catalogs`;
CREATE TABLE `product_catalogs` (
`id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`catalog_description` varchar(255) DEFAULT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
INSERT INTO `product_catalogs` VALUES ('115153f3-2f59-4234-8ff8-e1b205761428','Automotive','',1),('f56f3412-ed23-490b-be6e-016208c415d2','Software','',1);
DROP TABLE IF EXISTS `product_categories`;
CREATE TABLE `product_categories` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`product_catalog_id` char(36) NOT NULL,
`internal_id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`category_description` text DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`lft` int(11) NOT NULL,
`rght` int(11) NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME_AND_CATALOG_ID` (`product_catalog_id`,`name`)
-- KEY `parent_id` (`parent_id`),
-- KEY `lft` (`lft`),
-- KEY `product_catalog_id` (`product_catalog_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
INSERT INTO `product_categories` VALUES (1,'115153f3-2f59-4234-8ff8-e1b205761428','db4b4273-eddc-46d4-93c8-45cf7c6e058e','Engine','',NULL,1,4,1),(2,'115153f3-2f59-4234-8ff8-e1b205761428','3c2377c5-b97c-4bc9-9660-8f77b4893d8b','Engine Internals','',1,2,3,1),(3,'115153f3-2f59-4234-8ff8-e1b205761428','fbee6709-396f-4bb4-b60b-e125b0bc4e83','Electrical','',NULL,5,8,1),(4,'115153f3-2f59-4234-8ff8-e1b205761428','6d223283-361b-4f9f-a7f1-c97aa0ca4c23','Wiring','',3,6,7,1),(5,'115153f3-2f59-4234-8ff8-e1b205761428','c447b6f4-0fb1-4d59-ba45-5613829a725a','Suspension','',NULL,9,12,1),(6,'115153f3-2f59-4234-8ff8-e1b205761428','1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e','Coilovers','',5,10,11,1),(7,'f56f3412-ed23-490b-be6e-016208c415d2','8c89a3ca-d56f-46bf-a738-7e85b3342b2a','Support','',NULL,1,2,1);
DROP TABLE IF EXISTS `product_category_attributes`;
CREATE TABLE `product_category_attributes` (
`id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`product_category_id` char(36) DEFAULT NULL,
`attribute_type_id` int(11) NOT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE` (`name`,`product_category_id`),
KEY `BY_PRODUCT_CATEGORY_ID` (`product_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
INSERT INTO `product_category_attributes` VALUES ('bffebec4-2533-45b9-8f4e-e9169f5143d4','AWG','4',1,1);
DROP TABLE IF EXISTS `product_category_attribute_options`;
CREATE TABLE `product_category_attribute_options` (
`id` char(36) NOT NULL,
`product_category_attribute_id` char(36) NOT NULL,
`attribute_value` varchar(255) NOT NULL,
`attribute_label` varchar(255) NOT NULL,
`enabled` tinyint(1) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
KEY `BY_PRODUCT_CATEGORY_ATTRIBUTE_ID` (`product_category_attribute_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
LOCK TABLES `product_category_attribute_options` WRITE;
INSERT INTO `product_category_attribute_options` VALUES ('0a19dbc8-b09b-4843-8955-3c1a9c94de27','bffebec4-2533-45b9-8f4e-e9169f5143d4','8','8',1),('1d7705d0-e4a8-4b88-ad86-b021493a6191','bffebec4-2533-45b9-8f4e-e9169f5143d4','10','10',1),('49d79d68-62ac-4dae-8757-4b4e31f00f26','bffebec4-2533-45b9-8f4e-e9169f5143d4','12','12',1),('6fb40b3d-ec9f-4ad0-b21a-26de0769e10c','bffebec4-2533-45b9-8f4e-e9169f5143d4','14','14',1),('871df26a-8d91-425c-8f94-ac450323674f','bffebec4-2533-45b9-8f4e-e9169f5143d4','4','4',1),('87a465f3-5c4c-4c1b-9dd2-d5c08831386d','bffebec4-2533-45b9-8f4e-e9169f5143d4','16','16',1),('9efa9fce-cdcd-43ae-a6cc-c8fb4076690e','bffebec4-2533-45b9-8f4e-e9169f5143d4','6','6',1),('bebc8041-4502-4a3e-a452-ee41a1c6890e','bffebec4-2533-45b9-8f4e-e9169f5143d4','20','20',1),('dd21c817-670b-4118-9dcb-e9e88ffc8c86','bffebec4-2533-45b9-8f4e-e9169f5143d4','18','18',1);
UNLOCK TABLES;
DROP TABLE IF EXISTS `products`;
CREATE TABLE `products` (
`id` char(36) NOT NULL,
`name` varchar(255) NOT NULL,
`product_category_id` char(36) NOT NULL,
`product_type_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `BY_NAME_AND_CATEGORY_ID` (`product_category_id`,`name`),
KEY `product_category_id` (`product_category_id`),
KEY `product_type_id` (`product_type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
DROP TABLE IF EXISTS `external_product_catalogs`;
CREATE TABLE `external_product_catalogs` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`product_catalog_id` char(36) NOT NULL,
`base_url` varchar(255) NOT NULL,
`api_url` varchar(255) NOT NULL,
`created` datetime NOT NULL,
`deleted` datetime DEFAULT NULL,
`enabled` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `BY_PRODUCT_CATALOG_ID` (`product_catalog_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

View File

@ -0,0 +1,20 @@
<?php
namespace TestApp;
use Cake\Http\BaseApplication;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\RoutingMiddleware;
class Application extends BaseApplication {
/**
* @inheritDoc
*/
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue {
$middleware->add(new RoutingMiddleware($this));
return $middleware;
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace TestApp\Controller;
use Cake\Controller\Controller;
class AppController extends Controller {
}

View File

@ -0,0 +1,11 @@
<?php
namespace TestApp\View;
use Cake\View\View;
/**
* @property \TinyAuth\View\Helper\AuthUserHelper $AuthUser
*/
class AppView extends View {
}

View File

@ -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>

View File

@ -0,0 +1,6 @@
<?php
/**
* @var \App\View\AppView $this
*/
?>
<?= $this->fetch('content') ?>

View File

@ -0,0 +1,6 @@
<?php
/**
* @var \App\View\AppView $this
*/
?>
<?= $this->fetch('content') ?>