diff --git a/composer.json b/composer.json index 8db7aa9..5a68c45 100644 --- a/composer.json +++ b/composer.json @@ -9,11 +9,14 @@ "dereuromark/cakephp-tools": "^3.9", "muffin/trash": "^4.2", "cakephp/cakephp": "^5.0.1", - "bentools/cartesian-product": "dev-master" + "bentools/cartesian-product": "^2.0" }, "require-dev": { "phpunit/phpunit": "^10.1", - "cakephp/migrations": "^4.0.0" + "cakephp/migrations": "^4.0.0", + "cakedc/cakephp-phpstan": "^4.1", + "dereuromark/composer-prefer-lowest": "^0.1.10", + "fig-r/psr2r-sniffer": "^2.7" }, "suggest": { "hi-powered-dev/cake-carts": "Allow users to add products/SKUs to a cart" @@ -29,5 +32,22 @@ "Cake\\Test\\": "vendor/cakephp/cakephp/tests/", "TestApp\\": "tests/test_app/src/" } + }, + "scripts": { + "check": [ + "@test", + "@cs-check" + ], + "test": "phpunit --colors=always", + "cs-check": "vendor/bin/phpcs --colors", + "cs-fix": "vendor/bin/phpcbf --colors", + "lowest": "validate-prefer-lowest", + "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json", + "stan": "phpstan analyze" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/config/Migrations/20241114080900_CreateProductCatalogs.php b/config/Migrations/20241114080900_CreateProductCatalogs.php index 4140232..06c23fb 100644 --- a/config/Migrations/20241114080900_CreateProductCatalogs.php +++ b/config/Migrations/20241114080900_CreateProductCatalogs.php @@ -3,42 +3,42 @@ declare(strict_types=1); use Migrations\AbstractMigration; -class CreateProductCatalogs extends AbstractMigration -{ - /** +class CreateProductCatalogs extends AbstractMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('catalog_description', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => null, - 'null' => false, - ]); - $table->addIndex([ - 'name', - ], [ - 'name' => 'BY_NAME', - 'unique' => true, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('product_catalogs', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('catalog_description', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => null, + 'null' => false, + ]); + $table->addIndex([ + 'name', + ], [ + 'name' => 'BY_NAME', + 'unique' => true, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20241114081036_CreateProductCategories.php b/config/Migrations/20241114081036_CreateProductCategories.php index 10631b0..5cece9d 100644 --- a/config/Migrations/20241114081036_CreateProductCategories.php +++ b/config/Migrations/20241114081036_CreateProductCategories.php @@ -3,36 +3,35 @@ declare(strict_types=1); use Migrations\AbstractMigration; -class CreateProductCategories extends AbstractMigration -{ - /** +class CreateProductCategories extends AbstractMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_categories'); + public function change(): void { + $table = $this->table('product_categories'); - $table->addColumn('product_catalog_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('internal_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('category_description', 'text', [ - 'default' => null, - 'null' => true, - ]); + $table->addColumn('product_catalog_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('internal_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('category_description', 'text', [ + 'default' => null, + 'null' => true, + ]); // $table->addColumn('shopify_v1_id', 'integer', [ // 'default' => null, // 'limit' => 11, @@ -43,36 +42,37 @@ class CreateProductCategories extends AbstractMigration // 'limit' => 255, // 'null' => true, // ]); - $table->addColumn('parent_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]); - $table->addColumn('lft', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]); - $table->addColumn('rght', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => false, - 'null' => false, - ]); + $table->addColumn('parent_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => true, + ]); + $table->addColumn('lft', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]); + $table->addColumn('rght', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => false, + 'null' => false, + ]); + + $table->addIndex('parent_id'); + $table->addIndex('lft'); + $table->addIndex('product_catalog_id'); + $table->addIndex([ + 'product_catalog_id', + 'name', + ], [ + 'name' => 'BY_NAME_AND_CATALOG_ID', + 'unique' => true, + ]); + $table->create(); + } - $table->addIndex('parent_id'); - $table->addIndex('lft'); - $table->addIndex('product_catalog_id'); - $table->addIndex([ - 'product_catalog_id', - 'name', - ], [ - 'name' => 'BY_NAME_AND_CATALOG_ID', - 'unique' => true, - ]); - $table->create(); - } } diff --git a/config/Migrations/20241114090547_CreateProducts.php b/config/Migrations/20241114090547_CreateProducts.php index b680fb2..1a28a6f 100644 --- a/config/Migrations/20241114090547_CreateProducts.php +++ b/config/Migrations/20241114090547_CreateProducts.php @@ -3,38 +3,37 @@ declare(strict_types=1); use Migrations\AbstractMigration; -class CreateProducts extends AbstractMigration -{ - /** +class CreateProducts extends AbstractMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('products', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('product_category_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_type_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]); - $table->addIndex('product_category_id'); - $table->addIndex('product_type_id'); + public function change(): void { + $table = $this->table('products', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('product_category_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_type_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]); + $table->addIndex('product_category_id'); + $table->addIndex('product_type_id'); // $table->addIndex([ // 'product_category_id', // 'name', @@ -42,6 +41,7 @@ class CreateProducts extends AbstractMigration // 'name' => 'BY_NAME_AND_CATEGORY_ID', // 'unique' => true, // ]); - $table->create(); - } + $table->create(); + } + } diff --git a/config/Migrations/20241115054627_CreateProductCategoryAttributes.php b/config/Migrations/20241115054627_CreateProductCategoryAttributes.php index b229ec3..dd6cba8 100644 --- a/config/Migrations/20241115054627_CreateProductCategoryAttributes.php +++ b/config/Migrations/20241115054627_CreateProductCategoryAttributes.php @@ -3,53 +3,53 @@ declare(strict_types=1); use Migrations\AbstractMigration; -class CreateProductCategoryAttributes extends AbstractMigration -{ - /** +class CreateProductCategoryAttributes extends AbstractMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('product_category_id', 'uuid', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('attribute_type_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => null, - 'null' => false, - ]); - $table->addIndex([ - 'product_category_id', - ], [ - 'name' => 'BY_PRODUCT_CATEGORY_ID', - 'unique' => false, - ]); - $table->addIndex([ - 'name', - 'product_category_id', - ], [ - 'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE', - 'unique' => true, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('product_category_attributes', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('product_category_id', 'uuid', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('attribute_type_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => null, + 'null' => false, + ]); + $table->addIndex([ + 'product_category_id', + ], [ + 'name' => 'BY_PRODUCT_CATEGORY_ID', + 'unique' => false, + ]); + $table->addIndex([ + 'name', + 'product_category_id', + ], [ + 'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE', + 'unique' => true, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20241115062613_CreateProductCategoryAttributeOptions.php b/config/Migrations/20241115062613_CreateProductCategoryAttributeOptions.php index 868f349..29f3cb2 100644 --- a/config/Migrations/20241115062613_CreateProductCategoryAttributeOptions.php +++ b/config/Migrations/20241115062613_CreateProductCategoryAttributeOptions.php @@ -3,46 +3,46 @@ declare(strict_types=1); use Migrations\AbstractMigration; -class CreateProductCategoryAttributeOptions extends AbstractMigration -{ - /** +class CreateProductCategoryAttributeOptions extends AbstractMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_category_attribute_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('attribute_value', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('attribute_label', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => true, - 'null' => false, - ]); - $table->addIndex([ - 'product_category_attribute_id', - ], [ - 'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID', - 'unique' => false, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('product_category_attribute_options', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_category_attribute_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('attribute_value', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('attribute_label', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => true, + 'null' => false, + ]); + $table->addIndex([ + 'product_category_attribute_id', + ], [ + 'name' => 'BY_PRODUCT_CATEGORY_ATTRIBUTE_ID', + 'unique' => false, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20241122070040_CreateExternalProductCatalogs.php b/config/Migrations/20241122070040_CreateExternalProductCatalogs.php index 6af05d7..2d95603 100644 --- a/config/Migrations/20241122070040_CreateExternalProductCatalogs.php +++ b/config/Migrations/20241122070040_CreateExternalProductCatalogs.php @@ -3,54 +3,54 @@ declare(strict_types=1); use Migrations\AbstractMigration; -class CreateExternalProductCatalogs extends AbstractMigration -{ - /** +class CreateExternalProductCatalogs extends AbstractMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('external_product_catalogs', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_catalog_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('base_url', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('api_url', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('created', 'datetime', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => null, - 'null' => false, - ]); - $table->addIndex([ - 'product_catalog_id', - ], [ - 'name' => 'BY_PRODUCT_CATALOG_ID', - 'unique' => false, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('external_product_catalogs', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_catalog_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('base_url', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('api_url', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => null, + 'null' => false, + ]); + $table->addIndex([ + 'product_catalog_id', + ], [ + 'name' => 'BY_PRODUCT_CATALOG_ID', + 'unique' => false, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20250331012424_RemoveCatalogIdFromExternalProductCatalogs.php b/config/Migrations/20250331012424_RemoveCatalogIdFromExternalProductCatalogs.php index 27ccc02..f575938 100644 --- a/config/Migrations/20250331012424_RemoveCatalogIdFromExternalProductCatalogs.php +++ b/config/Migrations/20250331012424_RemoveCatalogIdFromExternalProductCatalogs.php @@ -3,20 +3,20 @@ declare(strict_types=1); use Migrations\BaseMigration; -class RemoveCatalogIdFromExternalProductCatalogs extends BaseMigration -{ - /** +class RemoveCatalogIdFromExternalProductCatalogs extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('external_product_catalogs'); - $table->removeColumn('product_catalog_id'); - $table->removeColumn('enabled'); - $table->update(); - } + public function change(): void { + $table = $this->table('external_product_catalogs'); + $table->removeColumn('product_catalog_id'); + $table->removeColumn('enabled'); + $table->update(); + } + } diff --git a/config/Migrations/20250331030759_CreateExternalProductCatalogsProductCatalogs.php b/config/Migrations/20250331030759_CreateExternalProductCatalogsProductCatalogs.php index 90d6629..ba8266d 100644 --- a/config/Migrations/20250331030759_CreateExternalProductCatalogsProductCatalogs.php +++ b/config/Migrations/20250331030759_CreateExternalProductCatalogsProductCatalogs.php @@ -3,34 +3,34 @@ declare(strict_types=1); use Migrations\BaseMigration; -class CreateExternalProductCatalogsProductCatalogs extends BaseMigration -{ - /** +class CreateExternalProductCatalogsProductCatalogs extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('external_product_catalogs_product_catalogs'); - $table->addColumn('external_product_catalog_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_catalog_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('created', 'datetime', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => null, - 'null' => false, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('external_product_catalogs_product_catalogs'); + $table->addColumn('external_product_catalog_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_catalog_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => null, + 'null' => false, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20250405081049_CreateProductAttributes.php b/config/Migrations/20250405081049_CreateProductAttributes.php index 9e1fc53..179b1ed 100644 --- a/config/Migrations/20250405081049_CreateProductAttributes.php +++ b/config/Migrations/20250405081049_CreateProductAttributes.php @@ -3,39 +3,39 @@ declare(strict_types=1); use Migrations\BaseMigration; -class CreateProductAttributes extends BaseMigration -{ - /** +class CreateProductAttributes extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_category_attribute_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('attribute_value', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]); - $table->addColumn('product_category_attribute_option_id', 'uuid', [ - 'default' => null, - 'null' => true, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('product_attributes', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_category_attribute_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('attribute_value', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, + ]); + $table->addColumn('product_category_attribute_option_id', 'uuid', [ + 'default' => null, + 'null' => true, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20250408080349_AddSoftDeleteToAllTables.php b/config/Migrations/20250408080349_AddSoftDeleteToAllTables.php index 0fecf4b..d7ad3b9 100644 --- a/config/Migrations/20250408080349_AddSoftDeleteToAllTables.php +++ b/config/Migrations/20250408080349_AddSoftDeleteToAllTables.php @@ -3,64 +3,64 @@ declare(strict_types=1); use Migrations\BaseMigration; -class AddSoftDeleteToAllTables extends BaseMigration -{ - /** +class AddSoftDeleteToAllTables extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('products'); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->update(); + public function change(): void { + $table = $this->table('products'); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->update(); - $table = $this->table('product_category_attributes'); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->update(); + $table = $this->table('product_category_attributes'); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->update(); - $table = $this->table('product_category_attribute_options'); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->update(); + $table = $this->table('product_category_attribute_options'); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->update(); - $table = $this->table('product_categories'); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->update(); + $table = $this->table('product_categories'); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->update(); - $table = $this->table('product_catalogs'); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->update(); + $table = $this->table('product_catalogs'); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->update(); - $table = $this->table('external_product_catalogs_product_catalogs'); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->update(); + $table = $this->table('external_product_catalogs_product_catalogs'); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->update(); + + $table = $this->table('product_attributes'); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->update(); + } - $table = $this->table('product_attributes'); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->update(); - } } diff --git a/config/Migrations/20250415090249_CreateProductSkus.php b/config/Migrations/20250415090249_CreateProductSkus.php index 970397b..08b8085 100644 --- a/config/Migrations/20250415090249_CreateProductSkus.php +++ b/config/Migrations/20250415090249_CreateProductSkus.php @@ -3,60 +3,60 @@ declare(strict_types=1); use Migrations\BaseMigration; -class CreateProductSkus extends BaseMigration -{ - /** +class CreateProductSkus extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('sku', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('barcode', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]); - $table->addColumn('price', 'decimal', [ - 'default' => null, - 'precision' => 15, - 'scale' => 6, - 'null' => true, - ]); - $table->addColumn('cost', 'decimal', [ - 'default' => null, - 'precision' => 15, - 'scale' => 6, - 'null' => true, - ]); - $table->addColumn('created', 'datetime', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('modified', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('sku', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('barcode', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, + ]); + $table->addColumn('price', 'decimal', [ + 'default' => null, + 'precision' => 15, + 'scale' => 6, + 'null' => true, + ]); + $table->addColumn('cost', 'decimal', [ + 'default' => null, + 'precision' => 15, + 'scale' => 6, + 'null' => true, + ]); + $table->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('modified', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20250629054627_CreateProductCategoryVariants.php b/config/Migrations/20250629054627_CreateProductCategoryVariants.php index c8e240e..b9ed9ed 100644 --- a/config/Migrations/20250629054627_CreateProductCategoryVariants.php +++ b/config/Migrations/20250629054627_CreateProductCategoryVariants.php @@ -3,51 +3,50 @@ declare(strict_types=1); use Migrations\AbstractMigration; -class CreateProductCategoryVariants extends AbstractMigration -{ - /** +class CreateProductCategoryVariants extends AbstractMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('product_category_id', 'uuid', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('product_id', 'uuid', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => null, - 'null' => false, - ]); - $table->addIndex([ - 'product_category_id', - ], [ - 'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID', - 'unique' => false, - ]); - $table->addIndex([ - 'product_id', - ], [ - 'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID', - 'unique' => false, - ]); + public function change(): void { + $table = $this->table('product_category_variants', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('product_category_id', 'uuid', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('product_id', 'uuid', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => null, + 'null' => false, + ]); + $table->addIndex([ + 'product_category_id', + ], [ + 'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID', + 'unique' => false, + ]); + $table->addIndex([ + 'product_id', + ], [ + 'name' => 'CATEGORY_VARIANTS_BY_PRODUCT_ID', + 'unique' => false, + ]); // $table->addIndex([ // 'name', // 'product_category_id', @@ -56,6 +55,7 @@ class CreateProductCategoryVariants extends AbstractMigration // 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE', // 'unique' => true, // ]); - $table->create(); - } + $table->create(); + } + } diff --git a/config/Migrations/20250706011935_CreateProductCategoryVariantOptions.php b/config/Migrations/20250706011935_CreateProductCategoryVariantOptions.php index 2628b15..d2e8133 100644 --- a/config/Migrations/20250706011935_CreateProductCategoryVariantOptions.php +++ b/config/Migrations/20250706011935_CreateProductCategoryVariantOptions.php @@ -3,54 +3,54 @@ declare(strict_types=1); use Migrations\BaseMigration; -class CreateProductCategoryVariantOptions extends BaseMigration -{ - /** +class CreateProductCategoryVariantOptions extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_category_variant_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('variant_value', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('variant_label', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => true, - ]); - $table->addColumn('created', 'datetime', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('modified', 'datetime', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => true, - 'null' => false, - ]); + public function change(): void { + $table = $this->table('product_category_variant_options', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_category_variant_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('variant_value', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('variant_label', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, + ]); + $table->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('modified', 'datetime', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => true, + 'null' => false, + ]); // $table->addForeignKey('product_category_variant_id', 'product_category_variants'); // @TODO why cant this be included??? breaks tests on tearDown - $table->create(); - } + $table->create(); + } + } diff --git a/config/Migrations/20250706061008_AddDefaultProductTypeIdToProductCategories.php b/config/Migrations/20250706061008_AddDefaultProductTypeIdToProductCategories.php index fecca37..80cce8a 100644 --- a/config/Migrations/20250706061008_AddDefaultProductTypeIdToProductCategories.php +++ b/config/Migrations/20250706061008_AddDefaultProductTypeIdToProductCategories.php @@ -3,23 +3,23 @@ declare(strict_types=1); use Migrations\BaseMigration; -class AddDefaultProductTypeIdToProductCategories extends BaseMigration -{ - /** +class AddDefaultProductTypeIdToProductCategories extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_categories'); - $table->addColumn('default_product_type_id', 'integer', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]); - $table->update(); - } + public function change(): void { + $table = $this->table('product_categories'); + $table->addColumn('default_product_type_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => true, + ]); + $table->update(); + } + } diff --git a/config/Migrations/20250810031402_CreateProductPhotos.php b/config/Migrations/20250810031402_CreateProductPhotos.php index cfcaa22..fed7897 100644 --- a/config/Migrations/20250810031402_CreateProductPhotos.php +++ b/config/Migrations/20250810031402_CreateProductPhotos.php @@ -3,9 +3,9 @@ declare(strict_types=1); use Migrations\BaseMigration; -class CreateProductPhotos extends BaseMigration -{ - /** +class CreateProductPhotos extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: @@ -13,75 +13,75 @@ class CreateProductPhotos extends BaseMigration * * @return void */ - public function change(): void - { - $table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_sku_id', 'uuid', [ - 'default' => null, - 'null' => true, - ]); + public function change(): void { + $table = $this->table('product_photos', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_sku_id', 'uuid', [ + 'default' => null, + 'null' => true, + ]); - $table->addColumn('photo_dir', 'text', [ - 'default' => null, - 'length' => 255, - 'null' => false, - ]); - $table->addColumn('photo_filename', 'string', [ - 'default' => null, - 'length' => 255, - 'null' => false, - ]); + $table->addColumn('photo_dir', 'text', [ + 'default' => null, + 'length' => 255, + 'null' => false, + ]); + $table->addColumn('photo_filename', 'string', [ + 'default' => null, + 'length' => 255, + 'null' => false, + ]); - $table->addColumn('primary_photo', 'boolean', [ - 'default' => false, - 'null' => false, - ]); + $table->addColumn('primary_photo', 'boolean', [ + 'default' => false, + 'null' => false, + ]); - $table->addColumn('photo_position', 'integer', [ - 'default' => 100, - 'limit' => 11, - 'null' => false, - ]); + $table->addColumn('photo_position', 'integer', [ + 'default' => 100, + 'limit' => 11, + 'null' => false, + ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => false, - 'null' => false, - ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => false, + 'null' => false, + ]); - $table->addColumn('created', 'datetime', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('modified', 'datetime', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('deleted', 'datetime', [ - 'default' => null, - 'null' => true, - ]); + $table->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('modified', 'datetime', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('deleted', 'datetime', [ + 'default' => null, + 'null' => true, + ]); - $table->addIndex([ - 'product_id', - ], [ - 'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID', - 'unique' => false, - ]); - $table->addIndex([ - 'product_sku_id', - ], [ - 'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID', - 'unique' => false, - ]); + $table->addIndex([ + 'product_id', + ], [ + 'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_ID', + 'unique' => false, + ]); + $table->addIndex([ + 'product_sku_id', + ], [ + 'name' => 'PRODUCT_PHOTOS_BY_PRODUCT_SKU_ID', + 'unique' => false, + ]); + + $table->create(); + } - $table->create(); - } } diff --git a/config/Migrations/20250906074703_CreateProductSkuVariantValues.php b/config/Migrations/20250906074703_CreateProductSkuVariantValues.php index c95b25d..a22767a 100644 --- a/config/Migrations/20250906074703_CreateProductSkuVariantValues.php +++ b/config/Migrations/20250906074703_CreateProductSkuVariantValues.php @@ -3,9 +3,9 @@ declare(strict_types=1); use Migrations\BaseMigration; -class CreateProductSkuVariantValues extends BaseMigration -{ - /** +class CreateProductSkuVariantValues extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: @@ -13,25 +13,25 @@ class CreateProductSkuVariantValues extends BaseMigration * * @return void */ - public function change(): void - { - $table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_sku_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_variant_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('product_category_variant_option_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->create(); - } + public function change(): void { + $table = $this->table('product_sku_variant_values', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_sku_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_variant_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('product_category_variant_option_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->create(); + } + } diff --git a/config/Migrations/20250922045018_CreateProductVariants.php b/config/Migrations/20250922045018_CreateProductVariants.php index 3da6467..5f34a11 100644 --- a/config/Migrations/20250922045018_CreateProductVariants.php +++ b/config/Migrations/20250922045018_CreateProductVariants.php @@ -3,9 +3,9 @@ declare(strict_types=1); use Migrations\BaseMigration; -class CreateProductVariants extends BaseMigration -{ - /** +class CreateProductVariants extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: @@ -13,42 +13,41 @@ class CreateProductVariants extends BaseMigration * * @return void */ - public function change(): void - { - $table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]); - $table->addColumn('id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('name', 'string', [ - 'default' => null, - 'limit' => 255, - 'null' => false, - ]); - $table->addColumn('product_category_variant_id', 'uuid', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('product_id', 'uuid', [ - 'default' => null, - 'null' => false, - ]); - $table->addColumn('enabled', 'boolean', [ - 'default' => null, - 'null' => false, - ]); - $table->addIndex([ - 'product_category_variant_id', - ], [ - 'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID', - 'unique' => false, - ]); - $table->addIndex([ - 'product_id', - ], [ - 'name' => 'VARIANTS_BY_PRODUCT_ID', - 'unique' => false, - ]); + public function change(): void { + $table = $this->table('product_variants', ['id' => false, 'primary_key' => ['id']]); + $table->addColumn('id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false, + ]); + $table->addColumn('product_category_variant_id', 'uuid', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('product_id', 'uuid', [ + 'default' => null, + 'null' => false, + ]); + $table->addColumn('enabled', 'boolean', [ + 'default' => null, + 'null' => false, + ]); + $table->addIndex([ + 'product_category_variant_id', + ], [ + 'name' => 'VARIANTS_BY_PARENT_PRODUCT_CATEGORY_VARIANT_ID', + 'unique' => false, + ]); + $table->addIndex([ + 'product_id', + ], [ + 'name' => 'VARIANTS_BY_PRODUCT_ID', + 'unique' => false, + ]); // $table->addIndex([ // 'name', @@ -57,6 +56,7 @@ class CreateProductVariants extends BaseMigration // 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE', // 'unique' => true, // ]); - $table->create(); - } + $table->create(); + } + } diff --git a/config/Migrations/20251006061008_AddDefaultSkuToProductSkus.php b/config/Migrations/20251006061008_AddDefaultSkuToProductSkus.php index 5740581..ed65b28 100644 --- a/config/Migrations/20251006061008_AddDefaultSkuToProductSkus.php +++ b/config/Migrations/20251006061008_AddDefaultSkuToProductSkus.php @@ -3,23 +3,23 @@ declare(strict_types=1); use Migrations\BaseMigration; -class AddDefaultSkuToProductSkus extends BaseMigration -{ - /** +class AddDefaultSkuToProductSkus extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_skus'); - $table->addColumn('default_sku', 'boolean', [ - 'default' => false, - 'limit' => 11, - 'null' => false, - ]); - $table->update(); - } + public function change(): void { + $table = $this->table('product_skus'); + $table->addColumn('default_sku', 'boolean', [ + 'default' => false, + 'limit' => 11, + 'null' => false, + ]); + $table->update(); + } + } diff --git a/config/Migrations/20251012073807_AddProductCategoryIdToProductPhotos.php b/config/Migrations/20251012073807_AddProductCategoryIdToProductPhotos.php index 6348ea8..4f4600b 100644 --- a/config/Migrations/20251012073807_AddProductCategoryIdToProductPhotos.php +++ b/config/Migrations/20251012073807_AddProductCategoryIdToProductPhotos.php @@ -3,9 +3,9 @@ declare(strict_types=1); use Migrations\BaseMigration; -class AddProductCategoryIdToProductPhotos extends BaseMigration -{ - /** +class AddProductCategoryIdToProductPhotos extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: @@ -13,17 +13,17 @@ class AddProductCategoryIdToProductPhotos extends BaseMigration * * @return void */ - public function change(): void - { - $table = $this->table('product_photos'); - $table->addColumn('product_category_id', 'uuid', [ - 'default' => null, - 'null' => true, - ]); - $table->addColumn('primary_category_photo', 'boolean', [ - 'default' => false, - 'null' => false, - ]); - $table->update(); - } + public function change(): void { + $table = $this->table('product_photos'); + $table->addColumn('product_category_id', 'uuid', [ + 'default' => null, + 'null' => true, + ]); + $table->addColumn('primary_category_photo', 'boolean', [ + 'default' => false, + 'null' => false, + ]); + $table->update(); + } + } diff --git a/config/Migrations/20251101150008_AddPrimarySkuPhotoToProductPhotos.php b/config/Migrations/20251101150008_AddPrimarySkuPhotoToProductPhotos.php index bf88b2b..3729b98 100644 --- a/config/Migrations/20251101150008_AddPrimarySkuPhotoToProductPhotos.php +++ b/config/Migrations/20251101150008_AddPrimarySkuPhotoToProductPhotos.php @@ -3,23 +3,23 @@ declare(strict_types=1); use Migrations\BaseMigration; -class AddPrimarySkuPhotoToProductPhotos extends BaseMigration -{ - /** +class AddPrimarySkuPhotoToProductPhotos extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_photos'); - $table->addColumn('primary_sku_photo', 'boolean', [ - 'default' => false, - 'limit' => 11, - 'null' => false, - ]); - $table->update(); - } + public function change(): void { + $table = $this->table('product_photos'); + $table->addColumn('primary_sku_photo', 'boolean', [ + 'default' => false, + 'limit' => 11, + 'null' => false, + ]); + $table->update(); + } + } diff --git a/config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php b/config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php index a1200b8..47e4b01 100644 --- a/config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php +++ b/config/Migrations/20251101150009_AllowProductIdToBeNullInProductPhotos.php @@ -3,51 +3,50 @@ declare(strict_types=1); use Migrations\BaseMigration; -class AllowProductIdToBeNullInProductPhotos extends BaseMigration -{ - /** - * Change Method. - * - * More information on this method is available here: - * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method - * @return void - */ - public function up(): void - { - $table = $this->table('product_photos'); - $table->changeColumn('product_id', 'uuid', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]); - $table->changeColumn('product_category_id', 'uuid', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]); - $table->update(); - } +class AllowProductIdToBeNullInProductPhotos extends BaseMigration { - /** + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function down(): void - { - $table = $this->table('product_photos'); - $table->changeColumn('product_id', 'uuid', [ - 'default' => null, - 'limit' => 11, - 'null' => false, - ]); - $table->changeColumn('product_category_id', 'uuid', [ - 'default' => null, - 'limit' => 11, - 'null' => true, - ]); - $table->update(); - } + public function up(): void { + $table = $this->table('product_photos'); + $table->changeColumn('product_id', 'uuid', [ + 'default' => null, + 'limit' => 11, + 'null' => true, + ]); + $table->changeColumn('product_category_id', 'uuid', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]); + $table->update(); + } + + /** + * Change Method. + * + * More information on this method is available here: + * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method + * @return void + */ + public function down(): void { + $table = $this->table('product_photos'); + $table->changeColumn('product_id', 'uuid', [ + 'default' => null, + 'limit' => 11, + 'null' => false, + ]); + $table->changeColumn('product_category_id', 'uuid', [ + 'default' => null, + 'limit' => 11, + 'null' => true, + ]); + $table->update(); + } + } diff --git a/config/Migrations/20251103150008_AddIsSystemToProductCategoryVariants.php b/config/Migrations/20251103150008_AddIsSystemToProductCategoryVariants.php index 864f37e..eab6ba7 100644 --- a/config/Migrations/20251103150008_AddIsSystemToProductCategoryVariants.php +++ b/config/Migrations/20251103150008_AddIsSystemToProductCategoryVariants.php @@ -3,23 +3,23 @@ declare(strict_types=1); use Migrations\BaseMigration; -class AddIsSystemToProductCategoryVariants extends BaseMigration -{ - /** +class AddIsSystemToProductCategoryVariants extends BaseMigration { + + /** * Change Method. * * More information on this method is available here: * https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method * @return void */ - public function change(): void - { - $table = $this->table('product_category_variants'); - $table->addColumn('is_system_variant', 'boolean', [ - 'default' => false, - 'limit' => 11, - 'null' => false, - ]); - $table->update(); - } + public function change(): void { + $table = $this->table('product_category_variants'); + $table->addColumn('is_system_variant', 'boolean', [ + 'default' => false, + 'limit' => 11, + 'null' => false, + ]); + $table->update(); + } + } diff --git a/config/Seeds/CreateSystemCategoryVariantsSeed.php b/config/Seeds/CreateSystemCategoryVariantsSeed.php index 0f781fe..71c0173 100644 --- a/config/Seeds/CreateSystemCategoryVariantsSeed.php +++ b/config/Seeds/CreateSystemCategoryVariantsSeed.php @@ -3,14 +3,15 @@ declare(strict_types=1); namespace Seeds; +use Cake\Utility\Text; use Migrations\BaseSeed; /** * CreateSystemCategoryVariants seed. */ -class CreateSystemCategoryVariantsSeed extends BaseSeed -{ - /** +class CreateSystemCategoryVariantsSeed extends BaseSeed { + + /** * Run Method. * * Write your database seeder using this method. @@ -20,36 +21,36 @@ class CreateSystemCategoryVariantsSeed extends BaseSeed * * @return void */ - public function run(): void - { - $data = [ - [ - 'id' => \Cake\Utility\Text::uuid(), - 'name' => 'Subscription Length', - 'product_category_id' => null, - 'enabled' => true, - 'is_system_variant' => true, - ], - [ - 'id' => \Cake\Utility\Text::uuid(), - 'name' => 'Subscription Length Units', - 'product_category_id' => null, - 'enabled' => true, - 'is_system_variant' => true, - ], - ]; - $table = $this->table('product_category_variants'); - $toInsert = []; - foreach ($data as $singleRecordToInsert) { - $stmt = $this->query('SELECT * FROM product_category_variants WHERE name="' . $singleRecordToInsert['name'] . '" AND product_category_id IS NULL;'); // returns PDOStatement - $rows = $stmt->fetchAll(); // returns the result as an array - if ($rows) { - continue; - } - $toInsert[] = $singleRecordToInsert; - } - if ($toInsert) { - $table->insert($data)->save(); - } - } + public function run(): void { + $data = [ + [ + 'id' => Text::uuid(), + 'name' => 'Subscription Length', + 'product_category_id' => null, + 'enabled' => true, + 'is_system_variant' => true, + ], + [ + 'id' => Text::uuid(), + 'name' => 'Subscription Length Units', + 'product_category_id' => null, + 'enabled' => true, + 'is_system_variant' => true, + ], + ]; + $table = $this->table('product_category_variants'); + $toInsert = []; + foreach ($data as $singleRecordToInsert) { + $stmt = $this->query('SELECT * FROM product_category_variants WHERE name="' . $singleRecordToInsert['name'] . '" AND product_category_id IS NULL;'); // returns PDOStatement + $rows = $stmt->fetchAll(); // returns the result as an array + if ($rows) { + continue; + } + $toInsert[] = $singleRecordToInsert; + } + if ($toInsert) { + $table->insert($data)->save(); + } + } + } diff --git a/config/app.example.php b/config/app.example.php index 6f05787..404a730 100644 --- a/config/app.example.php +++ b/config/app.example.php @@ -4,10 +4,10 @@ return [ 'CakeProducts' => [ - 'photos' => [ - 'directory' => WWW_ROOT . 'images' . DS . 'products' . DS, - ], - /** + 'photos' => [ + 'directory' => WWW_ROOT . 'images' . DS . 'products' . DS, + ], + /** * internal CakeProducts settings - used in the source of truth/internal only system. * Can optionally manage external catalogs * @@ -15,17 +15,17 @@ return [ * which will receive changes to the catalogs and optionally allow for external API access. * Will have no effect if true but no external catalogs have been added or none are enabled */ - 'internal' => [ - 'enabled' => true, - /** + 'internal' => [ + 'enabled' => true, + /** * syncExternally defaults to false - product catalogs can have 1 or more external catalogs linked to them * which will receive changes to the catalogs and optionally allow for external API access. * Will have no effect if true but no external catalogs have been added or none are enabled */ - 'syncExternally' => false, - ], - 'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example) - 'enabled' => false, - ], + 'syncExternally' => false, + ], + 'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example) + 'enabled' => false, + ], ], ]; diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..689bfe3 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,21 @@ + + + + + src/ + config/ + tests/ + + /tests/test_files/ + /tests/test_app/ + + + + + */config/Migrations/* + + + */config/Migrations/* + + + diff --git a/src/CakeProductsPlugin.php b/src/CakeProductsPlugin.php index 06adca8..1bae2f1 100644 --- a/src/CakeProductsPlugin.php +++ b/src/CakeProductsPlugin.php @@ -13,9 +13,9 @@ use Cake\Routing\RouteBuilder; /** * Plugin for CakeProducts */ -class CakeProductsPlugin extends BasePlugin -{ - /** +class CakeProductsPlugin extends BasePlugin { + + /** * Load all the plugin configuration and bootstrap logic. * * The host application is provided as an argument. This allows you to load @@ -24,11 +24,10 @@ class CakeProductsPlugin extends BasePlugin * @param \Cake\Core\PluginApplicationInterface $app The host application * @return void */ - public function bootstrap(PluginApplicationInterface $app): void - { - } + public function bootstrap(PluginApplicationInterface $app): void { + } - /** + /** * Add routes for the plugin. * * If your plugin has many routes and you would like to isolate them into a separate file, @@ -37,57 +36,54 @@ class CakeProductsPlugin extends BasePlugin * @param \Cake\Routing\RouteBuilder $routes The route builder to update. * @return void */ - public function routes(RouteBuilder $routes): void - { - $routes->plugin( - 'CakeProducts', - ['path' => '/cake-products'], - function (RouteBuilder $builder) { - // Add custom routes here + public function routes(RouteBuilder $routes): void { + $routes->plugin( + 'CakeProducts', + ['path' => '/cake-products'], + function (RouteBuilder $builder) { + // Add custom routes here - $builder->fallbacks(); - } - ); - parent::routes($routes); - } + $builder->fallbacks(); + }, + ); + parent::routes($routes); + } - /** + /** * Add middleware for the plugin. * * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update. * @return \Cake\Http\MiddlewareQueue */ - public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue - { - // Add your middlewares here + public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue { + // Add your middlewares here - return $middlewareQueue; - } + return $middlewareQueue; + } - /** + /** * Add commands for the plugin. * * @param \Cake\Console\CommandCollection $commands The command collection to update. * @return \Cake\Console\CommandCollection */ - public function console(CommandCollection $commands): CommandCollection - { - // Add your commands here + public function console(CommandCollection $commands): CommandCollection { + // Add your commands here - $commands = parent::console($commands); + $commands = parent::console($commands); - return $commands; - } + return $commands; + } - /** + /** * Register application container services. * + * @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection * @param \Cake\Core\ContainerInterface $container The Container to update. * @return void - * @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection */ - public function services(ContainerInterface $container): void - { - // Add your services here - } + public function services(ContainerInterface $container): void { + // Add your services here + } + } diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index c63822f..d1c21f0 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -5,6 +5,5 @@ namespace CakeProducts\Controller; use App\Controller\AppController as BaseController; -class AppController extends BaseController -{ +class AppController extends BaseController { } diff --git a/src/Controller/ExternalProductCatalogsController.php b/src/Controller/ExternalProductCatalogsController.php index b9446c6..cf7fd39 100644 --- a/src/Controller/ExternalProductCatalogsController.php +++ b/src/Controller/ExternalProductCatalogsController.php @@ -3,130 +3,122 @@ declare(strict_types=1); namespace CakeProducts\Controller; -use Cake\Core\Configure; use Cake\Log\Log; -use Cake\ORM\Table; -use Cake\ORM\TableRegistry; /** * ExternalProductCatalogs Controller * * @property \CakeProducts\Model\Table\ExternalProductCatalogsTable $ExternalProductCatalogs */ -class ExternalProductCatalogsController extends AppController -{ +class ExternalProductCatalogsController extends AppController { + // use OverrideTableTrait; - /** + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.ExternalProductCatalogs'; // $this->_tableConfigKey = 'CakeProducts.ExternalProductCatalogs.table'; - } + } - /** + /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ - public function index() - { - $query = $this->ExternalProductCatalogs->find() - ->contain(['ProductCatalogs']); - $externalProductCatalogs = $this->paginate($query); + public function index() { + $query = $this->ExternalProductCatalogs->find() + ->contain(['ProductCatalogs']); + $externalProductCatalogs = $this->paginate($query); - $this->set(compact('externalProductCatalogs')); - } + $this->set(compact('externalProductCatalogs')); + } - /** + /** * View method * * @param string|null $id External Product Catalog id. - * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Renders view */ - public function view($id = null) - { - $externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']); - $this->set(compact('externalProductCatalog')); - } + public function view($id = null) { + $externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: ['ProductCatalogs']); + $this->set(compact('externalProductCatalog')); + } - /** + /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add() - { - $externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity(); - if ($this->request->is('post')) { - $saveOptions = [ - 'associated' => [ - 'ExternalProductCatalogsProductCatalogs', - ], - ]; - $postData = $this->request->getData(); - Log::debug(print_r('$postData', true)); - Log::debug(print_r($postData, true)); - $externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions); - if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) { - $this->Flash->success(__('The external product catalog has been saved.')); + public function add() { + $externalProductCatalog = $this->ExternalProductCatalogs->newEmptyEntity(); + if ($this->request->is('post')) { + $saveOptions = [ + 'associated' => [ + 'ExternalProductCatalogsProductCatalogs', + ], + ]; + $postData = $this->request->getData(); + Log::debug(print_r('$postData', true)); + Log::debug(print_r($postData, true)); + $externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $postData, $saveOptions); + if ($this->ExternalProductCatalogs->save($externalProductCatalog, $saveOptions)) { + $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)); - $this->Flash->error(__('The external product catalog could not be saved. Please, try again.')); - } - $productCatalogs = $this->ExternalProductCatalogs->ProductCatalogs->find('list', limit: 200)->all(); - $this->set(compact('externalProductCatalog', 'productCatalogs')); - } + return $this->redirect(['action' => 'index']); + } + 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(); + $this->set(compact('externalProductCatalog', 'productCatalogs')); + } - /** + /** * Edit method * * @param string|null $id External Product Catalog id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: []); - if ($this->request->is(['patch', 'post', 'put'])) { - $externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData()); - if ($this->ExternalProductCatalogs->save($externalProductCatalog)) { - $this->Flash->success(__('The external product catalog has been saved.')); + public function edit($id = null) { + $externalProductCatalog = $this->ExternalProductCatalogs->get($id, contain: []); + if ($this->request->is(['patch', 'post', 'put'])) { + $externalProductCatalog = $this->ExternalProductCatalogs->patchEntity($externalProductCatalog, $this->request->getData()); + if ($this->ExternalProductCatalogs->save($externalProductCatalog)) { + $this->Flash->success(__('The external product catalog has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /edit', 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(); - $this->set(compact('externalProductCatalog', 'productCatalogs')); - } + return $this->redirect(['action' => 'index']); + } + Log::debug(print_r('$externalProductCatalog->getErrors() next - failed /edit', 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(); + $this->set(compact('externalProductCatalog', 'productCatalogs')); + } - /** + /** * Delete method * * @param string|null $id External Product Catalog id. - * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $externalProductCatalog = $this->ExternalProductCatalogs->get($id); - if ($this->ExternalProductCatalogs->delete($externalProductCatalog)) { - $this->Flash->success(__('The external product catalog has been deleted.')); - } else { - $this->Flash->error(__('The external product catalog could not be deleted. Please, try again.')); - } + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $externalProductCatalog = $this->ExternalProductCatalogs->get($id); + if ($this->ExternalProductCatalogs->delete($externalProductCatalog)) { + $this->Flash->success(__('The external product catalog has been deleted.')); + } else { + $this->Flash->error(__('The external product catalog could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } - return $this->redirect(['action' => 'index']); - } } diff --git a/src/Controller/ExternalProductCatalogsProductCatalogsController.php b/src/Controller/ExternalProductCatalogsProductCatalogsController.php index d63835a..e4c05e1 100644 --- a/src/Controller/ExternalProductCatalogsProductCatalogsController.php +++ b/src/Controller/ExternalProductCatalogsProductCatalogsController.php @@ -3,49 +3,45 @@ declare(strict_types=1); namespace CakeProducts\Controller; -use Cake\Datasource\Exception\RecordNotFoundException; -use Cake\Http\Response; use Cake\Log\Log; /** * ExternalProductCatalogsProductCatalogs Controller - * */ -class ExternalProductCatalogsProductCatalogsController extends AppController -{ - /** +class ExternalProductCatalogsProductCatalogsController extends AppController { + + /** * Add method * - * @return Response|null|void Redirects on successful add, renders view otherwise. + * @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise. */ - public function add() - { - Log::debug('inside external product catalogs product catalogs controller add'); - $productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray(); - $this->set(compact( 'productCatalogs')); - } + public function add() { + Log::debug('inside external product catalogs product catalogs controller add'); + $productCatalogs = $this->ExternalProductCatalogsProductCatalogs->ProductCatalogs->find('list')->toArray(); + $this->set(compact('productCatalogs')); + } - /** + /** * Delete method * * @param string|null $id Customers Contact id. - * @return Response|null Redirects to index. * @throws RecordNotFoundException When record not found. + * @return Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id); - if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) { - $this->Flash->success(__('The customers contact has been deleted.')); - } else { - $this->Flash->error(__('The customers contact could not be deleted. Please, try again.')); - } + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $externalProductCatalogProductCatalog = $this->ExternalProductCatalogsProductCatalogs->get($id); + if ($this->ExternalProductCatalogsProductCatalogs->delete($externalProductCatalogProductCatalog)) { + $this->Flash->success(__('The customers contact has been deleted.')); + } else { + $this->Flash->error(__('The customers contact could not be deleted. Please, try again.')); + } + + return $this->redirect($this->referer([ + 'controller' => 'ExternalProductCatalogs', + 'action' => 'view', + $externalProductCatalogProductCatalog->external_product_catalog_id, + ])); + } - return $this->redirect($this->referer([ - 'controller' => 'ExternalProductCatalogs', - 'action' => 'view', - $externalProductCatalogProductCatalog->external_product_catalog_id, - ])); - } } diff --git a/src/Controller/ProductCatalogsController.php b/src/Controller/ProductCatalogsController.php index ea70b4c..2469896 100644 --- a/src/Controller/ProductCatalogsController.php +++ b/src/Controller/ProductCatalogsController.php @@ -4,126 +4,116 @@ declare(strict_types=1); namespace CakeProducts\Controller; use Cake\Core\Configure; -use Cake\Datasource\Exception\RecordNotFoundException; -use Cake\Http\Response; use Cake\Log\Log; -use Cake\ORM\Table; -use Cake\ORM\TableRegistry; -use CakeProducts\Model\Table\ProductCatalogsTable; /** * ProductCatalogs Controller * - * @property ProductCatalogsTable $ProductCatalogs + * @property \CakeProducts\Model\Table\ProductCatalogsTable $ProductCatalogs */ -class ProductCatalogsController extends AppController -{ - /** +class ProductCatalogsController extends AppController { + + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.ProductCatalogs'; // $this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table'; - } + } - /** + /** * Index method * - * @return Response|null|void Renders view + * @return \Cake\Http\Response|voidRenders|null view */ - public function index() - { - $query = $this->ProductCatalogs->find(); - $productCatalogs = $this->paginate($query); + public function index() { + $query = $this->ProductCatalogs->find(); + $productCatalogs = $this->paginate($query); - $this->set(compact('productCatalogs')); - } + $this->set(compact('productCatalogs')); + } - /** + /** * View method * * @param string|null $id Product Catalog id. - * @return Response|null|void Renders view * @throws RecordNotFoundException When record not found. + * @return Response|null|void Renders view */ - public function view($id = null) - { - $contain = ['ProductCategories']; - if (Configure::read('CakeProducts.internal.syncExternally', false)) { - $contain[] = 'ExternalProductCatalogs'; - } - $productCatalog = $this->ProductCatalogs->get($id, contain: $contain); - $this->set(compact('productCatalog')); - } + public function view($id = null) { + $contain = ['ProductCategories']; + if (Configure::read('CakeProducts.internal.syncExternally', false)) { + $contain[] = 'ExternalProductCatalogs'; + } + $productCatalog = $this->ProductCatalogs->get($id, contain: $contain); + $this->set(compact('productCatalog')); + } - /** + /** * Add method * - * @return Response|null|void Redirects on successful add, renders view otherwise. + * @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise. */ - public function add() - { - $productCatalogsTable = $this->ProductCatalogs; - $productCatalog = $productCatalogsTable->newEmptyEntity(); - if ($this->request->is('post')) { - $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); - if ($productCatalogsTable->save($productCatalog)) { - $this->Flash->success(__('The product catalog has been saved.')); + public function add() { + $productCatalogsTable = $this->ProductCatalogs; + $productCatalog = $productCatalogsTable->newEmptyEntity(); + if ($this->request->is('post')) { + $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); + if ($productCatalogsTable->save($productCatalog)) { + $this->Flash->success(__('The product catalog has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug('failed to save new product catalog errors next'); - Log::debug(print_r('$productCatalog->getErrors()', true)); - Log::debug(print_r($productCatalog->getErrors(), true)); + return $this->redirect(['action' => 'index']); + } + Log::debug('failed to save new product catalog errors next'); + Log::debug(print_r('$productCatalog->getErrors()', true)); + Log::debug(print_r($productCatalog->getErrors(), true)); - $this->Flash->error(__('The product catalog could not be saved. Please, try again.')); - } - $this->set(compact('productCatalog')); - } + $this->Flash->error(__('The product catalog could not be saved. Please, try again.')); + } + $this->set(compact('productCatalog')); + } - /** + /** * Edit method * * @param string|null $id Product Catalog id. - * @return Response|null|void Redirects on successful edit, renders view otherwise. * @throws RecordNotFoundException When record not found. + * @return Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productCatalogsTable = $this->ProductCatalogs; - $productCatalog = $productCatalogsTable->get($id, contain: []); - if ($this->request->is(['patch', 'post', 'put'])) { - $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); - if ($productCatalogsTable->save($productCatalog)) { - $this->Flash->success(__('The product catalog has been saved.')); + public function edit($id = null) { + $productCatalogsTable = $this->ProductCatalogs; + $productCatalog = $productCatalogsTable->get($id, contain: []); + if ($this->request->is(['patch', 'post', 'put'])) { + $productCatalog = $productCatalogsTable->patchEntity($productCatalog, $this->request->getData()); + if ($productCatalogsTable->save($productCatalog)) { + $this->Flash->success(__('The product catalog has been saved.')); - return $this->redirect(['action' => 'index']); - } - $this->Flash->error(__('The product catalog could not be saved. Please, try again.')); - } - $this->set(compact('productCatalog')); - } + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The product catalog could not be saved. Please, try again.')); + } + $this->set(compact('productCatalog')); + } - /** + /** * Delete method * * @param string|null $id Product Catalog id. - * @return Response|null Redirects to index. * @throws RecordNotFoundException When record not found. + * @return Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $productCatalogsTable = $this->ProductCatalogs; - $productCatalog = $productCatalogsTable->get($id); - if ($productCatalogsTable->delete($productCatalog)) { - $this->Flash->success(__('The product catalog has been deleted.')); - } else { - $this->Flash->error(__('The product catalog could not be deleted. Please, try again.')); - } + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $productCatalogsTable = $this->ProductCatalogs; + $productCatalog = $productCatalogsTable->get($id); + if ($productCatalogsTable->delete($productCatalog)) { + $this->Flash->success(__('The product catalog has been deleted.')); + } else { + $this->Flash->error(__('The product catalog could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } - return $this->redirect(['action' => 'index']); - } } diff --git a/src/Controller/ProductCategoriesController.php b/src/Controller/ProductCategoriesController.php index 986ee02..850f1fc 100644 --- a/src/Controller/ProductCategoriesController.php +++ b/src/Controller/ProductCategoriesController.php @@ -3,10 +3,7 @@ declare(strict_types=1); namespace CakeProducts\Controller; -use Cake\Core\Configure; use Cake\Log\Log; -use Cake\ORM\Table; -use Cake\ORM\TableRegistry; use Cake\Utility\Text; /** @@ -14,163 +11,157 @@ use Cake\Utility\Text; * * @property \CakeProducts\Model\Table\ProductCategoriesTable $ProductCategories */ -class ProductCategoriesController extends AppController -{ - /** +class ProductCategoriesController extends AppController { + + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.ProductCategories'; // $this->_tableConfigKey = 'CakeProducts.ProductCategories.table'; - } + } - /** + /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ - public function index() - { - $query = $this->ProductCategories->find() - ->contain(['ProductCatalogs', 'ParentProductCategories']); - $productCategories = $this->paginate($query); + public function index() { + $query = $this->ProductCategories->find() + ->contain(['ProductCatalogs', 'ParentProductCategories']); + $productCategories = $this->paginate($query); - $this->set(compact('productCategories')); - } + $this->set(compact('productCategories')); + } - /** + /** * View method * * @param string|null $id Product Category id. - * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Renders view */ - public function view($id = null) - { - $productCategory = $this->ProductCategories->get($id, contain: [ - 'ProductCatalogs', - 'ParentProductCategories', - 'ChildProductCategories', - 'ProductCategoryAttributes', - 'ProductCategoryAttributes.ProductCategoryAttributeOptions', - 'PrimaryProductPhotos', - ]); + public function view($id = null) { + $productCategory = $this->ProductCategories->get($id, contain: [ + 'ProductCatalogs', + 'ParentProductCategories', + 'ChildProductCategories', + 'ProductCategoryAttributes', + 'ProductCategoryAttributes.ProductCategoryAttributeOptions', + 'PrimaryProductPhotos', + ]); - $productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id); - $this->set(compact('productCategory', 'productCategoryAttributes')); - } + $productCategoryAttributes = $this->ProductCategories->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($productCategory->internal_id); + $this->set(compact('productCategory', 'productCategoryAttributes')); + } - /** + /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add() - { - $productCategoriesTable = $this->ProductCategories; - $productCategory = $productCategoriesTable->newEmptyEntity(); - if ($this->request->is('post')) { - $postData = $this->request->getData(); - $saveOptions = [ - 'associated' => [], - ]; - if ($this->request->getSession()->read('Auth.User.id')) { - $postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); - } - if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) { - $postData['internal_id'] = Text::uuid(); - } - $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions); - if ($productCategory->getErrors()) { - Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true)); - Log::debug(print_r($productCategory->getErrors(), true)); - } - if ($this->ProductCategories->save($productCategory, $saveOptions)) { - $this->Flash->success(__('The product category has been saved.')); + public function add() { + $productCategoriesTable = $this->ProductCategories; + $productCategory = $productCategoriesTable->newEmptyEntity(); + if ($this->request->is('post')) { + $postData = $this->request->getData(); + $saveOptions = [ + 'associated' => [], + ]; + if ($this->request->getSession()->read('Auth.User.id')) { + $postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); + } + if (!array_key_exists('internal_id', $postData) || !$postData['internal_id']) { + $postData['internal_id'] = Text::uuid(); + } + $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData, $saveOptions); + if ($productCategory->getErrors()) { + Log::debug(print_r('$productCategory->getErrors() next - failed to save from create new product category', true)); + Log::debug(print_r($productCategory->getErrors(), true)); + } + if ($this->ProductCategories->save($productCategory, $saveOptions)) { + $this->Flash->success(__('The product category has been saved.')); - return $this->redirect(['action' => 'index']); - } - $this->Flash->error(__('The product category could not be saved. Please, try again.')); - } - $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); - $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray(); - $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); - } + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The product category could not be saved. Please, try again.')); + } + $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); + $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('treeList', limit: 200)->toArray(); + $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); + } - /** + /** * Edit method * * @param string|null $id Product Category id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productCategoriesTable = $this->ProductCategories; - $productCategory = $productCategoriesTable->get($id, contain: []); - if ($this->request->is(['patch', 'post', 'put'])) { - $postData = $this->request->getData(); - $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData); - if ($productCategoriesTable->save($productCategory)) { - $this->Flash->success(__('The product category has been saved.')); + public function edit($id = null) { + $productCategoriesTable = $this->ProductCategories; + $productCategory = $productCategoriesTable->get($id, contain: []); + if ($this->request->is(['patch', 'post', 'put'])) { + $postData = $this->request->getData(); + $productCategory = $productCategoriesTable->patchEntity($productCategory, $postData); + if ($productCategoriesTable->save($productCategory)) { + $this->Flash->success(__('The product category has been saved.')); - return $this->redirect(['action' => 'index']); - } - $this->Flash->error(__('The product category could not be saved. Please, try again.')); - } - $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); - $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all(); - $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); - } + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The product category could not be saved. Please, try again.')); + } + $productCatalogs = $productCategoriesTable->ProductCatalogs->find('list', limit: 200)->all(); + $parentProductCategories = $productCategoriesTable->ParentProductCategories->find('list', limit: 200)->all(); + $this->set(compact('productCategory', 'productCatalogs', 'parentProductCategories')); + } - /** + /** * Delete method * * @param string|null $id Product Category id. - * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $productCategoriesTable = $this->ProductCategories; + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $productCategoriesTable = $this->ProductCategories; - $productCategory = $productCategoriesTable->get($id); + $productCategory = $productCategoriesTable->get($id); // $productCategoriesTable->behaviors()->get('Tree')->setConfig([ // 'scope' => [ // 'product_catalog_id' => $productCategory->product_catalog_id, // ], // ]); - if ($productCategoriesTable->delete($productCategory)) { - $this->Flash->success(__('The product category has been deleted.')); - } else { - $this->Flash->error(__('The product category could not be deleted. Please, try again.')); - } + if ($productCategoriesTable->delete($productCategory)) { + $this->Flash->success(__('The product category has been deleted.')); + } else { + $this->Flash->error(__('The product category could not be deleted. Please, try again.')); + } - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } - /** + /** * @return \Cake\Http\Response|null|void Renders view */ - public function select() - { - $productCategoriesTable = $this->ProductCategories; - $productCategoriesTable->behaviors()->get('Tree')->setConfig([ - 'scope' => [ - 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), - ], - ]); - $productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ? - $productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') : - $productCategoriesTable->find('treeList'); + public function select() { + $productCategoriesTable = $this->ProductCategories; + $productCategoriesTable->behaviors()->get('Tree')->setConfig([ + 'scope' => [ + 'product_catalog_id' => $this->request->getQuery('product_catalog_id', -1), + ], + ]); + $productCategoriesQ = $this->request->getQuery('form', 'product_category') === 'product' ? + $productCategoriesTable->find('treeList', keyPath: 'internal_id', valuePath: 'name') : + $productCategoriesTable->find('treeList'); - $productCategories = $productCategoriesQ - ->orderBy(['ProductCategories.name']) - ->toArray(); + $productCategories = $productCategoriesQ + ->orderBy(['ProductCategories.name']) + ->toArray(); + + $this->set(compact('productCategories')); + } - $this->set(compact('productCategories')); - } } diff --git a/src/Controller/ProductCategoryAttributeOptionsController.php b/src/Controller/ProductCategoryAttributeOptionsController.php index 7bbed8b..7d76200 100644 --- a/src/Controller/ProductCategoryAttributeOptionsController.php +++ b/src/Controller/ProductCategoryAttributeOptionsController.php @@ -3,60 +3,55 @@ declare(strict_types=1); namespace CakeProducts\Controller; -use Cake\Core\Configure; use Cake\Log\Log; -use Cake\ORM\Table; -use Cake\ORM\TableRegistry; /** * ProductCategoryAttributeOptions Controller * * @property \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable $ProductCategoryAttributeOptions */ -class ProductCategoryAttributeOptionsController extends AppController -{ - /** +class ProductCategoryAttributeOptionsController extends AppController { + + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions'; // $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table'; - } + } - /** + /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add() - { - Log::debug('inside product category attribute options controller add'); + public function add() { + Log::debug('inside product category attribute options controller add'); - $productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity(); - $this->set(compact('productCategoryAttributeOption')); - } + $productCategoryAttributeOption = $this->ProductCategoryAttributeOptions->newEmptyEntity(); + $this->set(compact('productCategoryAttributeOption')); + } - /** + /** * Delete method * * @param string|null $id Product Category Attribute Option id. - * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions; + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $productCategoryAttributeOptionsTable = $this->ProductCategoryAttributeOptions; - $productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id); - if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) { - $this->Flash->success(__('The product category attribute option has been deleted.')); - } else { - $this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.')); - } + $productCategoryAttributeOption = $productCategoryAttributeOptionsTable->get($id); + if ($productCategoryAttributeOptionsTable->delete($productCategoryAttributeOption)) { + $this->Flash->success(__('The product category attribute option has been deleted.')); + } else { + $this->Flash->error(__('The product category attribute option could not be deleted. Please, try again.')); + } + + return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]); + } - return $this->redirect(['controller' => 'ProductCategoryAttributes', 'action' => 'view', $productCategoryAttributeOption->product_category_attribute_id]); - } } diff --git a/src/Controller/ProductCategoryAttributesController.php b/src/Controller/ProductCategoryAttributesController.php index e4cc336..f0f73c6 100644 --- a/src/Controller/ProductCategoryAttributesController.php +++ b/src/Controller/ProductCategoryAttributesController.php @@ -3,172 +3,159 @@ declare(strict_types=1); namespace CakeProducts\Controller; -use Cake\Core\Configure; -use Cake\Datasource\Exception\RecordNotFoundException; -use Cake\Http\Response; use Cake\Log\Log; -use Cake\ORM\Table; -use Cake\ORM\TableRegistry; -use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId; -use CakeProducts\Model\Table\ProductCategoryAttributesTable; /** * ProductCategoryAttributes Controller * - * @property ProductCategoryAttributesTable $ProductCategoryAttributes + * @property \CakeProducts\Model\Table\ProductCategoryAttributesTable $ProductCategoryAttributes */ -class ProductCategoryAttributesController extends AppController -{ - /** +class ProductCategoryAttributesController extends AppController { + + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.ProductCategoryAttributes'; // $this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table'; - } + } - /** + /** * Index method * - * @return Response|null|void Renders view + * @return \Cake\Http\Response|voidRenders|null view */ - public function index() - { - $query = $this->ProductCategoryAttributes->find() - ->contain(['ProductCategories']); - $productCategoryAttributes = $this->paginate($query); + public function index() { + $query = $this->ProductCategoryAttributes->find() + ->contain(['ProductCategories']); + $productCategoryAttributes = $this->paginate($query); - $this->set(compact('productCategoryAttributes')); - } + $this->set(compact('productCategoryAttributes')); + } - /** + /** * View method * * @param string|null $id Product Category Attribute id. - * @return Response|null|void Renders view * @throws RecordNotFoundException When record not found. + * @return Response|null|void Renders view */ - public function view($id = null) - { - $productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [ - 'ProductCategories', - 'ProductCategoryAttributeOptions', - ]); + public function view($id = null) { + $productCategoryAttribute = $this->ProductCategoryAttributes->get($id, contain: [ + 'ProductCategories', + 'ProductCategoryAttributeOptions', + ]); - $this->set(compact('productCategoryAttribute')); - } + $this->set(compact('productCategoryAttribute')); + } - /** + /** * Add method * - * @return Response|null|void Redirects on successful add, renders view otherwise. + * @return \Cake\Http\Response|voidRedirects|null on successful add, renders view otherwise. */ - public function add() - { - $productCategoryAttributesTable = $this->ProductCategoryAttributes; - $productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity(); - if ($this->request->is('post')) { - $postData = $this->request->getData(); - if ($this->request->getSession()->read('Auth.User.id')) { - $postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); - } - Log::debug(print_r('$postData', true)); - Log::debug(print_r($postData, true)); - $saveOptions = [ - 'associated' => [ - 'ProductCategoryAttributeOptions' - ], - ]; - $productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); - if ($productCategoryAttribute->getErrors()) { - Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true)); - Log::debug(print_r($productCategoryAttribute->getErrors(), true)); - } - if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { - $this->Flash->success(__('The product category attribute has been saved.')); + public function add() { + $productCategoryAttributesTable = $this->ProductCategoryAttributes; + $productCategoryAttribute = $productCategoryAttributesTable->newEmptyEntity(); + if ($this->request->is('post')) { + $postData = $this->request->getData(); + if ($this->request->getSession()->read('Auth.User.id')) { + $postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); + } + Log::debug(print_r('$postData', true)); + Log::debug(print_r($postData, true)); + $saveOptions = [ + 'associated' => [ + 'ProductCategoryAttributeOptions', + ], + ]; + $productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); + if ($productCategoryAttribute->getErrors()) { + Log::debug(print_r('$productCategoryAttribute->getErrors() next - failed to save from create new product category attribute', true)); + Log::debug(print_r($productCategoryAttribute->getErrors(), true)); + } + if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { + $this->Flash->success(__('The product category attribute has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug('failed to save new product category attribute errors next'); - Log::debug(print_r('$productCategoryAttribute->getErrors()', true)); - Log::debug(print_r($productCategoryAttribute->getErrors(), true)); - $this->Flash->error(__('The product category attribute could not be saved. Please, try again.')); - } - $productCategories = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); - $this->set(compact('productCategoryAttribute', 'productCategories')); - } + return $this->redirect(['action' => 'index']); + } + Log::debug('failed to save new product category attribute errors next'); + Log::debug(print_r('$productCategoryAttribute->getErrors()', true)); + Log::debug(print_r($productCategoryAttribute->getErrors(), true)); + $this->Flash->error(__('The product category attribute could not be saved. Please, try again.')); + } + $productCategories = $productCategoryAttributesTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); + $this->set(compact('productCategoryAttribute', 'productCategories')); + } - /** + /** * Edit method * * @param string|null $id Product Category Attribute id. - * @return Response|null|void Redirects on successful edit, renders view otherwise. * @throws RecordNotFoundException When record not found. + * @return Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productCategoryAttributesTable = $this->ProductCategoryAttributes; - $productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']); - if ($this->request->is(['patch', 'post', 'put'])) { - $postData = $this->request->getData(); - $saveOptions = [ - 'associated' => ['ProductCategoryAttributeOptions'], - ]; - Log::debug(print_r('$postData', true)); - Log::debug(print_r($postData, true)); + public function edit($id = null) { + $productCategoryAttributesTable = $this->ProductCategoryAttributes; + $productCategoryAttribute = $productCategoryAttributesTable->get($id, contain: ['ProductCategoryAttributeOptions']); + if ($this->request->is(['patch', 'post', 'put'])) { + $postData = $this->request->getData(); + $saveOptions = [ + 'associated' => ['ProductCategoryAttributeOptions'], + ]; + Log::debug(print_r('$postData', true)); + Log::debug(print_r($postData, true)); // if ($this->request->getData('attribute_type_id') != ProductCategoryAttributeTypeId::Constrained) { // $saveOptions['associated'] = []; // $postData['product_category_attribute_options'] = []; // } - Log::debug(print_r('$postData', true)); - Log::debug(print_r($postData, true)); - $productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); + Log::debug(print_r('$postData', true)); + Log::debug(print_r($postData, true)); + $productCategoryAttribute = $productCategoryAttributesTable->patchEntity($productCategoryAttribute, $postData, $saveOptions); - if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { - $this->Flash->success(__('The product category attribute has been saved.')); + if ($productCategoryAttributesTable->save($productCategoryAttribute, $saveOptions)) { + $this->Flash->success(__('The product category attribute has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug('failed to save product category attribute on edit errors next'); - Log::debug(print_r('$productCategoryAttribute->getErrors()', true)); - Log::debug(print_r($productCategoryAttribute->getErrors(), true)); - $this->Flash->error(__('The product category attribute could not be saved. Please, try again.')); - } - $productCategories = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all(); - $this->set(compact('productCategoryAttribute', 'productCategories')); - } + return $this->redirect(['action' => 'index']); + } + Log::debug('failed to save product category attribute on edit errors next'); + Log::debug(print_r('$productCategoryAttribute->getErrors()', true)); + Log::debug(print_r($productCategoryAttribute->getErrors(), true)); + $this->Flash->error(__('The product category attribute could not be saved. Please, try again.')); + } + $productCategories = $productCategoryAttributesTable->ProductCategories->find('list', limit: 200, keyField: 'internal_id', valueField: 'name')->all(); + $this->set(compact('productCategoryAttribute', 'productCategories')); + } - /** + /** * Delete method * * @param string|null $id Product Category Attribute id. - * @return Response|null Redirects to index. * @throws RecordNotFoundException When record not found. + * @return Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); - $productCategoryAttributesTable = $this->ProductCategoryAttributes; - $productCategoryAttribute = $productCategoryAttributesTable->get($id); - if ($productCategoryAttributesTable->delete($productCategoryAttribute)) { - $this->Flash->success(__('The product category attribute has been deleted.')); - } else { - $this->Flash->error(__('The product category attribute could not be deleted. Please, try again.')); - } + $productCategoryAttributesTable = $this->ProductCategoryAttributes; + $productCategoryAttribute = $productCategoryAttributesTable->get($id); + if ($productCategoryAttributesTable->delete($productCategoryAttribute)) { + $this->Flash->success(__('The product category attribute has been deleted.')); + } else { + $this->Flash->error(__('The product category attribute could not be deleted. Please, try again.')); + } - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } - /** + /** * @return void */ - public function form() - { - $productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1')); + public function form() { + $productCategories = $this->ProductCategoryAttributes->getAllCategoryAttributesForCategoryId($this->request->getQuery('product_category_id', '-1')); + + $this->set(compact('productCategories')); + } - $this->set(compact('productCategories')); - } } diff --git a/src/Controller/ProductCategoryVariantsController.php b/src/Controller/ProductCategoryVariantsController.php index aa94160..320955d 100644 --- a/src/Controller/ProductCategoryVariantsController.php +++ b/src/Controller/ProductCategoryVariantsController.php @@ -3,158 +3,150 @@ declare(strict_types=1); namespace CakeProducts\Controller; -use Cake\Core\Configure; use Cake\Log\Log; -use Cake\ORM\Table; -use Cake\ORM\TableRegistry; /** * ProductCategoryVariants Controller * * @property \App\Model\Table\ProductCategoryVariantsTable $ProductCategoryVariants */ -class ProductCategoryVariantsController extends AppController -{ - /** +class ProductCategoryVariantsController extends AppController { + + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.ProductCategoryVariants'; // $this->_tableConfigKey = 'CakeProducts.ProductCategoryVariants.table'; - } + } - /** + /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ - public function index() - { - $query = $this->ProductCategoryVariants->find() - ->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']); - $productCategoryVariants = $this->paginate($query); + public function index() { + $query = $this->ProductCategoryVariants->find() + ->contain(['ProductCategories', 'Products', 'ProductCategoryVariantOptions']); + $productCategoryVariants = $this->paginate($query); - $this->set(compact('productCategoryVariants')); - } + $this->set(compact('productCategoryVariants')); + } - /** + /** * View method * * @param string|null $id Product Category Variant id. - * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Renders view */ - public function view($id = null) - { - $productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [ - 'ProductCategories', - 'Products', - 'ProductCategoryVariantOptions', - ]); - $this->set(compact('productCategoryVariant')); - } + public function view($id = null) { + $productCategoryVariant = $this->ProductCategoryVariants->get($id, contain: [ + 'ProductCategories', + 'Products', + 'ProductCategoryVariantOptions', + ]); + $this->set(compact('productCategoryVariant')); + } - /** + /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add() - { - $productCategoryVariantsTable = $this->ProductCategoryVariants; + public function add() { + $productCategoryVariantsTable = $this->ProductCategoryVariants; - $productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity(); - if ($this->request->is('post')) { - $postData = $this->request->getData(); - if ($this->request->getSession()->read('Auth.User.id')) { - $postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); - } - $saveOptions = [ - 'associated' => [ - 'ProductCategoryVariantOptions' - ], - ]; - $productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); - if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) { - $this->Flash->success(__('The product category variant has been saved.')); + $productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity(); + if ($this->request->is('post')) { + $postData = $this->request->getData(); + if ($this->request->getSession()->read('Auth.User.id')) { + $postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); + } + $saveOptions = [ + 'associated' => [ + 'ProductCategoryVariantOptions', + ], + ]; + $productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); + if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) { + $this->Flash->success(__('The product category variant has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add'); - Log::debug(print_r($productCategoryVariant->getErrors(), true)); - $this->Flash->error(__('The product category variant could not be saved. Please, try again.')); - } - $productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); - $products = $productCategoryVariantsTable->Products->find('list')->all(); - $this->set(compact('productCategoryVariant', 'productCategories', 'products')); - } + return $this->redirect(['action' => 'index']); + } + Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add'); + Log::debug(print_r($productCategoryVariant->getErrors(), true)); + $this->Flash->error(__('The product category variant could not be saved. Please, try again.')); + } + $productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); + $products = $productCategoryVariantsTable->Products->find('list')->all(); + $this->set(compact('productCategoryVariant', 'productCategories', 'products')); + } - /** + /** * Edit method * * @param string|null $id Product Category Variant id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productCategoryVariantsTable = $this->ProductCategoryVariants; - $productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []); - if ($this->request->is(['patch', 'post', 'put'])) { - $postData = $this->request->getData(); + public function edit($id = null) { + $productCategoryVariantsTable = $this->ProductCategoryVariants; + $productCategoryVariant = $productCategoryVariantsTable->get($id, contain: []); + if ($this->request->is(['patch', 'post', 'put'])) { + $postData = $this->request->getData(); // if ($this->request->getSession()->read('Auth.User.id')) { // $postData['created_by'] = $this->request->getSession()->read('Auth.User.id'); // } - $postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData; - $saveOptions = [ - 'fields' => $productCategoryVariant->is_system_variant ? [ - 'product_category_variant_options', - ] : [ - 'name', - 'product_category_id', - 'enabled', - 'product_category_variant_options', - ], - 'associated' => [ - 'ProductCategoryVariantOptions' - ], - ]; - $productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); + $postData = $productCategoryVariant->is_system_variant ? ['product_category_variant_options' => $this->request->getData('product_category_variant_options')] : $postData; + $saveOptions = [ + 'fields' => $productCategoryVariant->is_system_variant ? [ + 'product_category_variant_options', + ] : [ + 'name', + 'product_category_id', + 'enabled', + 'product_category_variant_options', + ], + 'associated' => [ + 'ProductCategoryVariantOptions', + ], + ]; + $productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions); // dd($postData); - if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) { - $this->Flash->success(__('The product category variant has been saved.')); + if ($productCategoryVariantsTable->save($productCategoryVariant, $saveOptions)) { + $this->Flash->success(__('The product category variant has been saved.')); - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } // dd($productCategoryVariant->getErrors()); - $this->Flash->error(__('The product category variant could not be saved. Please, try again.')); - } - $productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); - $products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : []; - $this->set(compact('productCategoryVariant', 'productCategories', 'products')); - } + $this->Flash->error(__('The product category variant could not be saved. Please, try again.')); + } + $productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all(); + $products = isset($productCategoryVariant->product_category_id) ? $productCategoryVariantsTable->Products->find('list', limit: 200)->where(['product_category_id' => $productCategoryVariant->product_category_id])->all() : []; + $this->set(compact('productCategoryVariant', 'productCategories', 'products')); + } - /** + /** * Delete method * * @param string|null $id Product Category Variant id. - * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $productCategoryVariantsTable = $this->ProductCategoryVariants; + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $productCategoryVariantsTable = $this->ProductCategoryVariants; - $productCategoryVariant = $productCategoryVariantsTable->get($id); - if ($productCategoryVariantsTable->delete($productCategoryVariant)) { - $this->Flash->success(__('The product category variant has been deleted.')); - } else { - $this->Flash->error(__('The product category variant could not be deleted. Please, try again.')); - } + $productCategoryVariant = $productCategoryVariantsTable->get($id); + if ($productCategoryVariantsTable->delete($productCategoryVariant)) { + $this->Flash->success(__('The product category variant has been deleted.')); + } else { + $this->Flash->error(__('The product category variant could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } - return $this->redirect(['action' => 'index']); - } } diff --git a/src/Controller/ProductPhotosController.php b/src/Controller/ProductPhotosController.php index b07cd3d..c967ea6 100644 --- a/src/Controller/ProductPhotosController.php +++ b/src/Controller/ProductPhotosController.php @@ -6,209 +6,201 @@ namespace CakeProducts\Controller; use Cake\Core\Configure; use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Http\Exception\ForbiddenException; -use Cake\Http\Response; use Cake\Utility\Text; -use CakeProducts\Model\Table\ProductPhotosTable; -use Psr\Http\Message\UploadedFileInterface; /** * ProductPhotos Controller * - * @property ProductPhotosTable $ProductPhotos + * @property \CakeProducts\Model\Table\ProductPhotosTable $ProductPhotos */ -class ProductPhotosController extends AppController -{ - /** +class ProductPhotosController extends AppController { + + /** * Index method * - * @return Response|null|void Renders view + * @return \Cake\Http\Response|null|void Renders view */ - public function index() - { - $query = $this->ProductPhotos->find() - ->contain(['Products', 'ProductSkus', 'ProductCategories']); - $productPhotos = $this->paginate($query); + public function index() { + $query = $this->ProductPhotos->find() + ->contain(['Products', 'ProductSkus', 'ProductCategories']); + $productPhotos = $this->paginate($query); - $this->set(compact('productPhotos')); - } + $this->set(compact('productPhotos')); + } - /** + /** * View method * * @param string|null $id Product Photo id. - * @return Response|null|void Renders view * @throws RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Renders view */ - public function view($id = null) - { - $productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']); - $this->set(compact('productPhoto')); - } + public function view($id = null) { + $productPhoto = $this->ProductPhotos->get($id, contain: ['Products', 'ProductSkus', 'ProductCategories']); + $this->set(compact('productPhoto')); + } - /** + /** * Add method * - * @return Response|null|void Redirects on successful add, renders view otherwise. + * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add() - { - $productPhotosTable = $this->ProductPhotos; - $productPhoto = $productPhotosTable->newEmptyEntity(); - if ($this->request->is('post')) { - if (!$this->request->getData('photo')) { - $this->Flash->error('Photo is required. Nothing was uploaded. Please try again.'); - $productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; - $productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray(); - $this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); + public function add() { + $productPhotosTable = $this->ProductPhotos; + $productPhoto = $productPhotosTable->newEmptyEntity(); + if ($this->request->is('post')) { + if (!$this->request->getData('photo')) { + $this->Flash->error('Photo is required. Nothing was uploaded. Please try again.'); + $productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; + $productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray(); + $this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); - return; - } - $uuid = Text::uuid(); - $postData = $this->request->getData(); - $postData['id'] = $uuid; - $baseDir = Configure::readOrFail('CakeProducts.photos.directory'); - $path = ''; - if ($this->request->getData('product_sku_id')) { - $productSku = $productPhotosTable->ProductSkus - ->find() - ->contain(['Products', 'Products.ProductCategories']) - ->where([ - 'ProductSkus.id' => $this->request->getData('product_sku_id'), - ]) - ->first(); - $path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path; + return; + } + $uuid = Text::uuid(); + $postData = $this->request->getData(); + $postData['id'] = $uuid; + $baseDir = Configure::readOrFail('CakeProducts.photos.directory'); + $path = ''; + if ($this->request->getData('product_sku_id')) { + $productSku = $productPhotosTable->ProductSkus + ->find() + ->contain(['Products', 'Products.ProductCategories']) + ->where([ + 'ProductSkus.id' => $this->request->getData('product_sku_id'), + ]) + ->first(); + $path = $productSku ? $productSku->product_id . DS . 'skus' . DS . $productSku->id : $path; - $postData['product_id'] = $productSku->product->id ?? null; - $postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null; - } else if ($this->request->getData('product_id')) { - $product = $productPhotosTable->Products - ->find() - ->contain(['ProductCategories']) - ->where([ - 'Products.id' => $this->request->getData('product_id'), - ]) - ->first(); - $path = $product ? $product->id : $path; - $postData['product_category_id'] = $product->product_category->internal_id ?? null; + $postData['product_id'] = $productSku->product->id ?? null; + $postData['product_category_id'] = $productSku->product->product_category->internal_id ?? null; + } else if ($this->request->getData('product_id')) { + $product = $productPhotosTable->Products + ->find() + ->contain(['ProductCategories']) + ->where([ + 'Products.id' => $this->request->getData('product_id'), + ]) + ->first(); + $path = $product ? $product->id : $path; + $postData['product_category_id'] = $product->product_category->internal_id ?? null; - } else if ($this->request->getData('product_category_id')) { - $categoryId = $this->request->getData('product_category_id'); - // @link https://developer.wordpress.org/reference/functions/wp_is_uuid/ - $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'; - $field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id'; - $productCategoryPosted = $productPhotosTable->ProductCategories - ->find() - ->where([ - $field => $categoryId, - ]) - ->first(); - $postData['product_category_id'] = $productCategoryPosted->internal_id ?? null; - $path = $productCategoryPosted ? 'categories' : $path; - } - /** - * @var UploadedFileInterface $photoObject + } else if ($this->request->getData('product_category_id')) { + $categoryId = $this->request->getData('product_category_id'); + // @link https://developer.wordpress.org/reference/functions/wp_is_uuid/ + $regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/'; + $field = preg_match($regex, $categoryId) ? 'ProductCategories.internal_id' : 'ProductCategories.id'; + $productCategoryPosted = $productPhotosTable->ProductCategories + ->find() + ->where([ + $field => $categoryId, + ]) + ->first(); + $postData['product_category_id'] = $productCategoryPosted->internal_id ?? null; + $path = $productCategoryPosted ? 'categories' : $path; + } + /** + * @var \Psr\Http\Message\UploadedFileInterface $photoObject */ - $photoObject = $this->request->getData('photo'); - $ext = substr(strtolower($photoObject->getClientFilename()), -4); - $ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext; - $allowedFileTypes = ['png', 'jpeg', 'jpg']; - if (!in_array($ext, $allowedFileTypes)) { - throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.'); - } + $photoObject = $this->request->getData('photo'); + $ext = substr(strtolower($photoObject->getClientFilename()), -4); + $ext = str_starts_with($ext, '.') ? substr($ext, 1) : $ext; + $allowedFileTypes = ['png', 'jpeg', 'jpg']; + if (!in_array($ext, $allowedFileTypes)) { + throw new ForbiddenException('Invalid file type. Only PNG and JPG types are allowed.'); + } - $fullPath = $baseDir . $path; - if (!file_exists($fullPath)) { - if (!mkdir($fullPath, 0777, true)) { - throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.'); - } - } - $destination = $fullPath . DS . $uuid . '.' . $ext; + $fullPath = $baseDir . $path; + if (!file_exists($fullPath)) { + if (!mkdir($fullPath, 0777, true)) { + throw new ForbiddenException('Failed to create the required folders. Please check the folder permissions and try again.'); + } + } + $destination = $fullPath . DS . $uuid . '.' . $ext; - // Existing files with the same name will be replaced. - $photoObject->moveTo($destination); - if (!file_exists($destination)) { - throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.'); - } + // Existing files with the same name will be replaced. + $photoObject->moveTo($destination); + if (!file_exists($destination)) { + throw new ForbiddenException('Failed to move the uploaded image to the appropriate folder. Please try again.'); + } - $postData['photo_dir'] = $path; - $postData['photo_filename'] = $uuid . '.' . $ext; + $postData['photo_dir'] = $path; + $postData['photo_filename'] = $uuid . '.' . $ext; // dd($postData); - $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); - if ($productPhotosTable->save($productPhoto)) { - $this->Flash->success(__('The product photo has been saved.')); + $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); + if ($productPhotosTable->save($productPhoto)) { + $this->Flash->success(__('The product photo has been saved.')); - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } // dd($productPhoto->getErrors()); - $this->Flash->error(__('The product photo could not be saved. Please, try again.')); - } - $productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; - $productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray(); - $this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); - } + $this->Flash->error(__('The product photo could not be saved. Please, try again.')); + } + $productCategory = $productPhoto->product_category_id ? $productPhotosTable->ProductCategories->find()->where(['internal_id' => $productPhoto->product_category_id ?? '-1'])->first() : null; + $productCatalogs = $productPhotosTable->ProductCategories->ProductCatalogs->find('list')->toArray(); + $this->set(compact('productPhoto', 'productCatalogs', 'productCategory')); + } - /** + /** * Edit method * * @param string|null $id Product Photo id. - * @return Response|null|void Redirects on successful edit, renders view otherwise. * @throws RecordNotFoundException When record not found. + * @return Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productPhotosTable = $this->ProductPhotos; - $productPhoto = $productPhotosTable->get($id, contain: []); - if ($this->request->is(['patch', 'post', 'put'])) { - $postData = $this->request->getData(); + public function edit($id = null) { + $productPhotosTable = $this->ProductPhotos; + $productPhoto = $productPhotosTable->get($id, contain: []); + if ($this->request->is(['patch', 'post', 'put'])) { + $postData = $this->request->getData(); - $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); - if ($productPhotosTable->save($productPhoto)) { - $this->Flash->success(__('The product photo has been saved.')); + $productPhoto = $productPhotosTable->patchEntity($productPhoto, $postData); + if ($productPhotosTable->save($productPhoto)) { + $this->Flash->success(__('The product photo has been saved.')); - return $this->redirect(['action' => 'index']); - } - $this->Flash->error(__('The product photo could not be saved. Please, try again.')); - } - $products = $productPhotosTable->Products->find('list', limit: 200)->all(); - $productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all(); - $this->set(compact('productPhoto', 'products', 'productSkus')); - } + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The product photo could not be saved. Please, try again.')); + } + $products = $productPhotosTable->Products->find('list', limit: 200)->all(); + $productSkus = $productPhotosTable->ProductSkus->find('list', limit: 200)->all(); + $this->set(compact('productPhoto', 'products', 'productSkus')); + } - /** + /** * Delete method * * @param string|null $id Product Photo id. - * @return Response|null Redirects to index. * @throws RecordNotFoundException When record not found. + * @return Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $productPhotosTable = $this->ProductPhotos; + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $productPhotosTable = $this->ProductPhotos; - $productPhoto = $productPhotosTable->get($id); - if ($productPhotosTable->delete($productPhoto)) { - $this->Flash->success(__('The product photo has been deleted.')); - } else { - $this->Flash->error(__('The product photo could not be deleted. Please, try again.')); - } + $productPhoto = $productPhotosTable->get($id); + if ($productPhotosTable->delete($productPhoto)) { + $this->Flash->success(__('The product photo has been deleted.')); + } else { + $this->Flash->error(__('The product photo could not be deleted. Please, try again.')); + } - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } - /** + /** * @param $id * @return Response */ - public function image($id = null) - { - $productPhoto = $this->ProductPhotos->get($id); + public function image($id = null) { + $productPhoto = $this->ProductPhotos->get($id); - $fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename; + $fullPath = Configure::readOrFail('CakeProducts.photos.directory') . $productPhoto->photo_dir . DS . $productPhoto->photo_filename; + + return $this->response->withFile($fullPath, [ + 'download' => $this->request->getQuery('download', false) === '1', + ]); + } - return $this->response->withFile($fullPath, [ - 'download' => $this->request->getQuery('download', false) === '1' - ]); - } } diff --git a/src/Controller/ProductSkusController.php b/src/Controller/ProductSkusController.php index f8991e4..f94a140 100644 --- a/src/Controller/ProductSkusController.php +++ b/src/Controller/ProductSkusController.php @@ -12,240 +12,235 @@ use function BenTools\CartesianProduct\combinations; * * @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus */ -class ProductSkusController extends AppController -{ - /** +class ProductSkusController extends AppController { + + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.ProductSkus'; // $this->_tableConfigKey = 'CakeProducts.ProductSkus.table'; - } + } - /** + /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ - public function index() - { - $query = $this->ProductSkus->find() - ->contain(['Products']); - $productSkus = $this->paginate($query); + public function index() { + $query = $this->ProductSkus->find() + ->contain(['Products']); + $productSkus = $this->paginate($query); - $this->set(compact('productSkus')); - } + $this->set(compact('productSkus')); + } - /** + /** * View method * * @param string|null $id Product Skus id. - * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Renders view */ - public function view($id = null) - { - $productSku = $this->ProductSkus->get($id, contain: [ - 'Products', - 'ProductSkuVariantValues', - 'ProductSkuVariantValues.ProductVariants', - 'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants', - 'ProductSkuVariantValues.ProductCategoryVariantOptions', - ]); - $this->set(compact('productSku')); - } + public function view($id = null) { + $productSku = $this->ProductSkus->get($id, contain: [ + 'Products', + 'ProductSkuVariantValues', + 'ProductSkuVariantValues.ProductVariants', + 'ProductSkuVariantValues.ProductVariants.ProductCategoryVariants', + 'ProductSkuVariantValues.ProductCategoryVariantOptions', + ]); + $this->set(compact('productSku')); + } - /** + /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add($productId = null) - { - $toGetCartesianProductsFrom = []; - $productSkus = []; - $product = $this->ProductSkus->Products->get($productId, contain: [ - 'ProductSkus', - 'ProductSkus.ProductSkuVariantValues', - 'ProductVariants', - 'ProductVariants.ProductCategoryVariants', - 'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions', - ]); - $existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}'); - $existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values'); - $existingSkusForCartesianComparison = []; - foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) { - $existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id'); - } - $productVariants = isset($product->product_variants) ? $product->product_variants : []; + public function add($productId = null) { + $toGetCartesianProductsFrom = []; + $productSkus = []; + $product = $this->ProductSkus->Products->get($productId, contain: [ + 'ProductSkus', + 'ProductSkus.ProductSkuVariantValues', + 'ProductVariants', + 'ProductVariants.ProductCategoryVariants', + 'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions', + ]); + $existingProductSkus = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}'); + $existingProductSkusForMapping = Hash::combine($product->product_skus ?? [], '{n}.id', '{n}.product_sku_variant_values'); + $existingSkusForCartesianComparison = []; + foreach ($existingProductSkusForMapping as $existingProductSkuId => $existingProductSku) { + $existingSkusForCartesianComparison[$existingProductSkuId] = Hash::combine($existingProductSku, '{n}.product_variant_id', '{n}.product_category_variant_option_id'); + } + $productVariants = $product->product_variants ?? []; // dd($productVariants); - $productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id'); - $productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant'); + $productVariantsMapping = Hash::combine($productVariants, '{n}.product_category_variant.id', '{n}.id'); + $productCategoryVariants = Hash::extract($productVariants, '{n}.product_category_variant'); // dd($productCategoryVariants); - $optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value'); + $optionMapping = Hash::combine($productCategoryVariants, '{n}.product_category_variant_options.{n}.id', '{n}.product_category_variant_options.{n}.variant_value'); // dd($optionMapping); - $variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name'); + $variantNameMapping = Hash::combine($productCategoryVariants, '{n}.id', '{n}.name'); // dd($variantNameMapping); - foreach ($productCategoryVariants as $productCategoryVariant) { - $options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id'); - $toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options; - } + foreach ($productCategoryVariants as $productCategoryVariant) { + $options = Hash::extract($productCategoryVariant['product_category_variant_options'] ?? [], '{n}.id'); + $toGetCartesianProductsFrom[$productVariantsMapping[$productCategoryVariant['id']]] = $options; + } // dd($toGetCartesianProductsFrom); - $numSkusToAdd = count(combinations($toGetCartesianProductsFrom)); - for ($i = 0; $i < $numSkusToAdd; $i++) { - $productSkus[$i] = $this->ProductSkus->newEmptyEntity(); - } - $this->set(compact( - 'product', - 'productSkus', - 'productCategoryVariants', - 'productVariantsMapping', - 'toGetCartesianProductsFrom', - 'optionMapping', - 'variantNameMapping', - 'numSkusToAdd', - 'existingProductSkus', - 'existingSkusForCartesianComparison' - )); + $numSkusToAdd = count(combinations($toGetCartesianProductsFrom)); + for ($i = 0; $i < $numSkusToAdd; $i++) { + $productSkus[$i] = $this->ProductSkus->newEmptyEntity(); + } + $this->set(compact( + 'product', + 'productSkus', + 'productCategoryVariants', + 'productVariantsMapping', + 'toGetCartesianProductsFrom', + 'optionMapping', + 'variantNameMapping', + 'numSkusToAdd', + 'existingProductSkus', + 'existingSkusForCartesianComparison', + )); - if ($this->request->is('post')) { - $postedSkus = $this->request->getData(); - $saveOptions = [ - 'fields' => [ - 'product_id', - 'sku', - 'barcode', - 'price', - 'cost', - 'product_sku_variant_values', - 'created', - 'modified', - 'enabled', - 'default_sku', - ], - 'associated' => [ - 'ProductSkuVariantValues' => [ - 'fields' => [ - 'product_variant_id', - 'product_category_variant_option_id', - ], - ], - ], - ]; - $finalPostData = []; - $postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId); + if ($this->request->is('post')) { + $postedSkus = $this->request->getData(); + $saveOptions = [ + 'fields' => [ + 'product_id', + 'sku', + 'barcode', + 'price', + 'cost', + 'product_sku_variant_values', + 'created', + 'modified', + 'enabled', + 'default_sku', + ], + 'associated' => [ + 'ProductSkuVariantValues' => [ + 'fields' => [ + 'product_variant_id', + 'product_category_variant_option_id', + ], + ], + ], + ]; + $finalPostData = []; + $postedSkus = Hash::insert($postedSkus, '{n}.product_id', $productId); - foreach ($postedSkus as $postedSkuCnt => $postedSku) { - if (!isset($postedSku['sku']) || !$postedSku['sku']) { - unset($productSkus[$postedSkuCnt]); + foreach ($postedSkus as $postedSkuCnt => $postedSku) { + if (!isset($postedSku['sku']) || !$postedSku['sku']) { + unset($productSkus[$postedSkuCnt]); - continue; - } - $finalPostData[$postedSkuCnt] = $postedSku; - } - if (!$productSkus || !$postedSkus) { - $this->Flash->error('Nothing to save! Add at least one SKU next time.'); + continue; + } + $finalPostData[$postedSkuCnt] = $postedSku; + } + if (!$productSkus || !$postedSkus) { + $this->Flash->error('Nothing to save! Add at least one SKU next time.'); - return; - } + return; + } // dd($finalPostData); - $productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions); - $errors = []; - $successes = []; - foreach ($productSkus as $productSkuToSave) { + $productSkus = $this->ProductSkus->patchEntities($productSkus, $finalPostData, $saveOptions); + $errors = []; + $successes = []; + foreach ($productSkus as $productSkuToSave) { // dd($productSkuToSave); - if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) { - Log::debug(print_r('$productSkuToSave->getErrors()', true)); - Log::debug(print_r($productSkuToSave->getErrors(), true)); - dd($productSkuToSave->getErrors()); - continue; - } - $successes[] = $productSkuToSave; - } + if (!$this->ProductSkus->save($productSkuToSave, $saveOptions)) { + Log::debug(print_r('$productSkuToSave->getErrors()', true)); + Log::debug(print_r($productSkuToSave->getErrors(), true)); + dd($productSkuToSave->getErrors()); - if ($successes) { - $this->Flash->success(__(count($successes) . ' New SKUs have been saved.')); + continue; + } + $successes[] = $productSkuToSave; + } - return $this->redirect(['action' => 'index']); - } + if ($successes) { + $this->Flash->success(__(count($successes) . ' New SKUs have been saved.')); - $this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.')); - } - $this->set(compact( - 'productSkus' - )); - } + return $this->redirect(['action' => 'index']); + } - /** + $this->Flash->error(__('The product SKU(s) could not be saved. Please, try again.')); + } + $this->set(compact( + 'productSkus', + )); + } + + /** * Edit method * * @param string|null $id Product Skus id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productSku = $this->ProductSkus->get($id, contain: []); - if ($this->request->is(['patch', 'post', 'put'])) { - $postData = $this->request->getData(); - $saveOptions = [ - 'associated' => [], - ]; - // Log::debug(print_r('$postData', true)); + public function edit($id = null) { + $productSku = $this->ProductSkus->get($id, contain: []); + if ($this->request->is(['patch', 'post', 'put'])) { + $postData = $this->request->getData(); + $saveOptions = [ + 'associated' => [], + ]; + // Log::debug(print_r('$postData', true)); // Log::debug(print_r($postData, true)); // Log::debug(print_r('$saveOptions', true)); // Log::debug(print_r($saveOptions, true)); - $productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions); - if ($this->ProductSkus->save($productSku)) { - $this->Flash->success(__('The product skus has been saved.')); + $productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions); + if ($this->ProductSkus->save($productSku)) { + $this->Flash->success(__('The product skus has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true)); - Log::debug(print_r($productSku->getErrors(), true)); - $this->Flash->error(__('The product skus could not be saved. Please, try again.')); - } - $products = $this->ProductSkus->Products->find('list', limit: 200)->all(); - $this->set(compact('productSku', 'products')); - } + return $this->redirect(['action' => 'index']); + } + Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true)); + Log::debug(print_r($productSku->getErrors(), true)); + $this->Flash->error(__('The product skus could not be saved. Please, try again.')); + } + $products = $this->ProductSkus->Products->find('list', limit: 200)->all(); + $this->set(compact('productSku', 'products')); + } - /** + /** * Delete method * * @param string|null $id Product Skus id. - * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $productSku = $this->ProductSkus->get($id); - if ($this->ProductSkus->delete($productSku)) { - $this->Flash->success(__('The product skus has been deleted.')); - } else { - $this->Flash->error(__('The product skus could not be deleted. Please, try again.')); - } + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $productSku = $this->ProductSkus->get($id); + if ($this->ProductSkus->delete($productSku)) { + $this->Flash->success(__('The product skus has been deleted.')); + } else { + $this->Flash->error(__('The product skus could not be deleted. Please, try again.')); + } - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } - /** + /** * @return \Cake\Http\Response|null|void Renders view */ - public function select() - { - $productSkus = $this->ProductSkus - ->find('list') - ->where(['product_id' => $this->request->getQuery('product_id', '-1')]) - ->orderBy(['sku']) - ->toArray(); + public function select() { + $productSkus = $this->ProductSkus + ->find('list') + ->where(['product_id' => $this->request->getQuery('product_id', '-1')]) + ->orderBy(['sku']) + ->toArray(); + + $this->set(compact('productSkus')); + } - $this->set(compact('productSkus')); - } } diff --git a/src/Controller/ProductVariantsController.php b/src/Controller/ProductVariantsController.php index d74ab84..f4e7d80 100644 --- a/src/Controller/ProductVariantsController.php +++ b/src/Controller/ProductVariantsController.php @@ -10,109 +10,105 @@ use Cake\Log\Log; * * @property \App\Model\Table\ProductVariantsTable $ProductVariants */ -class ProductVariantsController extends AppController -{ - /** +class ProductVariantsController extends AppController { + + /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ - public function index() - { - $query = $this->ProductVariants->find() - ->contain(['ProductCategoryVariants', 'Products']); - $productVariants = $this->paginate($query); + public function index() { + $query = $this->ProductVariants->find() + ->contain(['ProductCategoryVariants', 'Products']); + $productVariants = $this->paginate($query); - $this->set(compact('productVariants')); - } + $this->set(compact('productVariants')); + } - /** + /** * View method * * @param string|null $id Product Variant id. - * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Renders view */ - public function view($id = null) - { - $productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']); - $this->set(compact('productVariant')); - } + public function view($id = null) { + $productVariant = $this->ProductVariants->get($id, contain: ['ProductCategoryVariants', 'Products']); + $this->set(compact('productVariant')); + } - /** + /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add($productId) - { - $product = $this->ProductVariants->Products->get($productId); - $productVariant = $this->ProductVariants->newEmptyEntity(); - if ($this->request->is('post')) { - $saveOptions = []; - $postData = $this->request->getData(); - $productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1')); - $postData['name'] = $productCategoryVariant->name; - $postData['product_id'] = $productId; - $productVariant = $this->ProductVariants->patchEntity($productVariant, $postData); - if ($this->ProductVariants->save($productVariant)) { - $this->Flash->success(__('The product variant has been saved.')); + public function add($productId) { + $product = $this->ProductVariants->Products->get($productId); + $productVariant = $this->ProductVariants->newEmptyEntity(); + if ($this->request->is('post')) { + $saveOptions = []; + $postData = $this->request->getData(); + $productCategoryVariant = $this->ProductVariants->ProductCategoryVariants->get($this->request->getData('product_category_variant_id', '-1')); + $postData['name'] = $productCategoryVariant->name; + $postData['product_id'] = $productId; + $productVariant = $this->ProductVariants->patchEntity($productVariant, $postData); + if ($this->ProductVariants->save($productVariant)) { + $this->Flash->success(__('The product variant has been saved.')); - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } - Log::debug(print_r('$productVariant->getErrors()', true)); - Log::debug(print_r($productVariant->getErrors(), true)); - $this->Flash->error(__('The product variant could not be saved. Please, try again.')); - } - $productCategoryVariants = $this->ProductVariants->ProductCategoryVariants - ->find('list', limit: 200) - ->where(['product_category_id' => $product->product_category_id]) - ->toArray(); - $this->set(compact('productVariant', 'productCategoryVariants', 'product')); - } + Log::debug(print_r('$productVariant->getErrors()', true)); + Log::debug(print_r($productVariant->getErrors(), true)); + $this->Flash->error(__('The product variant could not be saved. Please, try again.')); + } + $productCategoryVariants = $this->ProductVariants->ProductCategoryVariants + ->find('list', limit: 200) + ->where(['product_category_id' => $product->product_category_id]) + ->toArray(); + $this->set(compact('productVariant', 'productCategoryVariants', 'product')); + } - /** + /** * Edit method * * @param string|null $id Product Variant id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productVariant = $this->ProductVariants->get($id, contain: []); - if ($this->request->is(['patch', 'post', 'put'])) { - $productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData()); - if ($this->ProductVariants->save($productVariant)) { - $this->Flash->success(__('The product variant has been saved.')); + public function edit($id = null) { + $productVariant = $this->ProductVariants->get($id, contain: []); + if ($this->request->is(['patch', 'post', 'put'])) { + $productVariant = $this->ProductVariants->patchEntity($productVariant, $this->request->getData()); + if ($this->ProductVariants->save($productVariant)) { + $this->Flash->success(__('The product variant has been saved.')); - return $this->redirect(['action' => 'index']); - } - $this->Flash->error(__('The product variant could not be saved. Please, try again.')); - } - $productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all(); - $products = $this->ProductVariants->Products->find('list', limit: 200)->all(); - $this->set(compact('productVariant', 'productCategoryVariants', 'products')); - } + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The product variant could not be saved. Please, try again.')); + } + $productCategoryVariants = $this->ProductVariants->ProductCategoryVariants->find('list', limit: 200)->all(); + $products = $this->ProductVariants->Products->find('list', limit: 200)->all(); + $this->set(compact('productVariant', 'productCategoryVariants', 'products')); + } - /** + /** * Delete method * * @param string|null $id Product Variant id. - * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); - $productVariant = $this->ProductVariants->get($id); - if ($this->ProductVariants->delete($productVariant)) { - $this->Flash->success(__('The product variant has been deleted.')); - } else { - $this->Flash->error(__('The product variant could not be deleted. Please, try again.')); - } + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); + $productVariant = $this->ProductVariants->get($id); + if ($this->ProductVariants->delete($productVariant)) { + $this->Flash->success(__('The product variant has been deleted.')); + } else { + $this->Flash->error(__('The product variant could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } - return $this->redirect(['action' => 'index']); - } } diff --git a/src/Controller/ProductsController.php b/src/Controller/ProductsController.php index 4046a6f..cb63a2d 100644 --- a/src/Controller/ProductsController.php +++ b/src/Controller/ProductsController.php @@ -3,211 +3,202 @@ declare(strict_types=1); namespace CakeProducts\Controller; -use Cake\Core\Configure; use Cake\Log\Log; -use Cake\ORM\Table; -use Cake\ORM\TableRegistry; /** * Products Controller * * @property \CakeProducts\Model\Table\ProductsTable $Products */ -class ProductsController extends AppController -{ - /** +class ProductsController extends AppController { + + /** * @return void */ - public function initialize(): void - { - parent::initialize(); // TODO: Change the autogenerated stub + public function initialize(): void { + parent::initialize(); // TODO: Change the autogenerated stub // $this->_defaultTable = 'CakeProducts.Products'; // $this->_tableConfigKey = 'CakeProducts.Products.table'; - } + } - /** + /** * Index method * * @return \Cake\Http\Response|null|void Renders view */ - public function index() - { - $query = $this->Products->find() - ->contain(['ProductCategories']); - $products = $this->paginate($query); + public function index() { + $query = $this->Products->find() + ->contain(['ProductCategories']); + $products = $this->paginate($query); - $this->set(compact('products')); - } + $this->set(compact('products')); + } - /** + /** * View method * * @param string|null $id Product id. - * @return \Cake\Http\Response|null|void Renders view * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Renders view */ - public function view($id = null) - { - $product = $this->Products->get($id, contain: [ - 'ProductCategories', - 'ProductAttributes', - 'ProductAttributes.ProductCategoryAttributes', - 'ProductAttributes.ProductCategoryAttributeOptions', - 'ProductVariants', - 'ProductVariants.ProductCategoryVariants', - 'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions', - 'ProductSkus', - 'ProductPhotos', - ]); - $this->set(compact('product')); - } + public function view($id = null) { + $product = $this->Products->get($id, contain: [ + 'ProductCategories', + 'ProductAttributes', + 'ProductAttributes.ProductCategoryAttributes', + 'ProductAttributes.ProductCategoryAttributeOptions', + 'ProductVariants', + 'ProductVariants.ProductCategoryVariants', + 'ProductVariants.ProductCategoryVariants.ProductCategoryVariantOptions', + 'ProductSkus', + 'ProductPhotos', + ]); + $this->set(compact('product')); + } - /** + /** * Add method * * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. */ - public function add() - { - $productsTable = $this->Products; - $product = $productsTable->newEmptyEntity(); - if ($this->request->is('post')) { - $postData = $this->request->getData(); - $saveOptions = [ - 'associated' => ['ProductAttributes'], - ]; - Log::debug(print_r('$postData', true)); - Log::debug(print_r($postData, true)); - Log::debug(print_r('$saveOptions', true)); - Log::debug(print_r($saveOptions, true)); - $productVariantsData = []; - if (isset($postData['product_variants']) && $postData['product_variants']) { - foreach ($postData['product_variants'] as $postedProductVariant) { - if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) { - continue; - } - $existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']); - $optionsData = []; - foreach ($existingVariant->product_category_variant_options as $existingOption) { - $optionsData[] = [ - 'variant_value' => $existingOption->variant_value, - 'variant_label' => $existingOption->variant_label ?? null, - 'enabled' => $existingOption->enabled, - ]; - } - $tmpVariantData = [ - 'name' => $existingVariant->name, - 'product_category_variant_id' => $postedProductVariant['product_category_variant_id'], - 'enabled' => true, - 'product_category_variant_options' => $optionsData, - ]; - $productVariantsData[] = $tmpVariantData; - } - } - if ($productVariantsData) { - $saveOptions['fields'] = [ - 'name', - 'product_category_id', - 'product_type_id', - 'product_attributes', - 'product_category_variants' - ]; - $saveOptions['associated']['ProductCategoryVariants'] = [ - 'fields' => [ - 'name', - 'enabled', - 'product_category_variant_options', - ] - ]; - $saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions'; - $postData['product_category_variants'] = $productVariantsData; - } - $product = $productsTable->patchEntity($product, $postData, $saveOptions); - if ($productsTable->save($product, $saveOptions)) { - $this->Flash->success(__('The product has been saved.')); + public function add() { + $productsTable = $this->Products; + $product = $productsTable->newEmptyEntity(); + if ($this->request->is('post')) { + $postData = $this->request->getData(); + $saveOptions = [ + 'associated' => ['ProductAttributes'], + ]; + Log::debug(print_r('$postData', true)); + Log::debug(print_r($postData, true)); + Log::debug(print_r('$saveOptions', true)); + Log::debug(print_r($saveOptions, true)); + $productVariantsData = []; + if (isset($postData['product_variants']) && $postData['product_variants']) { + foreach ($postData['product_variants'] as $postedProductVariant) { + if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) { + continue; + } + $existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']); + $optionsData = []; + foreach ($existingVariant->product_category_variant_options as $existingOption) { + $optionsData[] = [ + 'variant_value' => $existingOption->variant_value, + 'variant_label' => $existingOption->variant_label ?? null, + 'enabled' => $existingOption->enabled, + ]; + } + $tmpVariantData = [ + 'name' => $existingVariant->name, + 'product_category_variant_id' => $postedProductVariant['product_category_variant_id'], + 'enabled' => true, + 'product_category_variant_options' => $optionsData, + ]; + $productVariantsData[] = $tmpVariantData; + } + } + if ($productVariantsData) { + $saveOptions['fields'] = [ + 'name', + 'product_category_id', + 'product_type_id', + 'product_attributes', + 'product_category_variants', + ]; + $saveOptions['associated']['ProductCategoryVariants'] = [ + 'fields' => [ + 'name', + 'enabled', + 'product_category_variant_options', + ], + ]; + $saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions'; + $postData['product_category_variants'] = $productVariantsData; + } + $product = $productsTable->patchEntity($product, $postData, $saveOptions); + if ($productsTable->save($product, $saveOptions)) { + $this->Flash->success(__('The product has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug(print_r('$product->getErrors() next - failed in products/add', true)); - Log::debug(print_r($product->getErrors(), true)); - $this->Flash->error(__('The product could not be saved. Please, try again.')); - } - $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null; - $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); - $this->set(compact('product', 'productCatalogs', 'productCategory')); - } + return $this->redirect(['action' => 'index']); + } + Log::debug(print_r('$product->getErrors() next - failed in products/add', true)); + Log::debug(print_r($product->getErrors(), true)); + $this->Flash->error(__('The product could not be saved. Please, try again.')); + } + $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null; + $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); + $this->set(compact('product', 'productCatalogs', 'productCategory')); + } - /** + /** * Edit method * * @param string|null $id Product id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. */ - public function edit($id = null) - { - $productsTable = $this->Products; - $product = $productsTable->get($id, contain: [ - 'ProductAttributes', - 'ProductAttributes.ProductCategoryAttributes', - 'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions', - ]); - if ($this->request->is(['patch', 'post', 'put'])) { - $saveOptions = [ - 'associated' => ['ProductAttributes'], - ]; - $product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions); - if ($productsTable->save($product)) { - $this->Flash->success(__('The product has been saved.')); + public function edit($id = null) { + $productsTable = $this->Products; + $product = $productsTable->get($id, contain: [ + 'ProductAttributes', + 'ProductAttributes.ProductCategoryAttributes', + 'ProductAttributes.ProductCategoryAttributes.ProductCategoryAttributeOptions', + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $saveOptions = [ + 'associated' => ['ProductAttributes'], + ]; + $product = $productsTable->patchEntity($product, $this->request->getData(), $saveOptions); + if ($productsTable->save($product)) { + $this->Flash->success(__('The product has been saved.')); - return $this->redirect(['action' => 'index']); - } - Log::debug(print_r('$product->getErrors() next - failed in products/edit', true)); - Log::debug(print_r($product->getErrors(), true)); - $this->Flash->error(__('The product could not be saved. Please, try again.')); - } - $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null; - $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); - $this->set(compact('product', 'productCatalogs', 'productCategory')); - } + return $this->redirect(['action' => 'index']); + } + Log::debug(print_r('$product->getErrors() next - failed in products/edit', true)); + Log::debug(print_r($product->getErrors(), true)); + $this->Flash->error(__('The product could not be saved. Please, try again.')); + } + $productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null; + $productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray(); + $this->set(compact('product', 'productCatalogs', 'productCategory')); + } - /** + /** * Delete method * * @param string|null $id Product id. - * @return \Cake\Http\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return \Cake\Http\Response|null Redirects to index. */ - public function delete($id = null) - { - $this->request->allowMethod(['post', 'delete']); + public function delete($id = null) { + $this->request->allowMethod(['post', 'delete']); - $productsTable = $this->Products; - $product = $productsTable->get($id); - if ($productsTable->delete($product)) { - $this->Flash->success(__('The product has been deleted.')); - } else { - $this->Flash->error(__('The product could not be deleted. Please, try again.')); - } + $productsTable = $this->Products; + $product = $productsTable->get($id); + if ($productsTable->delete($product)) { + $this->Flash->success(__('The product has been deleted.')); + } else { + $this->Flash->error(__('The product could not be deleted. Please, try again.')); + } - return $this->redirect(['action' => 'index']); - } + return $this->redirect(['action' => 'index']); + } - /** + /** * @return \Cake\Http\Response|null|void Renders view */ - public function select() - { - $productsTable = $this->Products; - $productCategory = $productsTable->ProductCategories->find() - ->where(['id' => $this->request->getQuery('product_category_id', '-1')]) - ->first(); - $products = $productsTable - ->find('list') - ->where(['product_category_id' => $productCategory->internal_id ?? '-1']) - ->orderBy(['Products.name']) - ->toArray(); + public function select() { + $productsTable = $this->Products; + $productCategory = $productsTable->ProductCategories->find() + ->where(['id' => $this->request->getQuery('product_category_id', '-1')]) + ->first(); + $products = $productsTable + ->find('list') + ->where(['product_category_id' => $productCategory->internal_id ?? '-1']) + ->orderBy(['Products.name']) + ->toArray(); + + $this->set(compact('products')); + } - $this->set(compact('products')); - } } diff --git a/src/Model/Behavior/SecondToggleBehavior.php b/src/Model/Behavior/SecondToggleBehavior.php index 64c6b79..de43c25 100644 --- a/src/Model/Behavior/SecondToggleBehavior.php +++ b/src/Model/Behavior/SecondToggleBehavior.php @@ -2,11 +2,7 @@ namespace CakeProducts\Model\Behavior; -use ArrayObject; use Cake\Datasource\EntityInterface; -use Cake\Event\EventInterface; -use Cake\ORM\Behavior; -use LogicException; use Tools\Model\Behavior\ToggleBehavior; /** @@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior; */ class SecondToggleBehavior extends ToggleBehavior { - /** + /** * Default config * * @var array */ - protected array $_defaultConfig = [ - 'field' => 'primary', - 'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions) - 'scopeFields' => [], - 'scope' => [], - 'findOrder' => null, // null = autodetect modified/created, false to disable - 'implementedMethods' => [], // to prevent conflict with public toggleField method - ]; + protected array $_defaultConfig = [ + 'field' => 'primary', + 'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions) + 'scopeFields' => [], + 'scope' => [], + 'findOrder' => null, // null = autodetect modified/created, false to disable + 'implementedMethods' => [], // to prevent conflict with public toggleField method + ]; - /** + /** * @param \Cake\Datasource\EntityInterface $entity * * @return array */ - protected function buildConditions(EntityInterface $entity) { - $conditions = $this->getConfig('scope'); - $scopeFields = (array)$this->getConfig('scopeFields'); + protected function buildConditions(EntityInterface $entity) { + $conditions = $this->getConfig('scope'); + $scopeFields = (array)$this->getConfig('scopeFields'); - foreach ($scopeFields as $scopeField) { - if ($entity->get($scopeField) === null) { - continue; - } - $conditions[$scopeField] = $entity->get($scopeField); - } + foreach ($scopeFields as $scopeField) { + if ($entity->get($scopeField) === null) { + continue; + } + $conditions[$scopeField] = $entity->get($scopeField); + } // dd($conditions); - return $conditions; - } + return $conditions; + } + } diff --git a/src/Model/Behavior/ThirdToggleBehavior.php b/src/Model/Behavior/ThirdToggleBehavior.php index 59a1364..3b6c402 100644 --- a/src/Model/Behavior/ThirdToggleBehavior.php +++ b/src/Model/Behavior/ThirdToggleBehavior.php @@ -2,11 +2,7 @@ namespace CakeProducts\Model\Behavior; -use ArrayObject; use Cake\Datasource\EntityInterface; -use Cake\Event\EventInterface; -use Cake\ORM\Behavior; -use LogicException; use Tools\Model\Behavior\ToggleBehavior; /** @@ -21,37 +17,38 @@ use Tools\Model\Behavior\ToggleBehavior; */ class ThirdToggleBehavior extends ToggleBehavior { - /** + /** * Default config * * @var array */ - protected array $_defaultConfig = [ - 'field' => 'primary', - 'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions) - 'scopeFields' => [], - 'scope' => [], - 'findOrder' => null, // null = autodetect modified/created, false to disable - 'implementedMethods' => [], // to prevent conflict with public toggleField method - ]; + protected array $_defaultConfig = [ + 'field' => 'primary', + 'on' => 'afterSave', // afterSave (without transactions) or beforeSave (with transactions) + 'scopeFields' => [], + 'scope' => [], + 'findOrder' => null, // null = autodetect modified/created, false to disable + 'implementedMethods' => [], // to prevent conflict with public toggleField method + ]; - /** + /** * @param \Cake\Datasource\EntityInterface $entity * * @return array */ - protected function buildConditions(EntityInterface $entity) { - $conditions = $this->getConfig('scope'); - $scopeFields = (array)$this->getConfig('scopeFields'); + protected function buildConditions(EntityInterface $entity) { + $conditions = $this->getConfig('scope'); + $scopeFields = (array)$this->getConfig('scopeFields'); - foreach ($scopeFields as $scopeField) { - if ($entity->get($scopeField) === null) { - continue; - } - $conditions[$scopeField] = $entity->get($scopeField); - } + foreach ($scopeFields as $scopeField) { + if ($entity->get($scopeField) === null) { + continue; + } + $conditions[$scopeField] = $entity->get($scopeField); + } // dd($conditions); - return $conditions; - } + return $conditions; + } + } diff --git a/src/Model/Entity/ExternalProductCatalog.php b/src/Model/Entity/ExternalProductCatalog.php index 69f2b8a..e0f6401 100644 --- a/src/Model/Entity/ExternalProductCatalog.php +++ b/src/Model/Entity/ExternalProductCatalog.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -12,15 +11,15 @@ use Cake\ORM\Entity; * @property int $id * @property string $base_url * @property string $api_url - * @property DateTime $created - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime $created + * @property \Cake\I18n\DateTime|null $deleted * * @property ProductCatalog[] $product_catalogs * @property ExternalProductCatalogsProductCatalog[] $external_product_catalogs_product_catalogs */ -class ExternalProductCatalog extends Entity -{ - /** +class ExternalProductCatalog extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -29,14 +28,15 @@ class ExternalProductCatalog extends Entity * * @var array */ - protected array $_accessible = [ - 'base_url' => true, - 'api_url' => true, - 'created' => true, - 'deleted' => true, - 'enabled' => true, + protected array $_accessible = [ + 'base_url' => true, + 'api_url' => true, + 'created' => true, + 'deleted' => true, + 'enabled' => true, + + // entities + 'external_product_catalogs_product_catalogs' => true, + ]; - // entities - 'external_product_catalogs_product_catalogs' => true, - ]; } diff --git a/src/Model/Entity/ExternalProductCatalogsProductCatalog.php b/src/Model/Entity/ExternalProductCatalogsProductCatalog.php index 101d45f..8bcee3d 100644 --- a/src/Model/Entity/ExternalProductCatalogsProductCatalog.php +++ b/src/Model/Entity/ExternalProductCatalogsProductCatalog.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -12,16 +11,16 @@ use Cake\ORM\Entity; * @property int $id * @property string $external_product_catalog_id * @property string $product_catalog_id - * @property DateTime $created + * @property \Cake\I18n\DateTime $created * @property bool $enabled - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime|null $deleted * * @property ExternalProductCatalog $external_product_catalog * @property ProductCatalog $product_catalog */ -class ExternalProductCatalogsProductCatalog extends Entity -{ - /** +class ExternalProductCatalogsProductCatalog extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -30,15 +29,16 @@ class ExternalProductCatalogsProductCatalog extends Entity * * @var array */ - protected array $_accessible = [ - 'external_product_catalog_id' => true, - 'product_catalog_id' => true, - 'created' => true, - 'enabled' => true, - 'deleted' => true, + protected array $_accessible = [ + 'external_product_catalog_id' => true, + 'product_catalog_id' => true, + 'created' => true, + 'enabled' => true, + 'deleted' => true, + + // entities + 'external_product_catalog' => true, + 'product_catalog' => true, + ]; - // entities - 'external_product_catalog' => true, - 'product_catalog' => true, - ]; } diff --git a/src/Model/Entity/Product.php b/src/Model/Entity/Product.php index 1d221f3..27f0a37 100644 --- a/src/Model/Entity/Product.php +++ b/src/Model/Entity/Product.php @@ -3,9 +3,7 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; -use CakeProducts\Model\Enum\ProductProductTypeId; /** * Product Entity @@ -13,17 +11,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId; * @property string $id * @property string $name * @property string $product_category_id - * @property ProductProductTypeId $product_type_id - * @property DateTime|null $deleted + * @property \CakeProducts\Model\Enum\ProductProductTypeId $product_type_id + * @property \Cake\I18n\DateTime|null $deleted * * @property ProductCategory $product_category * @property ProductAttribute[] $product_attributes * @property ProductCategoryVariant[] $product_category_variants - * */ -class Product extends Entity -{ - /** +class Product extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -32,16 +29,17 @@ class Product extends Entity * * @var array */ - protected array $_accessible = [ - 'name' => true, - 'product_category_id' => true, - 'product_type_id' => true, - 'deleted' => true, + protected array $_accessible = [ + 'name' => true, + 'product_category_id' => true, + 'product_type_id' => true, + 'deleted' => true, + + // entities + 'product_category' => false, + 'product_attributes' => true, + 'product_category_variants' => true, + 'primary_product_photo' => true, + ]; - // entities - 'product_category' => false, - 'product_attributes' => true, - 'product_category_variants' => true, - 'primary_product_photo' => true, - ]; } diff --git a/src/Model/Entity/ProductAttribute.php b/src/Model/Entity/ProductAttribute.php index c69640b..5da7688 100644 --- a/src/Model/Entity/ProductAttribute.php +++ b/src/Model/Entity/ProductAttribute.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -14,15 +13,15 @@ use Cake\ORM\Entity; * @property string $product_category_attribute_id * @property string|null $attribute_value * @property string|null $product_category_attribute_option_id - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime|null $deleted * * @property Product $product * @property ProductCategoryAttribute $product_category_attribute * @property ProductCategoryAttributeOption $product_category_attribute_option */ -class ProductAttribute extends Entity -{ - /** +class ProductAttribute extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -31,16 +30,17 @@ class ProductAttribute extends Entity * * @var array */ - protected array $_accessible = [ - 'product_id' => true, - 'product_category_attribute_id' => true, - 'attribute_value' => true, - 'product_category_attribute_option_id' => true, - 'deleted' => true, + protected array $_accessible = [ + 'product_id' => true, + 'product_category_attribute_id' => true, + 'attribute_value' => true, + 'product_category_attribute_option_id' => true, + 'deleted' => true, + + // entities + 'product' => false, + 'product_category_attribute' => false, + 'product_category_attribute_option' => false, + ]; - // entities - 'product' => false, - 'product_category_attribute' => false, - 'product_category_attribute_option' => false, - ]; } diff --git a/src/Model/Entity/ProductCatalog.php b/src/Model/Entity/ProductCatalog.php index 1d0022d..3cd6341 100644 --- a/src/Model/Entity/ProductCatalog.php +++ b/src/Model/Entity/ProductCatalog.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -13,14 +12,14 @@ use Cake\ORM\Entity; * @property string $name * @property string|null $catalog_description * @property bool $enabled - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime|null $deleted * * @property ProductCategory[] $product_categories * @property ExternalProductCatalog[] $external_product_catalogs */ -class ProductCatalog extends Entity -{ - /** +class ProductCatalog extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -29,14 +28,15 @@ class ProductCatalog extends Entity * * @var array */ - protected array $_accessible = [ - 'name' => true, - 'catalog_description' => true, - 'enabled' => true, - 'deleted' => true, + protected array $_accessible = [ + 'name' => true, + 'catalog_description' => true, + 'enabled' => true, + 'deleted' => true, + + // entities + 'product_categories' => true, + 'external_product_catalogs' => true, + ]; - // entities - 'product_categories' => true, - 'external_product_catalogs' => true, - ]; } diff --git a/src/Model/Entity/ProductCategory.php b/src/Model/Entity/ProductCategory.php index f50e188..5904412 100644 --- a/src/Model/Entity/ProductCategory.php +++ b/src/Model/Entity/ProductCategory.php @@ -3,9 +3,7 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; -use CakeProducts\Model\Enum\ProductProductTypeId; /** * ProductCategory Entity @@ -19,16 +17,16 @@ use CakeProducts\Model\Enum\ProductProductTypeId; * @property int $lft * @property int $rght * @property bool $enabled - * @property DateTime|null $deleted - * @property ProductProductTypeId|null $default_product_type_id + * @property \Cake\I18n\DateTime|null $deleted + * @property \CakeProducts\Model\Enum\ProductProductTypeId|null $default_product_type_id * * @property \CakeProducts\Model\Entity\ProductCatalog $product_catalog * @property \CakeProducts\Model\Entity\ParentProductCategory $parent_product_category * @property \CakeProducts\Model\Entity\ChildProductCategory[] $child_product_categories */ -class ProductCategory extends Entity -{ - /** +class ProductCategory extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -37,22 +35,23 @@ class ProductCategory extends Entity * * @var array */ - protected array $_accessible = [ - 'product_catalog_id' => true, - 'internal_id' => true, - 'name' => true, - 'category_description' => true, - 'default_product_type_id' => true, - 'parent_id' => true, - 'lft' => true, - 'rght' => true, - 'enabled' => true, - 'deleted' => true, + protected array $_accessible = [ + 'product_catalog_id' => true, + 'internal_id' => true, + 'name' => true, + 'category_description' => true, + 'default_product_type_id' => true, + 'parent_id' => true, + 'lft' => true, + 'rght' => true, + 'enabled' => true, + 'deleted' => true, + + // entities + 'product_catalog' => true, + 'parent_product_category' => true, + 'child_product_categories' => true, + 'primary_product_photo' => true, + ]; - // entities - 'product_catalog' => true, - 'parent_product_category' => true, - 'child_product_categories' => true, - 'primary_product_photo' => true, - ]; } diff --git a/src/Model/Entity/ProductCategoryAttribute.php b/src/Model/Entity/ProductCategoryAttribute.php index 95f0024..29b8f01 100644 --- a/src/Model/Entity/ProductCategoryAttribute.php +++ b/src/Model/Entity/ProductCategoryAttribute.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -14,14 +13,14 @@ use Cake\ORM\Entity; * @property string|null $product_category_id * @property int $attribute_type_id * @property bool $enabled - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime|null $deleted * * @property ProductCategory $product_category * @property ProductCategoryAttributeOption[] $product_category_attribute_options */ -class ProductCategoryAttribute extends Entity -{ - /** +class ProductCategoryAttribute extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -30,15 +29,16 @@ class ProductCategoryAttribute extends Entity * * @var array */ - protected array $_accessible = [ - 'name' => true, - 'product_category_id' => true, - 'attribute_type_id' => true, - 'enabled' => true, - 'deleted' => true, + protected array $_accessible = [ + 'name' => true, + 'product_category_id' => true, + 'attribute_type_id' => true, + 'enabled' => true, + 'deleted' => true, + + // entities + 'product_category' => true, + 'product_category_attribute_options' => true, + ]; - // entities - 'product_category' => true, - 'product_category_attribute_options' => true, - ]; } diff --git a/src/Model/Entity/ProductCategoryAttributeOption.php b/src/Model/Entity/ProductCategoryAttributeOption.php index 356f3d2..89f0d49 100644 --- a/src/Model/Entity/ProductCategoryAttributeOption.php +++ b/src/Model/Entity/ProductCategoryAttributeOption.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -14,13 +13,13 @@ use Cake\ORM\Entity; * @property string $attribute_value * @property string $attribute_label * @property bool $enabled - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime|null $deleted * * @property ProductCategoryAttribute $product_category_attribute */ -class ProductCategoryAttributeOption extends Entity -{ - /** +class ProductCategoryAttributeOption extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -29,14 +28,15 @@ class ProductCategoryAttributeOption extends Entity * * @var array */ - protected array $_accessible = [ - 'product_category_attribute_id' => true, - 'attribute_value' => true, - 'attribute_label' => true, - 'enabled' => true, - 'deleted' => true, + protected array $_accessible = [ + 'product_category_attribute_id' => true, + 'attribute_value' => true, + 'attribute_label' => true, + 'enabled' => true, + 'deleted' => true, + + // entities + 'product_category_attribute' => true, + ]; - // entities - 'product_category_attribute' => true, - ]; } diff --git a/src/Model/Entity/ProductCategoryVariant.php b/src/Model/Entity/ProductCategoryVariant.php index 9719859..8127643 100644 --- a/src/Model/Entity/ProductCategoryVariant.php +++ b/src/Model/Entity/ProductCategoryVariant.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\Datasource\EntityInterface; use Cake\ORM\Entity; /** @@ -16,12 +15,12 @@ use Cake\ORM\Entity; * @property bool $enabled * @property bool $is_system_variant * - * @property ProductCategory|EntityInterface $product_category - * @property ProductCategoryVariantOption[]|EntityInterface[] $product_category_variant_options + * @property ProductCategory|\Cake\Datasource\EntityInterface $product_category + * @property ProductCategoryVariantOption[]|\Cake\Datasource\EntityInterface[] $product_category_variant_options */ -class ProductCategoryVariant extends Entity -{ - /** +class ProductCategoryVariant extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -30,16 +29,17 @@ class ProductCategoryVariant extends Entity * * @var array */ - protected array $_accessible = [ - 'name' => true, - 'product_category_id' => true, - 'product_id' => true, - 'enabled' => true, - 'is_system_variant' => true, + protected array $_accessible = [ + 'name' => true, + 'product_category_id' => true, + 'product_id' => true, + 'enabled' => true, + 'is_system_variant' => true, + + // entities + 'product_category' => false, + 'product' => false, + 'product_category_variant_options' => true, + ]; - // entities - 'product_category' => false, - 'product' => false, - 'product_category_variant_options' => true, - ]; } diff --git a/src/Model/Entity/ProductCategoryVariantOption.php b/src/Model/Entity/ProductCategoryVariantOption.php index 81536c4..8221783 100644 --- a/src/Model/Entity/ProductCategoryVariantOption.php +++ b/src/Model/Entity/ProductCategoryVariantOption.php @@ -17,9 +17,9 @@ use Cake\ORM\Entity; * * @property \App\Model\Entity\ProductCategoryVariant $product_category_variant */ -class ProductCategoryVariantOption extends Entity -{ - /** +class ProductCategoryVariantOption extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -28,14 +28,15 @@ class ProductCategoryVariantOption extends Entity * * @var array */ - protected array $_accessible = [ - 'product_category_variant_id' => true, - 'variant_value' => true, - 'created' => true, - 'modified' => true, - 'deleted' => true, + protected array $_accessible = [ + 'product_category_variant_id' => true, + 'variant_value' => true, + 'created' => true, + 'modified' => true, + 'deleted' => true, + + // entities + 'product_category_variant' => false, + ]; - // entities - 'product_category_variant' => false, - ]; } diff --git a/src/Model/Entity/ProductPhoto.php b/src/Model/Entity/ProductPhoto.php index 4a3056e..25dfebb 100644 --- a/src/Model/Entity/ProductPhoto.php +++ b/src/Model/Entity/ProductPhoto.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -20,17 +19,17 @@ use Cake\ORM\Entity; * @property bool $primary_sku_photo * @property int $photo_position * @property bool $enabled - * @property DateTime $created - * @property DateTime|null $modified - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime $created + * @property \Cake\I18n\DateTime|null $modified + * @property \Cake\I18n\DateTime|null $deleted * * @property Product|null $product * @property ProductSku|null $product_sku * @property ProductCategory $product_category */ -class ProductPhoto extends Entity -{ - /** +class ProductPhoto extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -39,24 +38,25 @@ class ProductPhoto extends Entity * * @var array */ - protected array $_accessible = [ - 'product_id' => true, - 'product_sku_id' => true, - 'product_category_id' => true, - 'photo_dir' => true, - 'photo_filename' => true, - 'primary_photo' => true, - 'primary_category_photo' => true, - 'primary_sku_photo' => true, - 'photo_position' => true, - 'enabled' => true, - 'created' => true, - 'modified' => true, - 'deleted' => true, + protected array $_accessible = [ + 'product_id' => true, + 'product_sku_id' => true, + 'product_category_id' => true, + 'photo_dir' => true, + 'photo_filename' => true, + 'primary_photo' => true, + 'primary_category_photo' => true, + 'primary_sku_photo' => true, + 'photo_position' => true, + 'enabled' => true, + 'created' => true, + 'modified' => true, + 'deleted' => true, + + // entities + 'product' => false, + 'product_sku' => false, + 'product_category' => false, + ]; - // entities - 'product' => false, - 'product_sku' => false, - 'product_category' => false, - ]; } diff --git a/src/Model/Entity/ProductSku.php b/src/Model/Entity/ProductSku.php index eb2287c..d0109ec 100644 --- a/src/Model/Entity/ProductSku.php +++ b/src/Model/Entity/ProductSku.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Model\Entity; -use Cake\I18n\DateTime; use Cake\ORM\Entity; /** @@ -15,17 +14,17 @@ use Cake\ORM\Entity; * @property string|null $barcode * @property string|null $price * @property string|null $cost - * @property DateTime $created - * @property DateTime|null $modified - * @property DateTime|null $deleted + * @property \Cake\I18n\DateTime $created + * @property \Cake\I18n\DateTime|null $modified + * @property \Cake\I18n\DateTime|null $deleted * @property bool $default_sku * * @property Product $product * @property ProductSkuVariantValue[] $product_sku_variant_values */ -class ProductSku extends Entity -{ - /** +class ProductSku extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -34,19 +33,20 @@ class ProductSku extends Entity * * @var array */ - protected array $_accessible = [ - 'product_id' => true, - 'sku' => true, - 'barcode' => true, - 'price' => true, - 'cost' => true, - 'created' => true, - 'modified' => true, - 'deleted' => true, - 'default_sku' => true, + protected array $_accessible = [ + 'product_id' => true, + 'sku' => true, + 'barcode' => true, + 'price' => true, + 'cost' => true, + 'created' => true, + 'modified' => true, + 'deleted' => true, + 'default_sku' => true, + + // entities + 'product' => false, + 'product_sku_variant_values' => true, + ]; - // entities - 'product' => false, - 'product_sku_variant_values' => true, - ]; } diff --git a/src/Model/Entity/ProductSkuVariantValue.php b/src/Model/Entity/ProductSkuVariantValue.php index fa9720a..0f0aa19 100644 --- a/src/Model/Entity/ProductSkuVariantValue.php +++ b/src/Model/Entity/ProductSkuVariantValue.php @@ -17,9 +17,9 @@ use Cake\ORM\Entity; * @property ProductCategoryVariant $product_category_variant * @property ProductCategoryVariantOption $product_category_variant_option */ -class ProductSkuVariantValue extends Entity -{ - /** +class ProductSkuVariantValue extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -28,14 +28,15 @@ class ProductSkuVariantValue extends Entity * * @var array */ - protected array $_accessible = [ - 'product_sku_id' => true, - 'product_variant_id' => true, - 'product_category_variant_option_id' => true, + protected array $_accessible = [ + 'product_sku_id' => true, + 'product_variant_id' => true, + 'product_category_variant_option_id' => true, + + // entities + 'product_sku' => true, + 'product_variant' => true, + 'product_category_variant_option' => true, + ]; - // entities - 'product_sku' => true, - 'product_variant' => true, - 'product_category_variant_option' => true, - ]; } diff --git a/src/Model/Entity/ProductVariant.php b/src/Model/Entity/ProductVariant.php index 5bcadc3..ffb9cc0 100644 --- a/src/Model/Entity/ProductVariant.php +++ b/src/Model/Entity/ProductVariant.php @@ -17,9 +17,9 @@ use Cake\ORM\Entity; * @property \App\Model\Entity\ProductCategoryVariant $product_category_variant * @property \App\Model\Entity\Product $product */ -class ProductVariant extends Entity -{ - /** +class ProductVariant extends Entity { + + /** * Fields that can be mass assigned using newEntity() or patchEntity(). * * Note that when '*' is set to true, this allows all unspecified fields to @@ -28,12 +28,13 @@ class ProductVariant extends Entity * * @var array */ - protected array $_accessible = [ - 'name' => true, - 'product_category_variant_id' => true, - 'product_id' => true, - 'enabled' => true, - 'product_category_variant' => true, - 'product' => true, - ]; + protected array $_accessible = [ + 'name' => true, + 'product_category_variant_id' => true, + 'product_id' => true, + 'enabled' => true, + 'product_category_variant' => true, + 'product' => true, + ]; + } diff --git a/src/Model/Table/ExternalProductCatalogsProductCatalogsTable.php b/src/Model/Table/ExternalProductCatalogsProductCatalogsTable.php index 9d5b4ce..204a5d4 100644 --- a/src/Model/Table/ExternalProductCatalogsProductCatalogsTable.php +++ b/src/Model/Table/ExternalProductCatalogsProductCatalogsTable.php @@ -5,18 +5,10 @@ namespace CakeProducts\Model\Table; use ArrayObject; use Cake\Core\Configure; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; use Cake\Event\EventInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Behavior\TimestampBehavior; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ExternalProductCatalogsProductCatalogs Model @@ -24,15 +16,15 @@ use Psr\SimpleCache\CacheInterface; * @property ExternalProductCatalogsTable&BelongsTo $ExternalProductCatalogs * @property ProductCatalogsTable&BelongsTo $ProductCatalogs * - * @method ExternalProductCatalogsProductCatalog newEmptyEntity() - * @method ExternalProductCatalogsProductCatalog newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEmptyEntity() + * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog newEntity() * @method array newEntities(array $data, array $options = []) - * @method ExternalProductCatalogsProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ExternalProductCatalogsProductCatalog findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ExternalProductCatalogsProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog get() + * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog findOrCreate() + * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ExternalProductCatalogsProductCatalog|false save(EntityInterface $entity, array $options = []) - * @method ExternalProductCatalogsProductCatalog saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) @@ -40,86 +32,86 @@ use Psr\SimpleCache\CacheInterface; * * @mixin TimestampBehavior */ -class ExternalProductCatalogsProductCatalogsTable extends Table -{ - /** +class ExternalProductCatalogsProductCatalogsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('external_product_catalogs_product_catalogs'); - $this->setDisplayField('external_product_catalog_id'); - $this->setPrimaryKey('id'); + $this->setTable('external_product_catalogs_product_catalogs'); + $this->setDisplayField('external_product_catalog_id'); + $this->setPrimaryKey('id'); - $this->addBehavior('Timestamp'); + $this->addBehavior('Timestamp'); - $this->setEntityClass( - Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog') - ); - $this->belongsTo('ExternalProductCatalogs', [ - 'className' => 'CakeProducts.ExternalProductCatalogs', + $this->setEntityClass( + Configure::read('CakeProducts.ExternalProductCatalogsProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalogsProductCatalog'), + ); + $this->belongsTo('ExternalProductCatalogs', [ + 'className' => 'CakeProducts.ExternalProductCatalogs', // 'foreignKey' => 'external_product_catalog_id', - 'joinType' => 'INNER', - ]); - $this->belongsTo('ProductCatalogs', [ - 'className' => 'CakeProducts.ProductCatalogs', + 'joinType' => 'INNER', + ]); + $this->belongsTo('ProductCatalogs', [ + 'className' => 'CakeProducts.ProductCatalogs', // 'foreignKey' => 'product_catalog_id', - 'joinType' => 'INNER', - ]); + 'joinType' => 'INNER', + ]); - $this->addBehavior('Muffin/Trash.Trash'); - } + $this->addBehavior('Muffin/Trash.Trash'); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('external_product_catalog_id') - ->notEmptyString('external_product_catalog_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('external_product_catalog_id') + ->notEmptyString('external_product_catalog_id'); - $validator - ->uuid('product_catalog_id') - ->notEmptyString('product_catalog_id'); + $validator + ->uuid('product_catalog_id') + ->notEmptyString('product_catalog_id'); - $validator - ->boolean('enabled'); + $validator + ->boolean('enabled'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) - { - if (!isset($data['enabled'])) { - $data['enabled'] = false; - } - } + /** + * @return void + */ + public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) { + if (!isset($data['enabled'])) { + $data['enabled'] = false; + } + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { + public function buildRules(RulesChecker $rules): RulesChecker { // $rules->add($rules->existsIn(['external_product_catalog_id'], 'ExternalProductCatalogs'), ['errorField' => 'external_product_catalog_id']); // $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']); - return $rules; - } + return $rules; + } + } diff --git a/src/Model/Table/ExternalProductCatalogsTable.php b/src/Model/Table/ExternalProductCatalogsTable.php index f0dafa0..45720a3 100644 --- a/src/Model/Table/ExternalProductCatalogsTable.php +++ b/src/Model/Table/ExternalProductCatalogsTable.php @@ -4,32 +4,24 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; use Cake\Core\Configure; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Behavior\TimestampBehavior; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ExternalProductCatalog; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ExternalProductCatalogs Model * * @property ProductCatalogsTable&BelongsTo $ProductCatalogs * - * @method ExternalProductCatalog newEmptyEntity() - * @method ExternalProductCatalog newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ExternalProductCatalog newEmptyEntity() + * @method \CakeProducts\Model\Entity\ExternalProductCatalog newEntity() * @method array newEntities(array $data, array $options = []) - * @method ExternalProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ExternalProductCatalog findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ExternalProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ExternalProductCatalog get() + * @method \CakeProducts\Model\Entity\ExternalProductCatalog findOrCreate() + * @method \CakeProducts\Model\Entity\ExternalProductCatalog patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ExternalProductCatalog|false save(EntityInterface $entity, array $options = []) - * @method ExternalProductCatalog saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ExternalProductCatalog saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) @@ -37,81 +29,79 @@ use Psr\SimpleCache\CacheInterface; * * @mixin TimestampBehavior */ -class ExternalProductCatalogsTable extends Table -{ - /** +class ExternalProductCatalogsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('external_product_catalogs'); - $this->setDisplayField('base_url'); - $this->setPrimaryKey('id'); + $this->setTable('external_product_catalogs'); + $this->setDisplayField('base_url'); + $this->setPrimaryKey('id'); - $this->addBehavior('Timestamp'); + $this->addBehavior('Timestamp'); - $this->setEntityClass( - Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog') - ); + $this->setEntityClass( + Configure::read('CakeProducts.ExternalProductCatalogs.entity', 'CakeProducts\Model\Entity\ExternalProductCatalog'), + ); - $this->belongsToMany('ProductCatalogs', [ - 'through' => 'ExternalProductCatalogsProductCatalogs', - 'className' => 'CakeProducts.ProductCatalogs', - ]); + $this->belongsToMany('ProductCatalogs', [ + 'through' => 'ExternalProductCatalogsProductCatalogs', + 'className' => 'CakeProducts.ProductCatalogs', + ]); - $this->hasMany('ExternalProductCatalogsProductCatalogs', [ - 'foreignKey' => 'external_product_catalog_id', - 'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); + $this->hasMany('ExternalProductCatalogsProductCatalogs', [ + 'foreignKey' => 'external_product_catalog_id', + 'className' => 'CakeProducts.ExternalProductCatalogsProductCatalogs', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); - $this->addBehavior('Muffin/Trash.Trash'); - } + $this->addBehavior('Muffin/Trash.Trash'); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->scalar('base_url') - ->maxLength('base_url', 255) - ->requirePresence('base_url', 'create') - ->notEmptyString('base_url'); + public function validationDefault(Validator $validator): Validator { + $validator + ->scalar('base_url') + ->maxLength('base_url', 255) + ->requirePresence('base_url', 'create') + ->notEmptyString('base_url'); // ->url('base_url'); - $validator - ->scalar('api_url') - ->maxLength('api_url', 255) - ->requirePresence('api_url', 'create') - ->notEmptyString('api_url'); + $validator + ->scalar('api_url') + ->maxLength('api_url', 255) + ->requirePresence('api_url', 'create') + ->notEmptyString('api_url'); // ->url('api_url'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - return $rules; - } + public function buildRules(RulesChecker $rules): RulesChecker { + return $rules; + } + } diff --git a/src/Model/Table/ProductAttributesTable.php b/src/Model/Table/ProductAttributesTable.php index 556b074..9dfcefc 100644 --- a/src/Model/Table/ProductAttributesTable.php +++ b/src/Model/Table/ProductAttributesTable.php @@ -29,88 +29,86 @@ use Cake\Validation\Validator; * @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute>|false deleteMany(iterable $entities, array $options = []) * @method iterable<\App\Model\Entity\ProductAttribute>|\Cake\Datasource\ResultSetInterface<\App\Model\Entity\ProductAttribute> deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductAttributesTable extends Table -{ - /** +class ProductAttributesTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_attributes'); - $this->setDisplayField('id'); - $this->setPrimaryKey('id'); + $this->setTable('product_attributes'); + $this->setDisplayField('id'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute') - ); + $this->setEntityClass( + Configure::read('CakeProducts.ProductAttributes.entity', 'CakeProducts\Model\Entity\ProductAttribute'), + ); - $this->belongsTo('Products', [ - 'foreignKey' => 'product_id', - 'className' => 'CakeProducts.Products', - 'joinType' => 'INNER', - ]); - $this->belongsTo('ProductCategoryAttributes', [ - 'foreignKey' => 'product_category_attribute_id', - 'className' => 'CakeProducts.ProductCategoryAttributes', - 'joinType' => 'INNER', - ]); - $this->belongsTo('ProductCategoryAttributeOptions', [ - 'foreignKey' => 'product_category_attribute_option_id', - 'className' => 'CakeProducts.ProductCategoryAttributeOptions', - ]); + $this->belongsTo('Products', [ + 'foreignKey' => 'product_id', + 'className' => 'CakeProducts.Products', + 'joinType' => 'INNER', + ]); + $this->belongsTo('ProductCategoryAttributes', [ + 'foreignKey' => 'product_category_attribute_id', + 'className' => 'CakeProducts.ProductCategoryAttributes', + 'joinType' => 'INNER', + ]); + $this->belongsTo('ProductCategoryAttributeOptions', [ + 'foreignKey' => 'product_category_attribute_option_id', + 'className' => 'CakeProducts.ProductCategoryAttributeOptions', + ]); - } + } - /** + /** * Default validation rules. * * @param \Cake\Validation\Validator $validator Validator instance. * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('product_id') - ->notEmptyString('product_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('product_id') + ->notEmptyString('product_id'); - $validator - ->uuid('product_category_attribute_id') - ->notEmptyString('product_category_attribute_id'); + $validator + ->uuid('product_category_attribute_id') + ->notEmptyString('product_category_attribute_id'); - $validator - ->scalar('attribute_value') - ->maxLength('attribute_value', 255) - ->allowEmptyString('attribute_value'); + $validator + ->scalar('attribute_value') + ->maxLength('attribute_value', 255) + ->allowEmptyString('attribute_value'); - $validator - ->uuid('product_category_attribute_option_id') - ->allowEmptyString('product_category_attribute_option_id'); + $validator + ->uuid('product_category_attribute_option_id') + ->allowEmptyString('product_category_attribute_option_id'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); - $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); - $rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); + $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); + $rules->add($rules->existsIn(['product_category_attribute_option_id'], 'ProductCategoryAttributeOptions'), ['errorField' => 'product_category_attribute_option_id']); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductCatalogsTable.php b/src/Model/Table/ProductCatalogsTable.php index 876fb55..1ef4f5d 100644 --- a/src/Model/Table/ProductCatalogsTable.php +++ b/src/Model/Table/ProductCatalogsTable.php @@ -4,106 +4,98 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; use Cake\Core\Configure; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductCatalog; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductCatalogs Model * - * @method ProductCatalog newEmptyEntity() - * @method ProductCatalog newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCatalog newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductCatalog newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductCatalog get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductCatalog findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductCatalog patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCatalog get() + * @method \CakeProducts\Model\Entity\ProductCatalog findOrCreate() + * @method \CakeProducts\Model\Entity\ProductCatalog patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductCatalog|false save(EntityInterface $entity, array $options = []) - * @method ProductCatalog saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCatalog saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductCatalogsTable extends Table -{ - /** +class ProductCatalogsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_catalogs'); - $this->setDisplayField('name'); - $this->setPrimaryKey('id'); + $this->setTable('product_catalogs'); + $this->setDisplayField('name'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog') - ); - $this->hasMany('ProductCategories', [ - 'className' => 'CakeProducts.ProductCategories', - ]); - $this->belongsToMany('ExternalProductCatalogs', [ - 'through' => 'ExternalProductCatalogsProductCatalogs', - 'className' => 'CakeProducts.ExternalProductCatalogs', - ]); + $this->setEntityClass( + Configure::read('CakeProducts.ProductCatalogs.entity', 'CakeProducts\Model\Entity\ProductCatalog'), + ); + $this->hasMany('ProductCategories', [ + 'className' => 'CakeProducts.ProductCategories', + ]); + $this->belongsToMany('ExternalProductCatalogs', [ + 'through' => 'ExternalProductCatalogsProductCatalogs', + 'className' => 'CakeProducts.ExternalProductCatalogs', + ]); - $this->addBehavior('Muffin/Trash.Trash'); - } + $this->addBehavior('Muffin/Trash.Trash'); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->scalar('name') - ->maxLength('name', 255) - ->requirePresence('name', 'create') - ->notEmptyString('name') - ->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']); + public function validationDefault(Validator $validator): Validator { + $validator + ->scalar('name') + ->maxLength('name', 255) + ->requirePresence('name', 'create') + ->notEmptyString('name') + ->add('name', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']); - $validator - ->scalar('catalog_description') - ->maxLength('catalog_description', 255) - ->allowEmptyString('catalog_description'); + $validator + ->scalar('catalog_description') + ->maxLength('catalog_description', 255) + ->allowEmptyString('catalog_description'); - $validator - ->boolean('enabled') - ->requirePresence('enabled', 'create') - ->notEmptyString('enabled'); + $validator + ->boolean('enabled') + ->requirePresence('enabled', 'create') + ->notEmptyString('enabled'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->isUnique(['name']), ['errorField' => 'name']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->isUnique(['name']), ['errorField' => 'name']); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductCategoriesTable.php b/src/Model/Table/ProductCategoriesTable.php index 017ea6a..e9d5424 100644 --- a/src/Model/Table/ProductCategoriesTable.php +++ b/src/Model/Table/ProductCategoriesTable.php @@ -6,18 +6,10 @@ namespace CakeProducts\Model\Table; use Cake\Core\Configure; use Cake\Database\Type\EnumType; use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Association\HasMany; -use Cake\ORM\Behavior\TreeBehavior; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductCategory; use CakeProducts\Model\Enum\ProductProductTypeId; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductCategories Model @@ -26,14 +18,14 @@ use Psr\SimpleCache\CacheInterface; * @property ProductCategoriesTable&BelongsTo $ParentProductCategories * @property ProductCategoriesTable&HasMany $ChildProductCategories * - * @method ProductCategory newEmptyEntity() - * @method ProductCategory newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategory newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductCategory newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductCategory get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductCategory findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductCategory patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategory get() + * @method \CakeProducts\Model\Entity\ProductCategory findOrCreate() + * @method \CakeProducts\Model\Entity\ProductCategory patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) - * @method ProductCategory saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategory saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) @@ -41,175 +33,171 @@ use Psr\SimpleCache\CacheInterface; * * @mixin TreeBehavior */ -class ProductCategoriesTable extends Table -{ - /** +class ProductCategoriesTable extends Table { + + /** * Current scope for Tree behavior - per catalog * * @var string */ - protected $treeCatalogId; + protected $treeCatalogId; - /** + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); - $this->treeCatalogId = 1; + public function initialize(array $config): void { + parent::initialize($config); + $this->treeCatalogId = 1; - $this->setTable('product_categories'); - $this->setDisplayField('name'); - $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory') - ); - $this->addBehavior('Tree', [ - 'cascadeCallbacks' => true, - ]); + $this->setTable('product_categories'); + $this->setDisplayField('name'); + $this->setPrimaryKey('id'); + $this->setEntityClass( + Configure::read('CakeProducts.ProductCategories.entity', 'CakeProducts\Model\Entity\ProductCategory'), + ); + $this->addBehavior('Tree', [ + 'cascadeCallbacks' => true, + ]); - $this->belongsTo('ProductCatalogs', [ - 'foreignKey' => 'product_catalog_id', - 'joinType' => 'INNER', - 'className' => 'CakeProducts.ProductCatalogs', - ]); - $this->belongsTo('ParentProductCategories', [ - 'className' => 'CakeProducts.ProductCategories', - 'foreignKey' => 'parent_id', - ]); - $this->hasMany('ChildProductCategories', [ - 'className' => 'CakeProducts.ProductCategories', - 'foreignKey' => 'parent_id', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - $this->hasMany('ProductCategoryAttributes', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'className' => 'CakeProducts.ProductCategoryAttributes', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - $this->hasMany('ProductCategoryVariants', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'className' => 'CakeProducts.ProductCategoryVariants', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - $this->hasMany('Products', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'className' => 'CakeProducts.Products', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - $this->hasMany('ProductPhotos', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'className' => 'CakeProducts.ProductPhotos', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - $this->hasOne('PrimaryProductPhotos', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true], - 'className' => 'CakeProducts.ProductPhotos', - 'dependent' => true, - ]); + $this->belongsTo('ProductCatalogs', [ + 'foreignKey' => 'product_catalog_id', + 'joinType' => 'INNER', + 'className' => 'CakeProducts.ProductCatalogs', + ]); + $this->belongsTo('ParentProductCategories', [ + 'className' => 'CakeProducts.ProductCategories', + 'foreignKey' => 'parent_id', + ]); + $this->hasMany('ChildProductCategories', [ + 'className' => 'CakeProducts.ProductCategories', + 'foreignKey' => 'parent_id', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + $this->hasMany('ProductCategoryAttributes', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'className' => 'CakeProducts.ProductCategoryAttributes', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + $this->hasMany('ProductCategoryVariants', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'className' => 'CakeProducts.ProductCategoryVariants', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + $this->hasMany('Products', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'className' => 'CakeProducts.Products', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + $this->hasMany('ProductPhotos', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + $this->hasOne('PrimaryProductPhotos', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'conditions' => ['PrimaryProductPhotos.primary_category_photo' => true], + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + ]); - $this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class)); + $this->getSchema()->setColumnType('default_product_type_id', EnumType::from(ProductProductTypeId::class)); - $this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); - $this->addBehavior('Muffin/Trash.Trash'); - } + $this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); + $this->addBehavior('Muffin/Trash.Trash'); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('product_catalog_id') - ->notEmptyString('product_catalog_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('product_catalog_id') + ->notEmptyString('product_catalog_id'); - $validator - ->scalar('name') - ->maxLength('name', 255) - ->requirePresence('name', 'create') - ->notEmptyString('name'); + $validator + ->scalar('name') + ->maxLength('name', 255) + ->requirePresence('name', 'create') + ->notEmptyString('name'); - $validator - ->scalar('category_description') - ->allowEmptyString('category_description'); + $validator + ->scalar('category_description') + ->allowEmptyString('category_description'); - $validator - ->integer('parent_id') - ->allowEmptyString('parent_id'); + $validator + ->integer('parent_id') + ->allowEmptyString('parent_id'); - $validator - ->boolean('enabled') - ->notEmptyString('enabled'); + $validator + ->boolean('enabled') + ->notEmptyString('enabled'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - $validator - ->integer('default_product_type_id') - ->allowEmptyString('default_product_type_id'); + $validator + ->integer('default_product_type_id') + ->allowEmptyString('default_product_type_id'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']); - $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']); - $rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->isUnique(['product_catalog_id', 'name']), ['errorField' => 'product_catalog_id']); + $rules->add($rules->existsIn(['product_catalog_id'], 'ProductCatalogs'), ['errorField' => 'product_catalog_id']); + $rules->add($rules->existsIn(['parent_id'], 'ParentProductCategories'), ['errorField' => 'parent_id']); - return $rules; - } + return $rules; + } - /** - * @param int $catalogId + /** + * @param string $catalogId * * @return void */ - public function setConfigureCatalogId(string $catalogId) - { - $this->treeCatalogId = $catalogId; - $this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); - } + public function setConfigureCatalogId(string $catalogId) { + $this->treeCatalogId = $catalogId; + $this->behaviors()->Tree->setConfig('scope', ['product_catalog_id' => $this->treeCatalogId]); + } - /** - * @param EntityInterface $entity + /** + * @param \Cake\Datasource\EntityInterface $entity * @param array $options * - * @return EntityInterface|false + * @return \Cake\Datasource\EntityInterface|false */ - public function save(EntityInterface $entity, array $options = []): EntityInterface|false - { - $this->behaviors()->get('Tree')->setConfig([ - 'scope' => [ - 'product_catalog_id' => $entity->product_catalog_id, - ], - ]); + public function save(EntityInterface $entity, array $options = []): EntityInterface|false { + $this->behaviors()->get('Tree')->setConfig([ + 'scope' => [ + 'product_catalog_id' => $entity->product_catalog_id, + ], + ]); + + return parent::save($entity, $options); + } - return parent::save($entity, $options); - } } diff --git a/src/Model/Table/ProductCategoryAttributeOptionsTable.php b/src/Model/Table/ProductCategoryAttributeOptionsTable.php index 54e1e57..ef6083b 100644 --- a/src/Model/Table/ProductCategoryAttributeOptionsTable.php +++ b/src/Model/Table/ProductCategoryAttributeOptionsTable.php @@ -4,112 +4,103 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; use Cake\Core\Configure; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductCategoryAttributeOption; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductCategoryAttributeOptions Model * * @property ProductCategoryAttributesTable&BelongsTo $ProductCategoryAttributes * - * @method ProductCategoryAttributeOption newEmptyEntity() - * @method ProductCategoryAttributeOption newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductCategoryAttributeOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductCategoryAttributeOption findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductCategoryAttributeOption patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption get() + * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption findOrCreate() + * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductCategoryAttributeOption|false save(EntityInterface $entity, array $options = []) - * @method ProductCategoryAttributeOption saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryAttributeOption saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductCategoryAttributeOptionsTable extends Table -{ - /** +class ProductCategoryAttributeOptionsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_category_attribute_options'); - $this->setDisplayField('attribute_value'); - $this->setPrimaryKey('id'); + $this->setTable('product_category_attribute_options'); + $this->setDisplayField('attribute_value'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption') - ); + $this->setEntityClass( + Configure::read('CakeProducts.ProductCategoryAttributeOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryAttributeOption'), + ); - $this->belongsTo('ProductCategoryAttributes', [ - 'foreignKey' => 'product_category_attribute_id', - 'joinType' => 'INNER', - 'className' => 'CakeProducts.ProductCategoryAttributes', - ]); + $this->belongsTo('ProductCategoryAttributes', [ + 'foreignKey' => 'product_category_attribute_id', + 'joinType' => 'INNER', + 'className' => 'CakeProducts.ProductCategoryAttributes', + ]); - $this->addBehavior('Muffin/Trash.Trash'); - } + $this->addBehavior('Muffin/Trash.Trash'); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('product_category_attribute_id') - ->notEmptyString('product_category_attribute_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('product_category_attribute_id') + ->notEmptyString('product_category_attribute_id'); - $validator - ->scalar('attribute_value') - ->maxLength('attribute_value', 255) - ->requirePresence('attribute_value', 'create') - ->notEmptyString('attribute_value'); + $validator + ->scalar('attribute_value') + ->maxLength('attribute_value', 255) + ->requirePresence('attribute_value', 'create') + ->notEmptyString('attribute_value'); - $validator - ->scalar('attribute_label') - ->maxLength('attribute_label', 255) - ->requirePresence('attribute_label', 'create') - ->notEmptyString('attribute_label'); + $validator + ->scalar('attribute_label') + ->maxLength('attribute_label', 255) + ->requirePresence('attribute_label', 'create') + ->notEmptyString('attribute_label'); - $validator - ->boolean('enabled') - ->notEmptyString('enabled'); + $validator + ->boolean('enabled') + ->notEmptyString('enabled'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); - $rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id'])); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->existsIn(['product_category_attribute_id'], 'ProductCategoryAttributes'), ['errorField' => 'product_category_attribute_id']); + $rules->add($rules->isUnique(['attribute_value', 'product_category_attribute_id'])); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductCategoryAttributesTable.php b/src/Model/Table/ProductCategoryAttributesTable.php index c7cfa1c..2c2b4f9 100644 --- a/src/Model/Table/ProductCategoryAttributesTable.php +++ b/src/Model/Table/ProductCategoryAttributesTable.php @@ -5,146 +5,141 @@ namespace CakeProducts\Model\Table; use Cake\Core\Configure; use Cake\Database\Type\EnumType; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductCategoryAttribute; use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductCategoryAttributes Model * * @property ProductCategoriesTable&BelongsTo $ProductCategories * - * @method ProductCategoryAttribute newEmptyEntity() - * @method ProductCategoryAttribute newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductCategoryAttribute newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductCategoryAttribute get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductCategoryAttribute findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductCategoryAttribute patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryAttribute get() + * @method \CakeProducts\Model\Entity\ProductCategoryAttribute findOrCreate() + * @method \CakeProducts\Model\Entity\ProductCategoryAttribute patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductCategoryAttribute|false save(EntityInterface $entity, array $options = []) - * @method ProductCategoryAttribute saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryAttribute saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductCategoryAttributesTable extends Table -{ - /** +class ProductCategoryAttributesTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_category_attributes'); - $this->setDisplayField('name'); - $this->setPrimaryKey('id'); + $this->setTable('product_category_attributes'); + $this->setDisplayField('name'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute') - ); - $this->belongsTo('ProductCategories', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'className' => 'CakeProducts.ProductCategories', - ]); + $this->setEntityClass( + Configure::read('CakeProducts.ProductCategoryAttributes.entity', 'CakeProducts\Model\Entity\ProductCategoryAttribute'), + ); + $this->belongsTo('ProductCategories', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'className' => 'CakeProducts.ProductCategories', + ]); - $this->hasMany('ProductCategoryAttributeOptions', [ - 'foreignKey' => 'product_category_attribute_id', - 'className' => 'CakeProducts.ProductCategoryAttributeOptions', - 'saveStrategy' => 'replace', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - $this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class)); + $this->hasMany('ProductCategoryAttributeOptions', [ + 'foreignKey' => 'product_category_attribute_id', + 'className' => 'CakeProducts.ProductCategoryAttributeOptions', + 'saveStrategy' => 'replace', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + $this->getSchema()->setColumnType('attribute_type_id', EnumType::from(ProductCategoryAttributeTypeId::class)); - $this->addBehavior('Muffin/Trash.Trash'); - } + $this->addBehavior('Muffin/Trash.Trash'); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->scalar('name') - ->maxLength('name', 255) - ->requirePresence('name', 'create') - ->notEmptyString('name'); + public function validationDefault(Validator $validator): Validator { + $validator + ->scalar('name') + ->maxLength('name', 255) + ->requirePresence('name', 'create') + ->notEmptyString('name'); - $validator - ->uuid('product_category_id') - ->allowEmptyString('product_category_id'); + $validator + ->uuid('product_category_id') + ->allowEmptyString('product_category_id'); - $validator - ->integer('attribute_type_id') - ->requirePresence('attribute_type_id', 'create') - ->notEmptyString('attribute_type_id'); + $validator + ->integer('attribute_type_id') + ->requirePresence('attribute_type_id', 'create') + ->notEmptyString('attribute_type_id'); - $validator - ->boolean('enabled') - ->requirePresence('enabled', 'create') - ->notEmptyString('enabled'); + $validator + ->boolean('enabled') + ->requirePresence('enabled', 'create') + ->notEmptyString('enabled'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']); - $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'name']); + $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); - return $rules; - } + return $rules; + } - /** - * @param SelectQuery $query + /** + * @param \Cake\ORM\Query\SelectQuery $query * @param string $internalCategoryId * - * @return array|\Cake\ORM\Query|SelectQuery + * @return \Cake\ORM\Query|\Cake\ORM\Query\SelectQuery|array */ - public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) - { - $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); + public function findAllCategoryAttributesForCategoryId(SelectQuery $query, string $internalCategoryId) { + $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); - $this->ProductCategories->behaviors()->get('Tree')->setConfig([ - 'scope' => [ - 'product_catalog_id' => $category->product_catalog_id ?? 1, - ], - ]); + $this->ProductCategories->behaviors()->get('Tree')->setConfig([ + 'scope' => [ + 'product_catalog_id' => $category->product_catalog_id ?? 1, + ], + ]); + + return $this->ProductCategories + ->find('path', for: $category->id) + ->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']); + } + + /** + * @param string $internalCategoryId + * @return array|array[]|\Cake\Datasource\EntityInterface[] + */ + public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) { + return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray(); + } - return $this->ProductCategories - ->find('path', for: $category->id) - ->contain(['ProductCategoryAttributes', 'ProductCategoryAttributes.ProductCategoryAttributeOptions']); - } - public function getAllCategoryAttributesForCategoryId(string $internalCategoryId) - { - return $this->find('allCategoryAttributesForCategoryId', $internalCategoryId)->toArray(); - } } diff --git a/src/Model/Table/ProductCategoryVariantOptionsTable.php b/src/Model/Table/ProductCategoryVariantOptionsTable.php index f564fa4..894e8b3 100644 --- a/src/Model/Table/ProductCategoryVariantOptionsTable.php +++ b/src/Model/Table/ProductCategoryVariantOptionsTable.php @@ -4,33 +4,24 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; use Cake\Core\Configure; -use CakeProducts\Model\Entity\ProductCategoryVariantOption; -use CakeProducts\Model\Table\ProductCategoryVariantsTable; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Behavior\TimestampBehavior; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductCategoryVariantOptions Model * * @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * - * @method ProductCategoryVariantOption newEmptyEntity() - * @method ProductCategoryVariantOption newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductCategoryVariantOption get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductCategoryVariantOption findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductCategoryVariantOption patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption get() + * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption findOrCreate() + * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductCategoryVariantOption|false save(EntityInterface $entity, array $options = []) - * @method ProductCategoryVariantOption saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryVariantOption saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) @@ -38,75 +29,73 @@ use Psr\SimpleCache\CacheInterface; * * @mixin TimestampBehavior */ -class ProductCategoryVariantOptionsTable extends Table -{ - /** +class ProductCategoryVariantOptionsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_category_variant_options'); - $this->setDisplayField('variant_value'); - $this->setPrimaryKey('id'); + $this->setTable('product_category_variant_options'); + $this->setDisplayField('variant_value'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption') - ); - $this->addBehavior('Timestamp'); + $this->setEntityClass( + Configure::read('CakeProducts.ProductCategoryVariantOptions.entity', 'CakeProducts\Model\Entity\ProductCategoryVariantOption'), + ); + $this->addBehavior('Timestamp'); - $this->belongsTo('ProductCategoryVariants', [ - 'foreignKey' => 'product_category_variant_id', - 'joinType' => 'INNER', - ]); - } + $this->belongsTo('ProductCategoryVariants', [ + 'foreignKey' => 'product_category_variant_id', + 'joinType' => 'INNER', + ]); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('product_category_variant_id') - ->notEmptyString('product_category_variant_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('product_category_variant_id') + ->notEmptyString('product_category_variant_id'); - $validator - ->scalar('variant_value') - ->maxLength('variant_value', 255) - ->requirePresence('variant_value', 'create') - ->notEmptyString('variant_value'); + $validator + ->scalar('variant_value') + ->maxLength('variant_value', 255) + ->requirePresence('variant_value', 'create') + ->notEmptyString('variant_value'); - $validator - ->scalar('variant_label') - ->maxLength('variant_label', 255) - ->allowEmptyString('variant_label'); + $validator + ->scalar('variant_label') + ->maxLength('variant_label', 255) + ->allowEmptyString('variant_label'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); - $rules->add($rules->isUnique(['variant_value', 'product_category_variant_id'])); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); + $rules->add($rules->isUnique(['variant_value', 'product_category_variant_id'])); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductCategoryVariantsTable.php b/src/Model/Table/ProductCategoryVariantsTable.php index 2cbea7f..a8d35fd 100644 --- a/src/Model/Table/ProductCategoryVariantsTable.php +++ b/src/Model/Table/ProductCategoryVariantsTable.php @@ -4,17 +4,10 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; use Cake\Core\Configure; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Query; use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductCategoryVariant; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductCategoryVariants Model @@ -22,143 +15,139 @@ use Psr\SimpleCache\CacheInterface; * @property ProductCategoriesTable&BelongsTo $ProductCategories * @property ProductsTable&BelongsTo $Products * - * @method ProductCategoryVariant newEmptyEntity() - * @method ProductCategoryVariant newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryVariant newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductCategoryVariant newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductCategoryVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductCategoryVariant findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductCategoryVariant patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryVariant get() + * @method \CakeProducts\Model\Entity\ProductCategoryVariant findOrCreate() + * @method \CakeProducts\Model\Entity\ProductCategoryVariant patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductCategoryVariant|false save(EntityInterface $entity, array $options = []) - * @method ProductCategoryVariant saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductCategoryVariant saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductCategoryVariantsTable extends Table -{ - /** +class ProductCategoryVariantsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_category_variants'); - $this->setDisplayField('name'); - $this->setPrimaryKey('id'); + $this->setTable('product_category_variants'); + $this->setDisplayField('name'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant') - ); + $this->setEntityClass( + Configure::read('CakeProducts.ProductCategoryVariants.entity', 'CakeProducts\Model\Entity\ProductCategoryVariant'), + ); - $this->belongsTo('ProductCategories', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'className' => 'CakeProducts.ProductCategories', - ]); - $this->belongsTo('Products', [ - 'foreignKey' => 'product_id', - 'className' => 'CakeProducts.Products', - ]); - $this->hasMany('ProductCategoryVariantOptions', [ - 'foreignKey' => 'product_category_variant_id', - 'className' => 'CakeProducts.ProductCategoryVariantOptions', - 'dependent' => true, - 'cascadeCallbacks' => true, - 'saveStrategy' => 'replace', - ]); + $this->belongsTo('ProductCategories', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'className' => 'CakeProducts.ProductCategories', + ]); + $this->belongsTo('Products', [ + 'foreignKey' => 'product_id', + 'className' => 'CakeProducts.Products', + ]); + $this->hasMany('ProductCategoryVariantOptions', [ + 'foreignKey' => 'product_category_variant_id', + 'className' => 'CakeProducts.ProductCategoryVariantOptions', + 'dependent' => true, + 'cascadeCallbacks' => true, + 'saveStrategy' => 'replace', + ]); - $this->hasMany('ProductVariants', [ - 'foreignKey' => 'product_category_variant_id', - 'className' => 'CakeProducts.ProductVariants', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - } + $this->hasMany('ProductVariants', [ + 'foreignKey' => 'product_category_variant_id', + 'className' => 'CakeProducts.ProductVariants', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->scalar('name') - ->maxLength('name', 255) - ->requirePresence('name', 'create') - ->notEmptyString('name'); + public function validationDefault(Validator $validator): Validator { + $validator + ->scalar('name') + ->maxLength('name', 255) + ->requirePresence('name', 'create') + ->notEmptyString('name'); - $validator - ->uuid('product_category_id') - ->allowEmptyString('product_category_id'); + $validator + ->uuid('product_category_id') + ->allowEmptyString('product_category_id'); - $validator - ->uuid('product_id') - ->allowEmptyString('product_id'); + $validator + ->uuid('product_id') + ->allowEmptyString('product_id'); - $validator - ->boolean('is_system_variant') - ->allowEmptyString('is_system_variant'); + $validator + ->boolean('is_system_variant') + ->allowEmptyString('is_system_variant'); - $validator - ->boolean('enabled') - ->requirePresence('enabled', 'create') - ->notEmptyString('enabled'); + $validator + ->boolean('enabled') + ->requirePresence('enabled', 'create') + ->notEmptyString('enabled'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']); - $rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']); - $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); - $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->isUnique(['name', 'product_category_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']); + $rules->add($rules->isUnique(['name', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_id']); + $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); + $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); - return $rules; - } + return $rules; + } - /** - * @param SelectQuery $query + /** + * @param \Cake\ORM\Query\SelectQuery $query * @param string $internalCategoryId * - * @return array|Query|SelectQuery + * @return Query|\Cake\ORM\Query\SelectQuery|array */ - public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) - { - $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); + public function findAllCategoryVariantsForCategoryId(SelectQuery $query, string $internalCategoryId) { + $category = $this->ProductCategories->find()->where(['internal_id' => $internalCategoryId])->firstOrFail(); - $this->ProductCategories->behaviors()->get('Tree')->setConfig([ - 'scope' => [ - 'product_catalog_id' => $category->product_catalog_id ?? 1, - ], - ]); + $this->ProductCategories->behaviors()->get('Tree')->setConfig([ + 'scope' => [ + 'product_catalog_id' => $category->product_catalog_id ?? 1, + ], + ]); - return $this->ProductCategories - ->find('path', for: $category->id) - ->contain(['ProductCategoryVariants']); - } + return $this->ProductCategories + ->find('path', for: $category->id) + ->contain(['ProductCategoryVariants']); + } - /** + /** * @param string $internalCategoryId * @return array */ - public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) - { - return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray(); - } + public function getAllCategoryVariantsForCategoryId(string $internalCategoryId) { + return $this->find('allCategoryVariantsForCategoryId', $internalCategoryId)->toArray(); + } + } diff --git a/src/Model/Table/ProductPhotosTable.php b/src/Model/Table/ProductPhotosTable.php index d89e565..66bfea1 100644 --- a/src/Model/Table/ProductPhotosTable.php +++ b/src/Model/Table/ProductPhotosTable.php @@ -4,16 +4,9 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; use Cake\Core\Configure; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Behavior\TimestampBehavior; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductPhoto; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductPhotos Model @@ -21,15 +14,15 @@ use Psr\SimpleCache\CacheInterface; * @property ProductsTable&BelongsTo $Products * @property ProductSkusTable&BelongsTo $ProductSkus * - * @method ProductPhoto newEmptyEntity() - * @method ProductPhoto newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductPhoto newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductPhoto get() + * @method \CakeProducts\Model\Entity\ProductPhoto findOrCreate() + * @method \CakeProducts\Model\Entity\ProductPhoto patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductPhoto|false save(EntityInterface $entity, array $options = []) - * @method ProductPhoto saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductPhoto saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) @@ -37,136 +30,134 @@ use Psr\SimpleCache\CacheInterface; * * @mixin TimestampBehavior */ -class ProductPhotosTable extends Table -{ - /** +class ProductPhotosTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_photos'); - $this->setDisplayField('photo_filename'); - $this->setPrimaryKey('id'); + $this->setTable('product_photos'); + $this->setDisplayField('photo_filename'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto') - ); + $this->setEntityClass( + Configure::read('CakeProducts.ProductPhotos.entity', 'CakeProducts\Model\Entity\ProductPhoto'), + ); - $this->addBehavior('Timestamp'); + $this->addBehavior('Timestamp'); - $this->addBehavior('Tools.Toggle', [ - 'field' => 'primary_category_photo', - 'scopeFields' => ['product_category_id'], - 'scope' => [ - 'deleted IS' => null, - ], - ]); - $this->addBehavior('CakeProducts.SecondToggle', [ - 'field' => 'primary_photo', - 'scopeFields' => ['product_id'], - 'scope' => [ - 'deleted IS' => null, - 'product_id IS NOT' => null, - ], - ]); - $this->addBehavior('CakeProducts.ThirdToggle', [ - 'field' => 'primary_sku_photo', - 'scopeFields' => ['product_sku_id'], - 'scope' => [ - 'deleted IS' => null, - 'product_sku_id IS NOT' => null, - ], - ]); - $this->belongsTo('Products', [ - 'foreignKey' => 'product_id', - 'joinType' => 'LEFT', - 'className' => 'CakeProducts.Products', - ]); + $this->addBehavior('Tools.Toggle', [ + 'field' => 'primary_category_photo', + 'scopeFields' => ['product_category_id'], + 'scope' => [ + 'deleted IS' => null, + ], + ]); + $this->addBehavior('CakeProducts.SecondToggle', [ + 'field' => 'primary_photo', + 'scopeFields' => ['product_id'], + 'scope' => [ + 'deleted IS' => null, + 'product_id IS NOT' => null, + ], + ]); + $this->addBehavior('CakeProducts.ThirdToggle', [ + 'field' => 'primary_sku_photo', + 'scopeFields' => ['product_sku_id'], + 'scope' => [ + 'deleted IS' => null, + 'product_sku_id IS NOT' => null, + ], + ]); + $this->belongsTo('Products', [ + 'foreignKey' => 'product_id', + 'joinType' => 'LEFT', + 'className' => 'CakeProducts.Products', + ]); - $this->belongsTo('ProductCategories', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'joinType' => 'INNER', - 'className' => 'CakeProducts.ProductCategories', - ]); + $this->belongsTo('ProductCategories', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'joinType' => 'INNER', + 'className' => 'CakeProducts.ProductCategories', + ]); - $this->belongsTo('ProductSkus', [ - 'foreignKey' => 'product_sku_id', - 'joinType' => 'LEFT', - 'className' => 'CakeProducts.ProductSkus', - ]); - } + $this->belongsTo('ProductSkus', [ + 'foreignKey' => 'product_sku_id', + 'joinType' => 'LEFT', + 'className' => 'CakeProducts.ProductSkus', + ]); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('product_id') - ->allowEmptyString('product_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('product_id') + ->allowEmptyString('product_id'); - $validator - ->uuid('product_sku_id') - ->allowEmptyString('product_sku_id'); + $validator + ->uuid('product_sku_id') + ->allowEmptyString('product_sku_id'); - $validator - ->uuid('product_category_id') - ->requirePresence('product_category_id', 'create') - ->notEmptyString('product_category_id'); + $validator + ->uuid('product_category_id') + ->requirePresence('product_category_id', 'create') + ->notEmptyString('product_category_id'); - $validator - ->scalar('photo_dir') - ->maxLength('photo_dir', 255) - ->requirePresence('photo_dir', 'create') - ->notEmptyString('photo_dir'); + $validator + ->scalar('photo_dir') + ->maxLength('photo_dir', 255) + ->requirePresence('photo_dir', 'create') + ->notEmptyString('photo_dir'); - $validator - ->scalar('photo_filename') - ->maxLength('photo_filename', 255) - ->requirePresence('photo_filename', 'create') - ->notEmptyString('photo_filename'); + $validator + ->scalar('photo_filename') + ->maxLength('photo_filename', 255) + ->requirePresence('photo_filename', 'create') + ->notEmptyString('photo_filename'); - $validator - ->boolean('primary_photo') - ->notEmptyString('primary_photo'); + $validator + ->boolean('primary_photo') + ->notEmptyString('primary_photo'); - $validator - ->integer('photo_position') - ->notEmptyString('photo_position'); + $validator + ->integer('photo_position') + ->notEmptyString('photo_position'); - $validator - ->boolean('enabled') - ->notEmptyString('enabled'); + $validator + ->boolean('enabled') + ->notEmptyString('enabled'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); - $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); - $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); + $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); + $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductSkuVariantValuesTable.php b/src/Model/Table/ProductSkuVariantValuesTable.php index dbe5e83..db7ae0e 100644 --- a/src/Model/Table/ProductSkuVariantValuesTable.php +++ b/src/Model/Table/ProductSkuVariantValuesTable.php @@ -3,16 +3,9 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductSkuVariantValue; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductSkuVariantValues Model @@ -21,92 +14,90 @@ use Psr\SimpleCache\CacheInterface; * @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductCategoryVariantOptionsTable&BelongsTo $ProductCategoryVariantOptions * - * @method ProductSkuVariantValue newEmptyEntity() - * @method ProductSkuVariantValue newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductSkuVariantValue newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductSkuVariantValue get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductSkuVariantValue findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductSkuVariantValue patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductSkuVariantValue get() + * @method \CakeProducts\Model\Entity\ProductSkuVariantValue findOrCreate() + * @method \CakeProducts\Model\Entity\ProductSkuVariantValue patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductSkuVariantValue|false save(EntityInterface $entity, array $options = []) - * @method ProductSkuVariantValue saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductSkuVariantValue saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductSkuVariantValuesTable extends Table -{ - /** +class ProductSkuVariantValuesTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_sku_variant_values'); - $this->setDisplayField('id'); - $this->setPrimaryKey('id'); + $this->setTable('product_sku_variant_values'); + $this->setDisplayField('id'); + $this->setPrimaryKey('id'); - $this->belongsTo('ProductSkus', [ - 'className' => 'CakeProducts.ProductSkus', - 'foreignKey' => 'product_sku_id', - 'propertyName' => 'product_sku', - 'joinType' => 'INNER', - ]); - $this->belongsTo('ProductVariants', [ - 'className' => 'CakeProducts.ProductVariants', - 'foreignKey' => 'product_variant_id', - 'joinType' => 'INNER', - ]); - $this->belongsTo('ProductCategoryVariantOptions', [ - 'className' => 'CakeProducts.ProductCategoryVariantOptions', - 'foreignKey' => 'product_category_variant_option_id', - 'joinType' => 'INNER', - ]); - } + $this->belongsTo('ProductSkus', [ + 'className' => 'CakeProducts.ProductSkus', + 'foreignKey' => 'product_sku_id', + 'propertyName' => 'product_sku', + 'joinType' => 'INNER', + ]); + $this->belongsTo('ProductVariants', [ + 'className' => 'CakeProducts.ProductVariants', + 'foreignKey' => 'product_variant_id', + 'joinType' => 'INNER', + ]); + $this->belongsTo('ProductCategoryVariantOptions', [ + 'className' => 'CakeProducts.ProductCategoryVariantOptions', + 'foreignKey' => 'product_category_variant_option_id', + 'joinType' => 'INNER', + ]); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('product_sku_id') - ->notEmptyString('product_sku_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('product_sku_id') + ->notEmptyString('product_sku_id'); - $validator - ->uuid('product_variant_id') - ->notEmptyString('product_variant_id'); + $validator + ->uuid('product_variant_id') + ->notEmptyString('product_variant_id'); - $validator - ->uuid('product_category_variant_option_id') - ->notEmptyString('product_category_variant_option_id'); + $validator + ->uuid('product_category_variant_option_id') + ->notEmptyString('product_category_variant_option_id'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']); - // @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add - $rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']); - $rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']); + // @TODO why not working?? causing tests to fail / associated variant values not saving on product-skus/add + $rules->add($rules->existsIn(['product_variant_id'], 'ProductVariants'), ['errorField' => 'product_variant_id']); + $rules->add($rules->existsIn(['product_category_variant_option_id'], 'ProductCategoryVariantOptions'), ['errorField' => 'product_category_variant_option_id']); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductSkusTable.php b/src/Model/Table/ProductSkusTable.php index 63ffe4f..dcd6dba 100644 --- a/src/Model/Table/ProductSkusTable.php +++ b/src/Model/Table/ProductSkusTable.php @@ -4,33 +4,24 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; use Cake\Core\Configure; -use Cake\ORM\Query\SelectQuery; -use CakeProducts\Model\Table\ProductsTable; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Behavior\TimestampBehavior; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\ProductSku; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductSkus Model * * @property ProductsTable&BelongsTo $Products * - * @method ProductSku newEmptyEntity() - * @method ProductSku newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductSku newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductSku newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductSku get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductSku get() + * @method \CakeProducts\Model\Entity\ProductSku findOrCreate() + * @method \CakeProducts\Model\Entity\ProductSku patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductSku|false save(EntityInterface $entity, array $options = []) - * @method ProductSku saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductSku saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) @@ -38,114 +29,112 @@ use Psr\SimpleCache\CacheInterface; * * @mixin TimestampBehavior */ -class ProductSkusTable extends Table -{ - /** +class ProductSkusTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_skus'); - $this->setDisplayField('sku'); - $this->setPrimaryKey('id'); + $this->setTable('product_skus'); + $this->setDisplayField('sku'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku') - ); + $this->setEntityClass( + Configure::read('CakeProducts.ProductSkus.entity', 'CakeProducts\Model\Entity\ProductSku'), + ); - $this->addBehavior('Timestamp'); - $this->addBehavior('Tools.Toggle', [ - 'field' => 'default_sku', - 'scopeFields' => ['product_id'], - 'scope' => [ - 'deleted IS' => null, - ], - ]); + $this->addBehavior('Timestamp'); + $this->addBehavior('Tools.Toggle', [ + 'field' => 'default_sku', + 'scopeFields' => ['product_id'], + 'scope' => [ + 'deleted IS' => null, + ], + ]); - $this->belongsTo('Products', [ - 'className' => 'CakeProducts.Products', - 'foreignKey' => 'product_id', - 'joinType' => 'INNER', - ]); + $this->belongsTo('Products', [ + 'className' => 'CakeProducts.Products', + 'foreignKey' => 'product_id', + 'joinType' => 'INNER', + ]); - $this->hasMany('ProductSkuVariantValues', [ - 'foreignKey' => 'product_sku_id', - 'className' => 'CakeProducts.ProductSkuVariantValues', - 'saveStrategy' => 'replace', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); + $this->hasMany('ProductSkuVariantValues', [ + 'foreignKey' => 'product_sku_id', + 'className' => 'CakeProducts.ProductSkuVariantValues', + 'saveStrategy' => 'replace', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); - $this->hasMany('ProductPhotos', [ - 'foreignKey' => 'product_sku_id', - 'className' => 'CakeProducts.ProductPhotos', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); + $this->hasMany('ProductPhotos', [ + 'foreignKey' => 'product_sku_id', + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); - $this->hasOne('PrimaryProductPhotos', [ - 'foreignKey' => 'product_sku_id', - 'conditions' => ['PrimaryProductPhotos.primary_photo' => true], - 'className' => 'CakeProducts.ProductPhotos', - 'dependent' => true, - ]); - } + $this->hasOne('PrimaryProductPhotos', [ + 'foreignKey' => 'product_sku_id', + 'conditions' => ['PrimaryProductPhotos.primary_photo' => true], + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + ]); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->uuid('product_id') - ->notEmptyString('product_id'); + public function validationDefault(Validator $validator): Validator { + $validator + ->uuid('product_id') + ->notEmptyString('product_id'); - $validator - ->scalar('sku') - ->maxLength('sku', 255) - ->requirePresence('sku', 'create') - ->notEmptyString('sku'); + $validator + ->scalar('sku') + ->maxLength('sku', 255) + ->requirePresence('sku', 'create') + ->notEmptyString('sku'); - $validator - ->scalar('barcode') - ->maxLength('barcode', 255) - ->allowEmptyString('barcode'); + $validator + ->scalar('barcode') + ->maxLength('barcode', 255) + ->allowEmptyString('barcode'); - $validator - ->decimal('price') - ->allowEmptyString('price'); + $validator + ->decimal('price') + ->allowEmptyString('price'); - $validator - ->decimal('cost') - ->allowEmptyString('cost'); + $validator + ->decimal('cost') + ->allowEmptyString('cost'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); - $rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); + $rules->add($rules->isUnique(['sku'], 'SKU must be unique'), ['errorField' => 'sku']); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductVariantsTable.php b/src/Model/Table/ProductVariantsTable.php index 4c759ed..4865680 100644 --- a/src/Model/Table/ProductVariantsTable.php +++ b/src/Model/Table/ProductVariantsTable.php @@ -3,18 +3,9 @@ declare(strict_types=1); namespace CakeProducts\Model\Table; -use CakeProducts\Model\Entity\ProductVariant; -use CakeProducts\Model\Table\ProductCategoryVariantsTable; -use CakeProducts\Model\Table\ProductsTable; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * ProductVariants Model @@ -22,96 +13,94 @@ use Psr\SimpleCache\CacheInterface; * @property ProductCategoryVariantsTable&BelongsTo $ProductCategoryVariants * @property ProductsTable&BelongsTo $Products * - * @method ProductVariant newEmptyEntity() - * @method ProductVariant newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductVariant newEmptyEntity() + * @method \CakeProducts\Model\Entity\ProductVariant newEntity() * @method array newEntities(array $data, array $options = []) - * @method ProductVariant get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method ProductVariant findOrCreate($search, ?callable $callback = null, array $options = []) - * @method ProductVariant patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\ProductVariant get() + * @method \CakeProducts\Model\Entity\ProductVariant findOrCreate() + * @method \CakeProducts\Model\Entity\ProductVariant patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method ProductVariant|false save(EntityInterface $entity, array $options = []) - * @method ProductVariant saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\ProductVariant saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductVariantsTable extends Table -{ - /** +class ProductVariantsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('product_variants'); - $this->setDisplayField('name'); - $this->setPrimaryKey('id'); + $this->setTable('product_variants'); + $this->setDisplayField('name'); + $this->setPrimaryKey('id'); - $this->belongsTo('ProductCategoryVariants', [ - 'className' => 'CakeProducts.ProductCategoryVariants', - 'foreignKey' => 'product_category_variant_id', - ]); - $this->belongsTo('Products', [ - 'className' => 'CakeProducts.Products', - 'foreignKey' => 'product_id', - 'joinType' => 'INNER', - ]); + $this->belongsTo('ProductCategoryVariants', [ + 'className' => 'CakeProducts.ProductCategoryVariants', + 'foreignKey' => 'product_category_variant_id', + ]); + $this->belongsTo('Products', [ + 'className' => 'CakeProducts.Products', + 'foreignKey' => 'product_id', + 'joinType' => 'INNER', + ]); - $this->hasMany('ProductSkuVariantValues', [ - 'className' => 'CakeProducts.ProductSkuVariantValues', - 'foreignKey' => 'product_variant_id', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); - } + $this->hasMany('ProductSkuVariantValues', [ + 'className' => 'CakeProducts.ProductSkuVariantValues', + 'foreignKey' => 'product_variant_id', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->scalar('name') - ->maxLength('name', 255) - ->requirePresence('name', 'create') - ->notEmptyString('name'); + public function validationDefault(Validator $validator): Validator { + $validator + ->scalar('name') + ->maxLength('name', 255) + ->requirePresence('name', 'create') + ->notEmptyString('name'); - $validator - ->uuid('product_category_variant_id') - ->allowEmptyString('product_category_variant_id'); + $validator + ->uuid('product_category_variant_id') + ->allowEmptyString('product_category_variant_id'); - $validator - ->uuid('product_id') - ->notEmptyString('product_id'); + $validator + ->uuid('product_id') + ->notEmptyString('product_id'); - $validator - ->boolean('enabled') - ->requirePresence('enabled', 'create') - ->notEmptyString('enabled'); + $validator + ->boolean('enabled') + ->requirePresence('enabled', 'create') + ->notEmptyString('enabled'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); - $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->existsIn(['product_category_variant_id'], 'ProductCategoryVariants'), ['errorField' => 'product_category_variant_id']); + $rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']); + + return $rules; + } - return $rules; - } } diff --git a/src/Model/Table/ProductsTable.php b/src/Model/Table/ProductsTable.php index 1cd285f..4d2a8ee 100644 --- a/src/Model/Table/ProductsTable.php +++ b/src/Model/Table/ProductsTable.php @@ -5,154 +5,145 @@ namespace CakeProducts\Model\Table; use Cake\Core\Configure; use Cake\Database\Type\EnumType; -use Cake\Datasource\EntityInterface; -use Cake\Datasource\ResultSetInterface; -use Cake\ORM\Association\BelongsTo; -use Cake\ORM\Query\SelectQuery; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; -use CakeProducts\Model\Entity\Product; use CakeProducts\Model\Enum\ProductProductTypeId; -use Closure; -use Psr\SimpleCache\CacheInterface; /** * Products Model * * @property ProductCategoriesTable&BelongsTo $ProductCategories * - * @method Product newEmptyEntity() - * @method Product newEntity(array $data, array $options = []) + * @method \CakeProducts\Model\Entity\Product newEmptyEntity() + * @method \CakeProducts\Model\Entity\Product newEntity() * @method array newEntities(array $data, array $options = []) - * @method Product get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args) - * @method Product findOrCreate($search, ?callable $callback = null, array $options = []) - * @method Product patchEntity(EntityInterface $entity, array $data, array $options = []) + * @method \CakeProducts\Model\Entity\Product get() + * @method \CakeProducts\Model\Entity\Product findOrCreate() + * @method \CakeProducts\Model\Entity\Product patchEntity() * @method array patchEntities(iterable $entities, array $data, array $options = []) * @method Product|false save(EntityInterface $entity, array $options = []) - * @method Product saveOrFail(EntityInterface $entity, array $options = []) + * @method \CakeProducts\Model\Entity\Product saveOrFail() * @method iterable|ResultSetInterface|false saveMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface saveManyOrFail(iterable $entities, array $options = []) * @method iterable|ResultSetInterface|false deleteMany(iterable $entities, array $options = []) * @method iterable|ResultSetInterface deleteManyOrFail(iterable $entities, array $options = []) */ -class ProductsTable extends Table -{ - /** +class ProductsTable extends Table { + + /** * Initialize method * * @param array $config The configuration for the Table. * @return void */ - public function initialize(array $config): void - { - parent::initialize($config); + public function initialize(array $config): void { + parent::initialize($config); - $this->setTable('products'); - $this->setDisplayField('name'); - $this->setPrimaryKey('id'); + $this->setTable('products'); + $this->setDisplayField('name'); + $this->setPrimaryKey('id'); - $this->setEntityClass( - Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product') - ); + $this->setEntityClass( + Configure::read('CakeProducts.Products.entity', 'CakeProducts\Model\Entity\Product'), + ); - $this->belongsTo('ProductCategories', [ - 'foreignKey' => 'product_category_id', - 'bindingKey' => 'internal_id', - 'joinType' => 'INNER', - 'className' => 'CakeProducts.ProductCategories', - ]); + $this->belongsTo('ProductCategories', [ + 'foreignKey' => 'product_category_id', + 'bindingKey' => 'internal_id', + 'joinType' => 'INNER', + 'className' => 'CakeProducts.ProductCategories', + ]); - $this->hasMany('ProductAttributes', [ - 'className' => 'CakeProducts.ProductAttributes', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); + $this->hasMany('ProductAttributes', [ + 'className' => 'CakeProducts.ProductAttributes', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); - $this->hasMany('ProductVariants', [ - 'foreignKey' => 'product_id', - 'className' => 'CakeProducts.ProductVariants', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); + $this->hasMany('ProductVariants', [ + 'foreignKey' => 'product_id', + 'className' => 'CakeProducts.ProductVariants', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); - $this->hasMany('ProductSkus', [ - 'foreignKey' => 'product_id', - 'className' => 'CakeProducts.ProductSkus', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); + $this->hasMany('ProductSkus', [ + 'foreignKey' => 'product_id', + 'className' => 'CakeProducts.ProductSkus', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); - $this->hasMany('ProductPhotos', [ - 'foreignKey' => 'product_id', - 'className' => 'CakeProducts.ProductPhotos', - 'dependent' => true, - 'cascadeCallbacks' => true, - ]); + $this->hasMany('ProductPhotos', [ + 'foreignKey' => 'product_id', + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); - $this->hasOne('PrimaryProductPhotos', [ - 'foreignKey' => 'product_id', - 'conditions' => ['PrimaryProductPhotos.primary_photo' => true], - 'className' => 'CakeProducts.ProductPhotos', - 'dependent' => true, - ]); + $this->hasOne('PrimaryProductPhotos', [ + 'foreignKey' => 'product_id', + 'conditions' => ['PrimaryProductPhotos.primary_photo' => true], + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + ]); - $this->hasOne('DefaultProductSkus', [ - 'foreignKey' => 'product_id', - 'conditions' => ['DefaultProductSkus.default_sku' => true], - 'className' => 'CakeProducts.ProductSkus', - 'propertyName' => 'default_product_sku', - 'dependent' => true, - ]); + $this->hasOne('DefaultProductSkus', [ + 'foreignKey' => 'product_id', + 'conditions' => ['DefaultProductSkus.default_sku' => true], + 'className' => 'CakeProducts.ProductSkus', + 'propertyName' => 'default_product_sku', + 'dependent' => true, + ]); - $this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class)); + $this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class)); - $this->addBehavior('Muffin/Trash.Trash'); - } + $this->addBehavior('Muffin/Trash.Trash'); + } - /** + /** * Default validation rules. * - * @param Validator $validator Validator instance. - * @return Validator + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator */ - public function validationDefault(Validator $validator): Validator - { - $validator - ->scalar('name') - ->maxLength('name', 255) - ->requirePresence('name', 'create') - ->notEmptyString('name'); + public function validationDefault(Validator $validator): Validator { + $validator + ->scalar('name') + ->maxLength('name', 255) + ->requirePresence('name', 'create') + ->notEmptyString('name'); - $validator - ->uuid('product_category_id') - ->notEmptyString('product_category_id'); + $validator + ->uuid('product_category_id') + ->notEmptyString('product_category_id'); - $validator - ->integer('product_type_id') - ->requirePresence('product_type_id', 'create') - ->notEmptyString('product_type_id'); + $validator + ->integer('product_type_id') + ->requirePresence('product_type_id', 'create') + ->notEmptyString('product_type_id'); - $validator - ->dateTime('deleted') - ->allowEmptyDateTime('deleted'); + $validator + ->dateTime('deleted') + ->allowEmptyDateTime('deleted'); - return $validator; - } + return $validator; + } - /** + /** * Returns a rules checker object that will be used for validating * application integrity. * - * @param RulesChecker $rules The rules object to be modified. - * @return RulesChecker + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker */ - public function buildRules(RulesChecker $rules): RulesChecker - { - $rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']); - $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); + public function buildRules(RulesChecker $rules): RulesChecker { + $rules->add($rules->isUnique(['product_category_id', 'name']), ['errorField' => 'product_category_id']); + $rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']); // $rules->add($rules->validCount('product_attributes', 0, '<=', 'You must not have any tags')); - return $rules; - } + return $rules; + } + } diff --git a/tests/Fixture/ExternalProductCatalogsFixture.php b/tests/Fixture/ExternalProductCatalogsFixture.php index 29664cb..b931166 100644 --- a/tests/Fixture/ExternalProductCatalogsFixture.php +++ b/tests/Fixture/ExternalProductCatalogsFixture.php @@ -8,24 +8,24 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ExternalProductCatalogsFixture */ -class ExternalProductCatalogsFixture extends TestFixture -{ - /** +class ExternalProductCatalogsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '115153f3-2f59-4234-8ff8-e1b205769999', - 'base_url' => 'http://localhost:8766', - 'api_url' => 'http://localhost:8766/api', - 'created' => '2024-11-22 09:39:37', - 'deleted' => null, - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => '115153f3-2f59-4234-8ff8-e1b205769999', + 'base_url' => 'http://localhost:8766', + 'api_url' => 'http://localhost:8766/api', + 'created' => '2024-11-22 09:39:37', + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ExternalProductCatalogsProductCatalogsFixture.php b/tests/Fixture/ExternalProductCatalogsProductCatalogsFixture.php index 7c589dc..1c66b8c 100644 --- a/tests/Fixture/ExternalProductCatalogsProductCatalogsFixture.php +++ b/tests/Fixture/ExternalProductCatalogsProductCatalogsFixture.php @@ -8,25 +8,25 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ExternalProductCatalogsProductCatalogsFixture */ -class ExternalProductCatalogsProductCatalogsFixture extends TestFixture -{ - /** +class ExternalProductCatalogsProductCatalogsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => 1, - 'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999', - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'created' => '2024-11-22 09:39:37', - 'enabled' => false, - 'deleted' => null, - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => 1, + 'external_product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205769999', + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'created' => '2024-11-22 09:39:37', + 'enabled' => false, + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductAttributesFixture.php b/tests/Fixture/ProductAttributesFixture.php index 953e7da..e5a64f7 100644 --- a/tests/Fixture/ProductAttributesFixture.php +++ b/tests/Fixture/ProductAttributesFixture.php @@ -8,18 +8,16 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductAttributesFixture */ -class ProductAttributesFixture extends TestFixture -{ - /** +class ProductAttributesFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ + public function init(): void { + $this->records = []; + parent::init(); + } - ]; - parent::init(); - } } diff --git a/tests/Fixture/ProductCatalogsFixture.php b/tests/Fixture/ProductCatalogsFixture.php index b2be958..566af6d 100644 --- a/tests/Fixture/ProductCatalogsFixture.php +++ b/tests/Fixture/ProductCatalogsFixture.php @@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductCatalogsFixture */ -class ProductCatalogsFixture extends TestFixture -{ - /** +class ProductCatalogsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'name' => 'Automotive', - 'catalog_description' => '', - 'enabled' => true, - 'deleted' => null, - ], - [ - 'id' => 'f56f3412-ed23-490b-be6e-016208c415d2', - 'name' => 'Software', - 'catalog_description' => '', - 'enabled' => true, - 'deleted' => null, - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'name' => 'Automotive', + 'catalog_description' => '', + 'enabled' => true, + 'deleted' => null, + ], + [ + 'id' => 'f56f3412-ed23-490b-be6e-016208c415d2', + 'name' => 'Software', + 'catalog_description' => '', + 'enabled' => true, + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductCategoriesFixture.php b/tests/Fixture/ProductCategoriesFixture.php index 0f40eb7..c0d05b5 100644 --- a/tests/Fixture/ProductCategoriesFixture.php +++ b/tests/Fixture/ProductCategoriesFixture.php @@ -8,101 +8,101 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductCategoriesFixture */ -class ProductCategoriesFixture extends TestFixture -{ - /** +class ProductCategoriesFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => 1, - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'name' => 'Engine', - 'category_description' => '', - 'parent_id' => null, - 'lft' => 1, - 'rght' => 4, - 'enabled' => true, - 'deleted' => null, - ], - [ - 'id' => 2, - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b', - 'name' => 'Engine Internals', - 'category_description' => '', - 'parent_id' => 1, - 'lft' => 2, - 'rght' => 3, - 'enabled' => true, - 'deleted' => null, - ], - [ - 'id' => 3, - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83', - 'name' => 'Electrical', - 'category_description' => '', - 'parent_id' => null, - 'lft' => 5, - 'rght' => 8, - 'enabled' => true, - 'deleted' => null, - ], - [ - 'id' => 4, - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'name' => 'Wiring', - 'category_description' => '', - 'parent_id' => 3, - 'lft' => 6, - 'rght' => 7, - 'enabled' => true, - 'deleted' => null, - ], - [ - 'id' => 5, - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a', - 'name' => 'Suspension', - 'category_description' => '', - 'parent_id' => null, - 'lft' => 9, - 'rght' => 12, - 'enabled' => true, - 'deleted' => null, - ], - [ - 'id' => 6, - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e', - 'name' => 'Coilovers', - 'category_description' => '', - 'parent_id' => 5, - 'lft' => 10, - 'rght' => 11, - 'enabled' => true, - 'deleted' => null, - ], - [ - 'id' => 7, - 'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2', - 'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a', - 'name' => 'Support', - 'category_description' => '', - 'parent_id' => null, - 'lft' => 1, - 'rght' => 2, - 'enabled' => true, - 'deleted' => null, - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => 1, + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'internal_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'name' => 'Engine', + 'category_description' => '', + 'parent_id' => null, + 'lft' => 1, + 'rght' => 4, + 'enabled' => true, + 'deleted' => null, + ], + [ + 'id' => 2, + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'internal_id' => '3c2377c5-b97c-4bc9-9660-8f77b4893d8b', + 'name' => 'Engine Internals', + 'category_description' => '', + 'parent_id' => 1, + 'lft' => 2, + 'rght' => 3, + 'enabled' => true, + 'deleted' => null, + ], + [ + 'id' => 3, + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'internal_id' => 'fbee6709-396f-4bb4-b60b-e125b0bc4e83', + 'name' => 'Electrical', + 'category_description' => '', + 'parent_id' => null, + 'lft' => 5, + 'rght' => 8, + 'enabled' => true, + 'deleted' => null, + ], + [ + 'id' => 4, + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'internal_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'name' => 'Wiring', + 'category_description' => '', + 'parent_id' => 3, + 'lft' => 6, + 'rght' => 7, + 'enabled' => true, + 'deleted' => null, + ], + [ + 'id' => 5, + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'internal_id' => 'c447b6f4-0fb1-4d59-ba45-5613829a725a', + 'name' => 'Suspension', + 'category_description' => '', + 'parent_id' => null, + 'lft' => 9, + 'rght' => 12, + 'enabled' => true, + 'deleted' => null, + ], + [ + 'id' => 6, + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'internal_id' => '1e749d3b-aee0-48a5-8d6c-8cf2b83e9b6e', + 'name' => 'Coilovers', + 'category_description' => '', + 'parent_id' => 5, + 'lft' => 10, + 'rght' => 11, + 'enabled' => true, + 'deleted' => null, + ], + [ + 'id' => 7, + 'product_catalog_id' => 'f56f3412-ed23-490b-be6e-016208c415d2', + 'internal_id' => '8c89a3ca-d56f-46bf-a738-7e85b3342b2a', + 'name' => 'Support', + 'category_description' => '', + 'parent_id' => null, + 'lft' => 1, + 'rght' => 2, + 'enabled' => true, + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductCategoryAttributeOptionsFixture.php b/tests/Fixture/ProductCategoryAttributeOptionsFixture.php index 6e5713c..5768773 100644 --- a/tests/Fixture/ProductCategoryAttributeOptionsFixture.php +++ b/tests/Fixture/ProductCategoryAttributeOptionsFixture.php @@ -8,41 +8,41 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductCategoryAttributeOptionsFixture */ -class ProductCategoryAttributeOptionsFixture extends TestFixture -{ - /** +class ProductCategoryAttributeOptionsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => 'e06f1723-2456-483a-b3c4-004603e032a8', - 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', - 'attribute_value' => 'Red', - 'attribute_label' => 'Red', - 'enabled' => 1, - 'deleted' => null, - ], - [ - 'id' => 'e06f1723-2456-483a-b3c4-004603e032a1', - 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', - 'attribute_value' => 'Blue', - 'attribute_label' => 'Blue', - 'enabled' => 1, - 'deleted' => null, - ], - [ - 'id' => 'e06f1723-2456-483a-b3c4-004603e032a2', - 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', - 'attribute_value' => 'Green', - 'attribute_label' => 'Green', - 'enabled' => 1, - 'deleted' => null, - ] - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => 'e06f1723-2456-483a-b3c4-004603e032a8', + 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', + 'attribute_value' => 'Red', + 'attribute_label' => 'Red', + 'enabled' => 1, + 'deleted' => null, + ], + [ + 'id' => 'e06f1723-2456-483a-b3c4-004603e032a1', + 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', + 'attribute_value' => 'Blue', + 'attribute_label' => 'Blue', + 'enabled' => 1, + 'deleted' => null, + ], + [ + 'id' => 'e06f1723-2456-483a-b3c4-004603e032a2', + 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', + 'attribute_value' => 'Green', + 'attribute_label' => 'Green', + 'enabled' => 1, + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductCategoryAttributesFixture.php b/tests/Fixture/ProductCategoryAttributesFixture.php index 1a40375..4228022 100644 --- a/tests/Fixture/ProductCategoryAttributesFixture.php +++ b/tests/Fixture/ProductCategoryAttributesFixture.php @@ -8,25 +8,25 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductCategoryAttributesFixture */ -class ProductCategoryAttributesFixture extends TestFixture -{ - /** +class ProductCategoryAttributesFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', - 'name' => 'Color', - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'attribute_type_id' => 1, - 'enabled' => 1, - 'deleted' => null, - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', + 'name' => 'Color', + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'attribute_type_id' => 1, + 'enabled' => 1, + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductCategoryVariantOptionsFixture.php b/tests/Fixture/ProductCategoryVariantOptionsFixture.php index c21c0cc..1e0d429 100644 --- a/tests/Fixture/ProductCategoryVariantOptionsFixture.php +++ b/tests/Fixture/ProductCategoryVariantOptionsFixture.php @@ -8,92 +8,91 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductCategoryVariantsFixture */ -class ProductCategoryVariantOptionsFixture extends TestFixture -{ - /** +class ProductCategoryVariantOptionsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', - 'variant_value' => 'Blue', - 'variant_label' => null, - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24', - 'variant_value' => 'Red', - 'variant_label' => null, - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], + public function init(): void { + $this->records = [ + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', + 'variant_value' => 'Blue', + 'variant_label' => null, + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24', + 'variant_value' => 'Red', + 'variant_label' => null, + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21', + 'variant_value' => '12AWG', + 'variant_label' => null, + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d22', + 'variant_value' => '14AWG', + 'variant_label' => null, + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d21', - 'variant_value' => '12AWG', - 'variant_label' => null, - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d22', - 'variant_value' => '14AWG', - 'variant_label' => null, - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', + 'variant_value' => 'Months', + 'variant_label' => 'Months', + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78112', + 'variant_value' => 'Years', + 'variant_label' => 'Years', + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221', + 'variant_value' => '6', + 'variant_label' => '6', + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222', + 'variant_value' => 12, + 'variant_label' => 12, + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222', + 'created' => '2025-07-04 12:00:00', + 'modified' => '2025-07-04 12:00:00', + 'enabled' => 1, + ], + ]; + parent::init(); + } - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', - 'variant_value' => 'Months', - 'variant_label' => 'Months', - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78112', - 'variant_value' => 'Years', - 'variant_label' => 'Years', - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221', - 'variant_value' => '6', - 'variant_label' => '6', - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222', - 'variant_value' => 12, - 'variant_label' => 12, - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222', - 'created' => '2025-07-04 12:00:00', - 'modified' => '2025-07-04 12:00:00', - 'enabled' => 1, - ], - ]; - parent::init(); - } } diff --git a/tests/Fixture/ProductCategoryVariantsFixture.php b/tests/Fixture/ProductCategoryVariantsFixture.php index 0577222..8b84be3 100644 --- a/tests/Fixture/ProductCategoryVariantsFixture.php +++ b/tests/Fixture/ProductCategoryVariantsFixture.php @@ -8,46 +8,46 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductCategoryVariantsFixture */ -class ProductCategoryVariantsFixture extends TestFixture -{ - /** +class ProductCategoryVariantsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', - 'name' => 'Subscription Length Units', - 'product_category_id' => null, - 'enabled' => true, - 'is_system_variant' => true, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222', - 'name' => 'Subscription Length', - 'product_category_id' => null, - 'enabled' => true, - 'is_system_variant' => true, - ], + public function init(): void { + $this->records = [ + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78111', + 'name' => 'Subscription Length Units', + 'product_category_id' => null, + 'enabled' => true, + 'is_system_variant' => true, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78222', + 'name' => 'Subscription Length', + 'product_category_id' => null, + 'enabled' => true, + 'is_system_variant' => true, + ], + + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', + 'name' => 'Color', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'enabled' => true, + 'is_system_variant' => false, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', + 'name' => 'AWG', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'enabled' => true, + 'is_system_variant' => false, + ], + ]; + parent::init(); + } - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', - 'name' => 'Color', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'enabled' => true, - 'is_system_variant' => false, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', - 'name' => 'AWG', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'enabled' => true, - 'is_system_variant' => false, - ], - ]; - parent::init(); - } } diff --git a/tests/Fixture/ProductPhotosFixture.php b/tests/Fixture/ProductPhotosFixture.php index ee177b3..82e1797 100644 --- a/tests/Fixture/ProductPhotosFixture.php +++ b/tests/Fixture/ProductPhotosFixture.php @@ -8,116 +8,116 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductPhotosFixture */ -class ProductPhotosFixture extends TestFixture -{ - /** +class ProductPhotosFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'product_sku_id' => null, - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', - 'primary_photo' => 1, - 'primary_category_photo' => 0, - 'primary_sku_photo' => 0, - 'photo_position' => 100, - 'enabled' => 1, - 'created' => '2025-08-10 04:32:10', - 'modified' => '2025-08-10 04:32:10', - 'deleted' => null, - ], + public function init(): void { + $this->records = [ + [ + 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f58', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'product_sku_id' => null, + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', + 'primary_photo' => 1, + 'primary_category_photo' => 0, + 'primary_sku_photo' => 0, + 'photo_position' => 100, + 'enabled' => 1, + 'created' => '2025-08-10 04:32:10', + 'modified' => '2025-08-10 04:32:10', + 'deleted' => null, + ], - [ - 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'product_sku_id' => null, - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'photo_dir' => 'categories', - 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', - 'primary_photo' => 0, - 'primary_category_photo' => 1, - 'primary_sku_photo' => 0, - 'photo_position' => 100, - 'enabled' => 1, - 'created' => '2025-08-10 04:32:10', - 'modified' => '2025-08-10 04:32:10', - 'deleted' => null, - ], + [ + 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f51', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'product_sku_id' => null, + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'photo_dir' => 'categories', + 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', + 'primary_photo' => 0, + 'primary_category_photo' => 1, + 'primary_sku_photo' => 0, + 'photo_position' => 100, + 'enabled' => 1, + 'created' => '2025-08-10 04:32:10', + 'modified' => '2025-08-10 04:32:10', + 'deleted' => null, + ], - [ - 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'product_sku_id' => null, - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', - 'primary_photo' => 0, - 'primary_category_photo' => 0, - 'primary_sku_photo' => 0, - 'photo_position' => 100, - 'enabled' => 1, - 'created' => '2025-08-10 04:32:10', - 'modified' => '2025-08-10 04:32:10', - 'deleted' => null, - ], - [ - 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f53', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'product_sku_id' => null, - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'photo_dir' => 'categories', - 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', - 'primary_photo' => 0, - 'primary_category_photo' => 0, - 'primary_sku_photo' => 0, - 'photo_position' => 100, - 'enabled' => 1, - 'created' => '2025-08-10 04:32:10', - 'modified' => '2025-08-10 04:32:10', - 'deleted' => null, - ], + [ + 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f50', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'product_sku_id' => null, + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', + 'primary_photo' => 0, + 'primary_category_photo' => 0, + 'primary_sku_photo' => 0, + 'photo_position' => 100, + 'enabled' => 1, + 'created' => '2025-08-10 04:32:10', + 'modified' => '2025-08-10 04:32:10', + 'deleted' => null, + ], + [ + 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f53', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'product_sku_id' => null, + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'photo_dir' => 'categories', + 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', + 'primary_photo' => 0, + 'primary_category_photo' => 0, + 'primary_sku_photo' => 0, + 'photo_position' => 100, + 'enabled' => 1, + 'created' => '2025-08-10 04:32:10', + 'modified' => '2025-08-10 04:32:10', + 'deleted' => null, + ], + + [ + 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f11', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979', + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', + 'primary_photo' => 0, + 'primary_category_photo' => 0, + 'primary_sku_photo' => 1, + 'photo_position' => 100, + 'enabled' => 1, + 'created' => '2025-08-10 04:32:10', + 'modified' => '2025-08-10 04:32:10', + 'deleted' => null, + ], + [ + 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f12', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979', + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', + 'primary_photo' => 0, + 'primary_category_photo' => 0, + 'primary_sku_photo' => 0, + 'photo_position' => 100, + 'enabled' => 1, + 'created' => '2025-08-10 04:32:10', + 'modified' => '2025-08-10 04:32:10', + 'deleted' => null, + ], + ]; + parent::init(); + } - [ - 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f11', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979', - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f58.png', - 'primary_photo' => 0, - 'primary_category_photo' => 0, - 'primary_sku_photo' => 1, - 'photo_position' => 100, - 'enabled' => 1, - 'created' => '2025-08-10 04:32:10', - 'modified' => '2025-08-10 04:32:10', - 'deleted' => null, - ], - [ - 'id' => '2c386086-f4c5-4093-bea5-ee9c29479f12', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979', - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'photo_dir' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'photo_filename' => '2c386086-f4c5-4093-bea5-ee9c29479f51.png', - 'primary_photo' => 0, - 'primary_category_photo' => 0, - 'primary_sku_photo' => 0, - 'photo_position' => 100, - 'enabled' => 1, - 'created' => '2025-08-10 04:32:10', - 'modified' => '2025-08-10 04:32:10', - 'deleted' => null, - ], - ]; - parent::init(); - } } diff --git a/tests/Fixture/ProductSkuVariantValuesFixture.php b/tests/Fixture/ProductSkuVariantValuesFixture.php index 3d1c057..5fc1c28 100644 --- a/tests/Fixture/ProductSkuVariantValuesFixture.php +++ b/tests/Fixture/ProductSkuVariantValuesFixture.php @@ -8,30 +8,30 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductSkuVariantValuesFixture */ -class ProductSkuVariantValuesFixture extends TestFixture -{ - /** +class ProductSkuVariantValuesFixture extends TestFixture { + + /** * Table name * * @var string */ - public string $table = 'product_sku_variant_values'; + public string $table = 'product_sku_variant_values'; - /** + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56', - 'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979', - 'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569', - 'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56', + 'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979', + 'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569', + 'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductSkusFixture.php b/tests/Fixture/ProductSkusFixture.php index 6bc872e..1004b78 100644 --- a/tests/Fixture/ProductSkusFixture.php +++ b/tests/Fixture/ProductSkusFixture.php @@ -8,34 +8,35 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductSkusFixture */ -class ProductSkusFixture extends TestFixture -{ - /** +class ProductSkusFixture extends TestFixture { + + /** * Table name * * @var string */ - public string $table = 'product_skus'; - /** + public string $table = 'product_skus'; + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '3a477e3e-7977-4813-81f6-f85949613979', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'sku' => '3a477e3e-7977-4813-81f6-f85949613979', - 'barcode' => '3a477e3e-7977-4813-81f6-f85949613979', - 'price' => 1.5, - 'cost' => 1.5, - 'created' => '2025-04-15 09:09:15', - 'modified' => '2025-04-15 09:09:15', - 'deleted' => null, - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => '3a477e3e-7977-4813-81f6-f85949613979', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'sku' => '3a477e3e-7977-4813-81f6-f85949613979', + 'barcode' => '3a477e3e-7977-4813-81f6-f85949613979', + 'price' => 1.5, + 'cost' => 1.5, + 'created' => '2025-04-15 09:09:15', + 'modified' => '2025-04-15 09:09:15', + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductVariantsFixture.php b/tests/Fixture/ProductVariantsFixture.php index fc654a9..d127985 100644 --- a/tests/Fixture/ProductVariantsFixture.php +++ b/tests/Fixture/ProductVariantsFixture.php @@ -8,45 +8,45 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductVariantsFixture */ -class ProductVariantsFixture extends TestFixture -{ - /** +class ProductVariantsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568', - 'name' => 'Color', - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'enabled' => 1, - ], - [ - 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569', - 'name' => 'Color', - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', - 'enabled' => 1, - ], - [ - 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561', - 'name' => 'AWG', - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'enabled' => 1, - ], - [ - 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562', - 'name' => 'AWG', - 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', - 'enabled' => 1, - ] - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568', + 'name' => 'Color', + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'enabled' => 1, + ], + [ + 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569', + 'name' => 'Color', + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', + 'enabled' => 1, + ], + [ + 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72561', + 'name' => 'AWG', + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'enabled' => 1, + ], + [ + 'id' => '2e6e4031-c430-4d07-b8d6-a4e759b72562', + 'name' => 'AWG', + 'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94', + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', + 'enabled' => 1, + ], + ]; + parent::init(); + } + } diff --git a/tests/Fixture/ProductsFixture.php b/tests/Fixture/ProductsFixture.php index 6138569..ec31dbf 100644 --- a/tests/Fixture/ProductsFixture.php +++ b/tests/Fixture/ProductsFixture.php @@ -8,31 +8,31 @@ use Cake\TestSuite\Fixture\TestFixture; /** * ProductsFixture */ -class ProductsFixture extends TestFixture -{ - /** +class ProductsFixture extends TestFixture { + + /** * Init method * * @return void */ - public function init(): void - { - $this->records = [ - [ - 'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'name' => '12AWG RED TXL Wire', - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'product_type_id' => 1, - 'deleted' => null, - ], - [ - 'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', - 'name' => 'Heat Shrink', - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'product_type_id' => 1, - 'deleted' => null, - ], - ]; - parent::init(); - } + public function init(): void { + $this->records = [ + [ + 'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'name' => '12AWG RED TXL Wire', + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'product_type_id' => 1, + 'deleted' => null, + ], + [ + 'id' => 'cfc98a9a-29b2-44c8-b587-8156adc05318', + 'name' => 'Heat Shrink', + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'product_type_id' => 1, + 'deleted' => null, + ], + ]; + parent::init(); + } + } diff --git a/tests/TestCase/Controller/BaseControllerTest.php b/tests/TestCase/Controller/BaseControllerTest.php index 5bc56d4..f6836af 100644 --- a/tests/TestCase/Controller/BaseControllerTest.php +++ b/tests/TestCase/Controller/BaseControllerTest.php @@ -14,55 +14,52 @@ use RecursiveIteratorIterator; * * Used to make logging in easier and to handle folder structure for product images */ -class BaseControllerTest extends TestCase -{ - use IntegrationTestTrait; +class BaseControllerTest extends TestCase { - public function loginUserByRole(string $role = 'admin'): void - { - $this->session(['Auth.User.id' => 1]); - $this->session(['Auth.id' => 1]); - } + use IntegrationTestTrait; - /** + public function loginUserByRole(string $role = 'admin'): void { + $this->session(['Auth.User.id' => 1]); + $this->session(['Auth.id' => 1]); + } + + /** * @return void */ - public function testTest() - { - $this->assertEquals(1, 1); - } + public function testTest() { + $this->assertEquals(1, 1); + } - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; - $productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS . - 'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; - if (file_exists($toCopy)) { - if (!file_exists($productsFolder)) { - mkdir($productsFolder, 0775, true); - } - copy($toCopy, $newName); - } - } + protected function setUp(): void { + parent::setUp(); + $toCopy = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'images' . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; + $productsFolder = PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS + . 'images' . DS . 'products' . DS . 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $newName = $productsFolder . DS . '2c386086-f4c5-4093-bea5-ee9c29479f58.png'; + if (file_exists($toCopy)) { + if (!file_exists($productsFolder)) { + mkdir($productsFolder, 0775, true); + } + copy($toCopy, $newName); + } + } - protected function tearDown(): void - { - parent::tearDown(); // TODO: Change the autogenerated stub + protected function tearDown(): void { + parent::tearDown(); // TODO: Change the autogenerated stub + + $path = Configure::readOrFail('CakeProducts.photos.directory'); + if (file_exists($path)) { + $di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); + $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); + foreach ($ri as $file) { + $file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath()); + } + } + } - $path = Configure::readOrFail('CakeProducts.photos.directory'); - if (file_exists($path)) { - $di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS); - $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); - foreach ( $ri as $file ) { - $file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath()); - } - } - } } diff --git a/tests/TestCase/Controller/ExternalProductCatalogsControllerTest.php b/tests/TestCase/Controller/ExternalProductCatalogsControllerTest.php index 50a151f..c05f5c5 100644 --- a/tests/TestCase/Controller/ExternalProductCatalogsControllerTest.php +++ b/tests/TestCase/Controller/ExternalProductCatalogsControllerTest.php @@ -4,332 +4,317 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; use Cake\Log\Log; -use Cake\ORM\Table; use Cake\ORM\TableRegistry; -use Cake\TestSuite\IntegrationTestTrait; -use Cake\TestSuite\TestCase; use CakeProducts\Controller\ExternalProductCatalogsController; -use CakeProducts\Model\Table\ExternalProductCatalogsTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ExternalProductCatalogsController Test Case */ #[CoversClass(ExternalProductCatalogsController::class)] -class ExternalProductCatalogsControllerTest extends BaseControllerTest -{ - /** +class ExternalProductCatalogsControllerTest extends BaseControllerTest { + + /** * Test subject table * - * @var ExternalProductCatalogsTable|Table + * @var \CakeProducts\Model\Table\ExternalProductCatalogsTable|\Cake\ORM\Table */ - protected $ExternalProductCatalogs; + protected $ExternalProductCatalogs; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ExternalProductCatalogs', - 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', - 'plugin.CakeProducts.ProductCatalogs', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ExternalProductCatalogs', + 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', + 'plugin.CakeProducts.ProductCatalogs', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $this->disableErrorHandlerMiddleware(); - $this->ExternalProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogs'); - } + $this->disableErrorHandlerMiddleware(); + $this->ExternalProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogs'); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ExternalProductCatalogs); + protected function tearDown(): void { + unset($this->ExternalProductCatalogs); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::index() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testIndexGet(): void - { - Log::debug('inside testIndexGet ExternalProductCatalogsControllerTest'); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGet(): void { + Log::debug('inside testIndexGet ExternalProductCatalogsControllerTest'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::view() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testViewGet(): void - { - $id = '115153f3-2f59-4234-8ff8-e1b205769999'; - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGet(): void { + $id = '115153f3-2f59-4234-8ff8-e1b205769999'; + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ExternalProductCatalogs->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ExternalProductCatalogs->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ExternalProductCatalogs->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ExternalProductCatalogs->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostSuccess(): void - { - $linksTable = TableRegistry::getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs'); - $cntBefore = $this->ExternalProductCatalogs->find()->count(); - $linksBefore = $linksTable->find()->count(); + public function testAddPostSuccess(): void { + $linksTable = TableRegistry::getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs'); + $cntBefore = $this->ExternalProductCatalogs->find()->count(); + $linksBefore = $linksTable->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'add', - ]; - $data = [ - 'base_url' => 'http://localhost:8766', - 'api_url' => 'http://localhost:8766/api/v1/', - 'enabled' => true, - 'external_product_catalogs_product_catalogs' => [ - ['product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428'], - ] - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('external-product-catalogs'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'add', + ]; + $data = [ + 'base_url' => 'http://localhost:8766', + 'api_url' => 'http://localhost:8766/api/v1/', + 'enabled' => true, + 'external_product_catalogs_product_catalogs' => [ + ['product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428'], + ], + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('external-product-catalogs'); - $cntAfter = $this->ExternalProductCatalogs->find()->count(); - $linksAfter = $linksTable->find()->count(); + $cntAfter = $this->ExternalProductCatalogs->find()->count(); + $linksAfter = $linksTable->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - $this->assertEquals($linksBefore + 1, $linksAfter); - } + $this->assertEquals($cntBefore + 1, $cntAfter); + $this->assertEquals($linksBefore + 1, $linksAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostFailure(): void - { - $cntBefore = $this->ExternalProductCatalogs->find()->count(); + public function testAddPostFailure(): void { + $cntBefore = $this->ExternalProductCatalogs->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'add', - ]; - $data = [ - 'product_catalog_id' => 999999, - 'base_url' => '', - 'api_url' => 'http://localhost:8766/api/v1/', - 'enabled' => true, - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'add', + ]; + $data = [ + 'product_catalog_id' => 999999, + 'base_url' => '', + 'api_url' => 'http://localhost:8766/api/v1/', + 'enabled' => true, + ]; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ExternalProductCatalogs->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ExternalProductCatalogs->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'edit', - '115153f3-2f59-4234-8ff8-e1b205769999', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testEditGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'edit', + '115153f3-2f59-4234-8ff8-e1b205769999', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutSuccess(): void - { - $this->loginUserByRole('admin'); - $id = '115153f3-2f59-4234-8ff8-e1b205769999'; - $before = $this->ExternalProductCatalogs->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'edit', - $id, - ]; - $data = [ - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'base_url' => 'http://localhost:8766', - 'api_url' => 'http://localhost:8766/api/v1/', - 'enabled' => true, - ]; - $this->put($url, $data); + public function testEditPutSuccess(): void { + $this->loginUserByRole('admin'); + $id = '115153f3-2f59-4234-8ff8-e1b205769999'; + $before = $this->ExternalProductCatalogs->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'edit', + $id, + ]; + $data = [ + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'base_url' => 'http://localhost:8766', + 'api_url' => 'http://localhost:8766/api/v1/', + 'enabled' => true, + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('external-product-catalogs'); + $this->assertResponseCode(302); + $this->assertRedirectContains('external-product-catalogs'); - $after = $this->ExternalProductCatalogs->get($id); - // assert saved properly below - } + $after = $this->ExternalProductCatalogs->get($id); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutFailure(): void - { - $this->loginUserByRole('admin'); - $id = '115153f3-2f59-4234-8ff8-e1b205769999'; - $before = $this->ExternalProductCatalogs->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'edit', - $id, - ]; - $data = [ - 'product_catalog_id' => 9999999, - 'base_url' => '', - 'api_url' => 'http://localhost:8766/api/v1/', - 'enabled' => true, - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->ExternalProductCatalogs->get($id); + public function testEditPutFailure(): void { + $this->loginUserByRole('admin'); + $id = '115153f3-2f59-4234-8ff8-e1b205769999'; + $before = $this->ExternalProductCatalogs->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'edit', + $id, + ]; + $data = [ + 'product_catalog_id' => 9999999, + 'base_url' => '', + 'api_url' => 'http://localhost:8766/api/v1/', + 'enabled' => true, + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->ExternalProductCatalogs->get($id); - // assert save failed below - } + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsController::delete() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testDelete(): void - { - $cntBefore = $this->ExternalProductCatalogs->find()->count(); + public function testDelete(): void { + $cntBefore = $this->ExternalProductCatalogs->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogs', - 'action' => 'delete', - '115153f3-2f59-4234-8ff8-e1b205769999', - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('external-product-catalogs'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogs', + 'action' => 'delete', + '115153f3-2f59-4234-8ff8-e1b205769999', + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('external-product-catalogs'); + + $cntAfter = $this->ExternalProductCatalogs->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + } - $cntAfter = $this->ExternalProductCatalogs->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - } } diff --git a/tests/TestCase/Controller/ExternalProductCatalogsProductCatalogsControllerTest.php b/tests/TestCase/Controller/ExternalProductCatalogsProductCatalogsControllerTest.php index b5b1160..023e5be 100644 --- a/tests/TestCase/Controller/ExternalProductCatalogsProductCatalogsControllerTest.php +++ b/tests/TestCase/Controller/ExternalProductCatalogsProductCatalogsControllerTest.php @@ -4,118 +4,111 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; use CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController; -use Cake\ORM\Table; -use Cake\TestSuite\IntegrationTestTrait; -use Cake\TestSuite\TestCase; -use CakeProducts\Model\Table\ExternalProductCatalogsProductCatalogsTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController Test Case */ #[CoversClass(ExternalProductCatalogsProductCatalogsController::class)] -class ExternalProductCatalogsProductCatalogsControllerTest extends BaseControllerTest -{ - /** +class ExternalProductCatalogsProductCatalogsControllerTest extends BaseControllerTest { + + /** * Test subject table * - * @var ExternalProductCatalogsProductCatalogsTable|Table + * @var \CakeProducts\Model\Table\ExternalProductCatalogsProductCatalogsTable|\Cake\ORM\Table */ - protected $ExternalProductCatalogsProductCatalogs; - /** + protected $ExternalProductCatalogsProductCatalogs; + + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', - 'plugin.CakeProducts.ExternalProductCatalogs', - 'plugin.CakeProducts.ProductCatalogs', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', + 'plugin.CakeProducts.ExternalProductCatalogs', + 'plugin.CakeProducts.ProductCatalogs', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $this->disableErrorHandlerMiddleware(); - $this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs'); - } + $this->disableErrorHandlerMiddleware(); + $this->ExternalProductCatalogsProductCatalogs = $this->getTableLocator()->get('CakeProducts.ExternalProductCatalogsProductCatalogs'); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ExternalProductCatalogsProductCatalogs); + protected function tearDown(): void { + unset($this->ExternalProductCatalogsProductCatalogs); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test add method * * Tests the add action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count(); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogsProductCatalogs', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogsProductCatalogs', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * * @uses \CakeProducts\Controller\ExternalProductCatalogsProductCatalogsController::delete() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testDelete(): void - { - $cntBeforeWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count(); - $cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count(); + public function testDelete(): void { + $cntBeforeWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count(); + $cntBefore = $this->ExternalProductCatalogsProductCatalogs->find()->count(); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ExternalProductCatalogsProductCatalogs', - 'action' => 'delete', - 1, - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('external-product-catalogs'); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ExternalProductCatalogsProductCatalogs', + 'action' => 'delete', + 1, + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('external-product-catalogs'); + + $cntAfterWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count(); + $cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + $this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed); + } - $cntAfterWithTrashed = $this->ExternalProductCatalogsProductCatalogs->find('withTrashed')->count(); - $cntAfter = $this->ExternalProductCatalogsProductCatalogs->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - $this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed); - } } diff --git a/tests/TestCase/Controller/ProductCatalogsControllerTest.php b/tests/TestCase/Controller/ProductCatalogsControllerTest.php index 5601bc8..d98c46e 100644 --- a/tests/TestCase/Controller/ProductCatalogsControllerTest.php +++ b/tests/TestCase/Controller/ProductCatalogsControllerTest.php @@ -3,325 +3,311 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; -use Cake\ORM\Table; -use Cake\TestSuite\IntegrationTestTrait; -use Cake\TestSuite\TestCase; use CakeProducts\Controller\ProductCatalogsController; use CakeProducts\Model\Table\ProductCatalogsTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ProductCatalogsController Test Case */ #[CoversClass(ProductCatalogsController::class)] -class ProductCatalogsControllerTest extends BaseControllerTest -{ - /** +class ProductCatalogsControllerTest extends BaseControllerTest { + + /** * Test subject table * - * @var ProductCatalogsTable|Table + * @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table */ - protected $ProductCatalogs; + protected $ProductCatalogs; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCatalogs', - 'plugin.CakeProducts.ProductCategories', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCatalogs', + 'plugin.CakeProducts.ProductCategories', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $this->disableErrorHandlerMiddleware(); - $config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class]; - $this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config); - } + $this->disableErrorHandlerMiddleware(); + $config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class]; + $this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCatalogs); + protected function tearDown(): void { + unset($this->ProductCatalogs); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::index() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testIndexGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::view() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testViewGet(): void - { - $id = '115153f3-2f59-4234-8ff8-e1b205761428'; - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGet(): void { + $id = '115153f3-2f59-4234-8ff8-e1b205761428'; + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ProductCatalogs->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ProductCatalogs->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCatalogs->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCatalogs->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostSuccess(): void - { - $cntBefore = $this->ProductCatalogs->find()->count(); + public function testAddPostSuccess(): void { + $cntBefore = $this->ProductCatalogs->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'add', - ]; - $data = [ - 'name' => 'new catalog', - 'catalog_description' => 'description', - 'enabled' => true, - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-catalogs'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'add', + ]; + $data = [ + 'name' => 'new catalog', + 'catalog_description' => 'description', + 'enabled' => true, + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-catalogs'); - $cntAfter = $this->ProductCatalogs->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - } + $cntAfter = $this->ProductCatalogs->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostFailure(): void - { - $cntBefore = $this->ProductCatalogs->find()->count(); + public function testAddPostFailure(): void { + $cntBefore = $this->ProductCatalogs->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'add', - ]; - $data = [ - 'name' => '', - 'catalog_description' => '', - 'enabled' => '', - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'add', + ]; + $data = [ + 'name' => '', + 'catalog_description' => '', + 'enabled' => '', + ]; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCatalogs->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCatalogs->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditGet(): void - { - $this->loginUserByRole('admin'); - $id = '115153f3-2f59-4234-8ff8-e1b205761428'; - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'edit', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testEditGet(): void { + $this->loginUserByRole('admin'); + $id = '115153f3-2f59-4234-8ff8-e1b205761428'; + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'edit', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutSuccess(): void - { - $this->loginUserByRole('admin'); - $id = '115153f3-2f59-4234-8ff8-e1b205761428'; + public function testEditPutSuccess(): void { + $this->loginUserByRole('admin'); + $id = '115153f3-2f59-4234-8ff8-e1b205761428'; // $before = $this->ProductCatalogs->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'edit', - $id, - ]; - $data = [ - // test new data here - 'name' => 'edited name', - 'catalog_description' => 'new catalog description', - 'enabled' => true, - ]; - $this->put($url, $data); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'edit', + $id, + ]; + $data = [ + // test new data here + 'name' => 'edited name', + 'catalog_description' => 'new catalog description', + 'enabled' => true, + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-catalogs'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-catalogs'); - $after = $this->ProductCatalogs->get($id); - $this->assertEquals($data['name'], $after->name); - $this->assertEquals($data['catalog_description'], $after->catalog_description); - // assert saved properly below - } + $after = $this->ProductCatalogs->get($id); + $this->assertEquals($data['name'], $after->name); + $this->assertEquals($data['catalog_description'], $after->catalog_description); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutFailure(): void - { - $this->loginUserByRole('admin'); - $id = '115153f3-2f59-4234-8ff8-e1b205761428'; - $before = $this->ProductCatalogs->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'edit', - $id, - ]; - $data = [ - 'name' => '', - 'catalog_description' => 'edited description', - 'enabled' => '', - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->ProductCatalogs->get($id); - $this->assertEquals($before->name, $after->name); - $this->assertEquals($before->catalog_description, $after->catalog_description); - // assert save failed below - } + public function testEditPutFailure(): void { + $this->loginUserByRole('admin'); + $id = '115153f3-2f59-4234-8ff8-e1b205761428'; + $before = $this->ProductCatalogs->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'edit', + $id, + ]; + $data = [ + 'name' => '', + 'catalog_description' => 'edited description', + 'enabled' => '', + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->ProductCatalogs->get($id); + $this->assertEquals($before->name, $after->name); + $this->assertEquals($before->catalog_description, $after->catalog_description); + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * * @uses \CakeProducts\Controller\ProductCatalogsController::delete() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testDelete(): void - { - $cntBefore = $this->ProductCatalogs->find()->count(); + public function testDelete(): void { + $cntBefore = $this->ProductCatalogs->find()->count(); - $this->loginUserByRole('admin'); - $id = '115153f3-2f59-4234-8ff8-e1b205761428'; - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCatalogs', - 'action' => 'delete', - $id, - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-catalogs'); + $this->loginUserByRole('admin'); + $id = '115153f3-2f59-4234-8ff8-e1b205761428'; + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCatalogs', + 'action' => 'delete', + $id, + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-catalogs'); + + $cntAfter = $this->ProductCatalogs->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + } - $cntAfter = $this->ProductCatalogs->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - } } diff --git a/tests/TestCase/Controller/ProductCategoriesControllerTest.php b/tests/TestCase/Controller/ProductCategoriesControllerTest.php index 9ddf42b..559897b 100644 --- a/tests/TestCase/Controller/ProductCategoriesControllerTest.php +++ b/tests/TestCase/Controller/ProductCategoriesControllerTest.php @@ -3,334 +3,310 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; -use Cake\ORM\Table; -use Cake\TestSuite\IntegrationTestTrait; -use Cake\TestSuite\TestCase; use CakeProducts\Controller\ProductCategoriesController; -use CakeProducts\Model\Table\ProductCategoriesTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ProductCategoriesController Test Case */ #[CoversClass(ProductCategoriesController::class)] -class ProductCategoriesControllerTest extends BaseControllerTest -{ - /** +class ProductCategoriesControllerTest extends BaseControllerTest { + + /** * Test subject table * - * @var ProductCategoriesTable|Table + * @var \CakeProducts\Model\Table\ProductCategoriesTable|\Cake\ORM\Table */ - protected $ProductCategories; + protected $ProductCategories; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCatalogs', - 'plugin.CakeProducts.ProductCategories', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCatalogs', + 'plugin.CakeProducts.ProductCategories', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $this->disableErrorHandlerMiddleware(); - $this->ProductCategories = $this->getTableLocator()->get('CakeProducts.ProductCategories'); - } + $this->disableErrorHandlerMiddleware(); + $this->ProductCategories = $this->getTableLocator()->get('CakeProducts.ProductCategories'); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategories); + protected function tearDown(): void { + unset($this->ProductCategories); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::index + * @throws Exception + * @return void */ - public function testIndexGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::view + * @throws Exception + * @return void */ - public function testViewGet(): void - { - $id = 1; - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGet(): void { + $id = 1; + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::add + * @throws Exception + * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ProductCategories->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ProductCategories->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategories->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategories->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::add + * @throws Exception + * @return void */ - public function testAddPostSuccess(): void - { - $cntBefore = $this->ProductCategories->find()->count(); + public function testAddPostSuccess(): void { + $cntBefore = $this->ProductCategories->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'add', - ]; - $data = [ - 'name' => 'Electrical Plugs', - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'category_description' => 'electrical', - 'parent_id' => 3, - 'enabled' => true, - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-categories'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'add', + ]; + $data = [ + 'name' => 'Electrical Plugs', + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'category_description' => 'electrical', + 'parent_id' => 3, + 'enabled' => true, + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-categories'); - $cntAfter = $this->ProductCategories->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - } + $cntAfter = $this->ProductCategories->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::add + * @throws Exception + * @return void */ - public function testAddPostFailure(): void - { - $cntBefore = $this->ProductCategories->find()->count(); + public function testAddPostFailure(): void { + $cntBefore = $this->ProductCategories->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'add', - ]; - $data = [ - 'name' => '', - 'product_catalog_id' => '', - 'category_description' => 'electrical', - 'parent_id' => '', - 'enabled' => true, - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'add', + ]; + $data = [ + 'name' => '', + 'product_catalog_id' => '', + 'category_description' => 'electrical', + 'parent_id' => '', + 'enabled' => true, + ]; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategories->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategories->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::edit + * @throws Exception + * @return void */ - public function testEditGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'edit', - 1, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testEditGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'edit', + 1, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::edit + * @throws Exception + * @return void */ - public function testEditPutSuccess(): void - { - $this->loginUserByRole('admin'); - $id = 1; - $before = $this->ProductCategories->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'edit', - $id, - ]; - $data = [ - // test new data here - 'name' => 'Electrical v2', - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'category_description' => 'electrical v2', - 'parent_id' => '', - 'enabled' => true, - ]; - $this->put($url, $data); + public function testEditPutSuccess(): void { + $this->loginUserByRole('admin'); + $id = 1; + $before = $this->ProductCategories->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'edit', + $id, + ]; + $data = [ + // test new data here + 'name' => 'Electrical v2', + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'category_description' => 'electrical v2', + 'parent_id' => '', + 'enabled' => true, + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-categories'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-categories'); - $after = $this->ProductCategories->get($id); - $this->assertEquals($data['name'], $after->name); - $this->assertEquals($data['product_catalog_id'], $after->product_catalog_id); - $this->assertEquals($data['category_description'], $after->category_description); - $this->assertNull($after->parent_id); - // assert saved properly below - } + $after = $this->ProductCategories->get($id); + $this->assertEquals($data['name'], $after->name); + $this->assertEquals($data['product_catalog_id'], $after->product_catalog_id); + $this->assertEquals($data['category_description'], $after->category_description); + $this->assertNull($after->parent_id); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::edit + * @throws Exception + * @return void */ - public function testEditPutFailure(): void - { - $this->loginUserByRole('admin'); - $id = 1; - $before = $this->ProductCategories->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'edit', - $id, - ]; - $data = [ - 'name' => '', - 'product_catalog_id' => '', - 'category_description' => 'electrical', - 'parent_id' => '', - 'enabled' => true, - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->ProductCategories->get($id); + public function testEditPutFailure(): void { + $this->loginUserByRole('admin'); + $id = 1; + $before = $this->ProductCategories->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'edit', + $id, + ]; + $data = [ + 'name' => '', + 'product_catalog_id' => '', + 'category_description' => 'electrical', + 'parent_id' => '', + 'enabled' => true, + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->ProductCategories->get($id); - // assert save failed below - } + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * - * @return void - *@throws Exception - * * @uses \CakeProducts\Controller\ProductCategoriesController::delete + *@throws Exception + * @return void */ - public function testDelete(): void - { - $cntBefore = $this->ProductCategories->find()->count(); - $cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategories', - 'action' => 'delete', - 1, - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-categories'); + public function testDelete(): void { + $cntBefore = $this->ProductCategories->find()->count(); + $cntBeforeWithTrashed = $this->ProductCategories->find('withTrashed')->count(); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategories', + 'action' => 'delete', + 1, + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-categories'); - $cntAfter = $this->ProductCategories->find()->count(); - $cntAfterWithTrashed = $this->ProductCategories->find('withTrashed')->count(); + $cntAfter = $this->ProductCategories->find()->count(); + $cntAfterWithTrashed = $this->ProductCategories->find('withTrashed')->count(); + + $this->assertEquals($cntBefore - 2, $cntAfter); // has 1 child category + $this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed); + } - $this->assertEquals($cntBefore - 2, $cntAfter); // has 1 child category - $this->assertEquals($cntBeforeWithTrashed, $cntAfterWithTrashed); - } } diff --git a/tests/TestCase/Controller/ProductCategoryAttributeOptionsControllerTest.php b/tests/TestCase/Controller/ProductCategoryAttributeOptionsControllerTest.php index 1f3c35b..cc24b77 100644 --- a/tests/TestCase/Controller/ProductCategoryAttributeOptionsControllerTest.php +++ b/tests/TestCase/Controller/ProductCategoryAttributeOptionsControllerTest.php @@ -3,142 +3,133 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; -use Cake\ORM\Table; use CakeProducts\Controller\ProductCategoryAttributeOptionsController; use CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ProductCategoryAttributeOptionsController Test Case */ #[CoversClass(ProductCategoryAttributeOptionsController::class)] -class ProductCategoryAttributeOptionsControllerTest extends BaseControllerTest -{ - /** +class ProductCategoryAttributeOptionsControllerTest extends BaseControllerTest { + + /** * Test subject * - * @var ProductCategoryAttributeOptionsTable|Table + * @var \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable|\Cake\ORM\Table */ - protected $ProductCategoryAttributeOptions; + protected $ProductCategoryAttributeOptions; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCategoryAttributeOptions', - 'plugin.CakeProducts.ProductCategoryAttributes', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCategoryAttributeOptions', + 'plugin.CakeProducts.ProductCategoryAttributes', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class]; - $this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config); - } + $config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class]; + $this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategoryAttributeOptions); + protected function tearDown(): void { + unset($this->ProductCategoryAttributeOptions); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test add method * * Tests the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add + * @throws Exception + * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ProductCategoryAttributeOptions->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ProductCategoryAttributeOptions->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributeOptions', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributeOptions', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::add + * @throws Exception + * @return void */ - public function testAddPostHasNoEffect(): void - { - $cntBefore = $this->ProductCategoryAttributeOptions->find()->count(); + public function testAddPostHasNoEffect(): void { + $cntBefore = $this->ProductCategoryAttributeOptions->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributeOptions', - 'action' => 'add', - ]; - $data = []; - $this->post($url, $data); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributeOptions', + 'action' => 'add', + ]; + $data = []; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * - * @return void - *@throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributeOptionsController::delete + *@throws Exception + * @return void */ - public function testDelete(): void - { - $cntBefore = $this->ProductCategoryAttributeOptions->find()->count(); + public function testDelete(): void { + $cntBefore = $this->ProductCategoryAttributeOptions->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributeOptions', - 'action' => 'delete', - 'e06f1723-2456-483a-b3c4-004603e032a8', - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-attributes'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributeOptions', + 'action' => 'delete', + 'e06f1723-2456-483a-b3c4-004603e032a8', + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-attributes'); + + $cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + } - $cntAfter = $this->ProductCategoryAttributeOptions->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - } } diff --git a/tests/TestCase/Controller/ProductCategoryAttributesControllerTest.php b/tests/TestCase/Controller/ProductCategoryAttributesControllerTest.php index a3084e1..ae6d7b9 100644 --- a/tests/TestCase/Controller/ProductCategoryAttributesControllerTest.php +++ b/tests/TestCase/Controller/ProductCategoryAttributesControllerTest.php @@ -3,373 +3,348 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; -use Cake\ORM\Table; -use Cake\TestSuite\IntegrationTestTrait; -use Cake\TestSuite\TestCase; use CakeProducts\Controller\ProductCategoryAttributesController; use CakeProducts\Model\Table\ProductCategoryAttributesTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ProductCategoryAttributesController Test Case */ #[CoversClass(ProductCategoryAttributesController::class)] -class ProductCategoryAttributesControllerTest extends BaseControllerTest -{ - /** +class ProductCategoryAttributesControllerTest extends BaseControllerTest { + + /** * Test subject * - * @var ProductCategoryAttributesTable|Table + * @var \CakeProducts\Model\Table\ProductCategoryAttributesTable|\Cake\ORM\Table */ - protected $ProductCategoryAttributes; + protected $ProductCategoryAttributes; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCategoryAttributes', - 'plugin.CakeProducts.ProductCategories', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCategoryAttributes', + 'plugin.CakeProducts.ProductCategories', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class]; - $this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config); - } + $config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class]; + $this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategoryAttributes); + protected function tearDown(): void { + unset($this->ProductCategoryAttributes); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::index + * @throws Exception + * @return void */ - public function testIndexGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::view + * @throws Exception + * @return void */ - public function testViewGet(): void - { - $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGet(): void { + $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add + * @throws Exception + * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ProductCategoryAttributes->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ProductCategoryAttributes->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategoryAttributes->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategoryAttributes->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add + * @throws Exception + * @return void */ - public function testAddPostSuccess(): void - { - $cntBefore = $this->ProductCategoryAttributes->find()->count(); + public function testAddPostSuccess(): void { + $cntBefore = $this->ProductCategoryAttributes->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'add', - ]; - $data = [ - 'name' => 'Size', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'attribute_type_id' => 2, - 'enabled' => true, - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-attributes'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'add', + ]; + $data = [ + 'name' => 'Size', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'attribute_type_id' => 2, + 'enabled' => true, + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-attributes'); - $cntAfter = $this->ProductCategoryAttributes->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - } + $cntAfter = $this->ProductCategoryAttributes->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add + * @throws Exception + * @return void */ - public function testAddPostSuccessConstrainedWithOptions(): void - { - $cntBefore = $this->ProductCategoryAttributes->find()->count(); - $cntOptionsBefore = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count(); + public function testAddPostSuccessConstrainedWithOptions(): void { + $cntBefore = $this->ProductCategoryAttributes->find()->count(); + $cntOptionsBefore = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'add', - ]; - $data = [ - 'name' => 'Size', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'attribute_type_id' => 1, - 'enabled' => true, - 'product_category_attribute_options' => [ - [ - 'attribute_value' => 'XL', - 'attribute_label' => 'XL', - 'enabled' => true, - ], - [ - 'attribute_value' => 'L', - 'attribute_label' => 'L', - 'enabled' => true, - ] - ], - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-attributes'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'add', + ]; + $data = [ + 'name' => 'Size', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'attribute_type_id' => 1, + 'enabled' => true, + 'product_category_attribute_options' => [ + [ + 'attribute_value' => 'XL', + 'attribute_label' => 'XL', + 'enabled' => true, + ], + [ + 'attribute_value' => 'L', + 'attribute_label' => 'L', + 'enabled' => true, + ], + ], + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-attributes'); - $cntAfter = $this->ProductCategoryAttributes->find()->count(); - $cntOptionsAfter = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count(); + $cntAfter = $this->ProductCategoryAttributes->find()->count(); + $cntOptionsAfter = $this->ProductCategoryAttributes->ProductCategoryAttributeOptions->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - $this->assertEquals($cntOptionsBefore + 2, $cntOptionsAfter); - } + $this->assertEquals($cntBefore + 1, $cntAfter); + $this->assertEquals($cntOptionsBefore + 2, $cntOptionsAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::add + * @throws Exception + * @return void */ - public function testAddPostFailure(): void - { - $cntBefore = $this->ProductCategoryAttributes->find()->count(); + public function testAddPostFailure(): void { + $cntBefore = $this->ProductCategoryAttributes->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'add', - ]; - $data = [ - 'name' => '', - 'product_category_id' => 1, - 'attribute_type_id' => 1, - 'enabled' => true, - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'add', + ]; + $data = [ + 'name' => '', + 'product_category_id' => 1, + 'attribute_type_id' => 1, + 'enabled' => true, + ]; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategoryAttributes->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategoryAttributes->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit + * @throws Exception + * @return void */ - public function testEditGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'edit', - '37078cf0-0130-4b93-bb7e-abe7d665ed2c', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testEditGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'edit', + '37078cf0-0130-4b93-bb7e-abe7d665ed2c', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit + * @throws Exception + * @return void */ - public function testEditPutSuccess(): void - { - $this->loginUserByRole('admin'); - $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; - $before = $this->ProductCategoryAttributes->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'edit', - $id, - ]; - $data = [ - // test new data here - 'name' => 'Color', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'attribute_type_id' => 1, - 'enabled' => true, - ]; - $this->put($url, $data); + public function testEditPutSuccess(): void { + $this->loginUserByRole('admin'); + $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; + $before = $this->ProductCategoryAttributes->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'edit', + $id, + ]; + $data = [ + // test new data here + 'name' => 'Color', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'attribute_type_id' => 1, + 'enabled' => true, + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-attributes'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-attributes'); - $after = $this->ProductCategoryAttributes->get($id); - // assert saved properly below - } + $after = $this->ProductCategoryAttributes->get($id); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::edit + * @throws Exception + * @return void */ - public function testEditPutFailure(): void - { - $this->loginUserByRole('admin'); - $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; - $before = $this->ProductCategoryAttributes->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'edit', - $id, - ]; - $data = [ - 'name' => '', - 'product_category_id' => 1, - 'attribute_type_id' => 1, - 'enabled' => true, - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->ProductCategoryAttributes->get($id); + public function testEditPutFailure(): void { + $this->loginUserByRole('admin'); + $id = '37078cf0-0130-4b93-bb7e-abe7d665ed2c'; + $before = $this->ProductCategoryAttributes->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'edit', + $id, + ]; + $data = [ + 'name' => '', + 'product_category_id' => 1, + 'attribute_type_id' => 1, + 'enabled' => true, + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->ProductCategoryAttributes->get($id); - // assert save failed below - } + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * - * @return void - *@throws Exception - * * @uses \CakeProducts\Controller\ProductCategoryAttributesController::delete + *@throws Exception + * @return void */ - public function testDelete(): void - { - $cntBefore = $this->ProductCategoryAttributes->find()->count(); + public function testDelete(): void { + $cntBefore = $this->ProductCategoryAttributes->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryAttributes', - 'action' => 'delete', - '37078cf0-0130-4b93-bb7e-abe7d665ed2c', - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-attributes'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryAttributes', + 'action' => 'delete', + '37078cf0-0130-4b93-bb7e-abe7d665ed2c', + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-attributes'); + + $cntAfter = $this->ProductCategoryAttributes->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + } - $cntAfter = $this->ProductCategoryAttributes->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - } } diff --git a/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php b/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php index cafd242..06f0676 100644 --- a/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php +++ b/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php @@ -3,425 +3,412 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; -use Cake\ORM\Table; use CakeProducts\Controller\ProductCategoryVariantsController; -use CakeProducts\Model\Table\ProductCategoryAttributesTable; use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable; use CakeProducts\Model\Table\ProductCategoryVariantsTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ProductCategoryVariantsController Test Case */ #[CoversClass(ProductCategoryVariantsController::class)] -class ProductCategoryVariantsControllerTest extends BaseControllerTest -{ - /** - * Test subject - * - * @var ProductCategoryVariantsTable|Table - */ - protected $ProductCategoryVariants; +class ProductCategoryVariantsControllerTest extends BaseControllerTest { - /** + /** * Test subject * - * @var ProductCategoryVariantOptionsTable|Table + * @var \CakeProducts\Model\Table\ProductCategoryVariantsTable|\Cake\ORM\Table */ - protected $ProductCategoryVariantOptions; - /** + protected $ProductCategoryVariants; + + /** + * Test subject + * + * @var \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable|\Cake\ORM\Table + */ + protected $ProductCategoryVariantOptions; + + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCategoryVariants', - 'plugin.CakeProducts.ProductCategoryVariantOptions', - 'plugin.CakeProducts.ProductVariants', - 'plugin.CakeProducts.ProductCategories', - 'plugin.CakeProducts.Products', - 'plugin.CakeProducts.ProductSkus', - 'plugin.CakeProducts.ProductPhotos', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCategoryVariants', + 'plugin.CakeProducts.ProductCategoryVariantOptions', + 'plugin.CakeProducts.ProductVariants', + 'plugin.CakeProducts.ProductCategories', + 'plugin.CakeProducts.Products', + 'plugin.CakeProducts.ProductSkus', + 'plugin.CakeProducts.ProductPhotos', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $this->disableErrorHandlerMiddleware(); + protected function setUp(): void { + parent::setUp(); + $this->disableErrorHandlerMiddleware(); - $config = $this->getTableLocator()->exists('ProductCategoryVariants') ? [] : ['className' => ProductCategoryVariantsTable::class]; - $this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants', $config); + $config = $this->getTableLocator()->exists('ProductCategoryVariants') ? [] : ['className' => ProductCategoryVariantsTable::class]; + $this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants', $config); - $config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class]; - $this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config); - } + $config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class]; + $this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategoryVariants); - unset($this->ProductCategoryVariantOptions); + protected function tearDown(): void { + unset($this->ProductCategoryVariants); + unset($this->ProductCategoryVariantOptions); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::index() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testIndexGet(): void - { - //$this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGet(): void { + //$this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::view() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testViewGet(): void - { - $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; - //$this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGet(): void { + $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; + //$this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ProductCategoryVariants->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ProductCategoryVariants->find()->count(); - //$this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + //$this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategoryVariants->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategoryVariants->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostLoggedInSuccess(): void - { - $cntBefore = $this->ProductCategoryVariants->find()->count(); - $cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count(); + public function testAddPostLoggedInSuccess(): void { + $cntBefore = $this->ProductCategoryVariants->find()->count(); + $cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count(); - //$this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'add', - ]; - $data = [ - 'name' => 'Size', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'product_id' => '', - 'enabled' => true, - 'product_category_variant_options' => [ - [ - 'variant_value' => 'XL', - 'variant_label' => 'XL', - 'enabled' => true, - ], - [ - 'variant_value' => 'XXL', - 'variant_label' => 'XXL', - 'enabled' => true, - ], - ] - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-variants'); + //$this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'add', + ]; + $data = [ + 'name' => 'Size', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'product_id' => '', + 'enabled' => true, + 'product_category_variant_options' => [ + [ + 'variant_value' => 'XL', + 'variant_label' => 'XL', + 'enabled' => true, + ], + [ + 'variant_value' => 'XXL', + 'variant_label' => 'XXL', + 'enabled' => true, + ], + ], + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-variants'); - $cntAfter = $this->ProductCategoryVariants->find()->count(); - $cntAfterOptions = $this->ProductCategoryVariantOptions->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - $this->assertEquals($cntBeforeOptions + 2, $cntAfterOptions); - } + $cntAfter = $this->ProductCategoryVariants->find()->count(); + $cntAfterOptions = $this->ProductCategoryVariantOptions->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); + $this->assertEquals($cntBeforeOptions + 2, $cntAfterOptions); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostLoggedInFailure(): void - { - $cntBefore = $this->ProductCategoryVariants->find()->count(); + public function testAddPostLoggedInFailure(): void { + $cntBefore = $this->ProductCategoryVariants->find()->count(); - //$this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'add', - ]; - $data = [ - 'name' => '', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'enabled' => true, - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + //$this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'add', + ]; + $data = [ + 'name' => '', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'enabled' => true, + ]; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ProductCategoryVariants->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductCategoryVariants->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditGet(): void - { - //$this->loginUserByRole('admin'); - $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; + public function testEditGet(): void { + //$this->loginUserByRole('admin'); + $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'edit', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'edit', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutLoggedInSuccess(): void - { - //$this->loginUserByRole('admin'); - $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; - $before = $this->ProductCategoryVariants->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'edit', - $id, - ]; - $data = [ - // test new data here - 'name' => 'updated name', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'enabled' => true, - ]; - $this->put($url, $data); + public function testEditPutLoggedInSuccess(): void { + //$this->loginUserByRole('admin'); + $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; + $before = $this->ProductCategoryVariants->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'edit', + $id, + ]; + $data = [ + // test new data here + 'name' => 'updated name', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'enabled' => true, + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-variants'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-variants'); - $after = $this->ProductCategoryVariants->get($id); - // assert saved properly below - } + $after = $this->ProductCategoryVariants->get($id); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutLoggedInSuccessSystemVariant(): void - { - //$this->loginUserByRole('admin'); - $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78222'; // subscription length - $before = $this->ProductCategoryVariants->get($id); - $cntBeforeOptions = $this->ProductCategoryVariantOptions - ->find() - ->where(['product_category_variant_id' => $id]) - ->toArray(); + public function testEditPutLoggedInSuccessSystemVariant(): void { + //$this->loginUserByRole('admin'); + $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78222'; // subscription length + $before = $this->ProductCategoryVariants->get($id); + $cntBeforeOptions = $this->ProductCategoryVariantOptions + ->find() + ->where(['product_category_variant_id' => $id]) + ->toArray(); // $this->assertEquals(2, count($cntBeforeOptions)); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'edit', - $id, - ]; - $data = [ - // test new data here - 'name' => 'updated name', - 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', - 'enabled' => false, - 'product_category_variant_options' => [ - [ - 'variant_value' => '14', - 'variant_label' => '14', - 'enabled' => true, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221', - 'variant_value' => '6', - 'variant_label' => '6', - 'enabled' => true, - ], - [ - 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222', - 'variant_value' => 12, - 'variant_label' => 12, - 'enabled' => true, - ], - ], - ]; - $this->put($url, $data); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'edit', + $id, + ]; + $data = [ + // test new data here + 'name' => 'updated name', + 'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e', + 'enabled' => false, + 'product_category_variant_options' => [ + [ + 'variant_value' => '14', + 'variant_label' => '14', + 'enabled' => true, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22221', + 'variant_value' => '6', + 'variant_label' => '6', + 'enabled' => true, + ], + [ + 'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f22222', + 'variant_value' => 12, + 'variant_label' => 12, + 'enabled' => true, + ], + ], + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-variants'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-variants'); - $after = $this->ProductCategoryVariants->get($id); - $cntAfterOptions = $this->ProductCategoryVariantOptions - ->find() - ->where(['product_category_variant_id' => $id]) - ->toArray(); + $after = $this->ProductCategoryVariants->get($id); + $cntAfterOptions = $this->ProductCategoryVariantOptions + ->find() + ->where(['product_category_variant_id' => $id]) + ->toArray(); - $this->assertEquals(count($cntBeforeOptions) + 1, count($cntAfterOptions)); + $this->assertEquals(count($cntBeforeOptions) + 1, count($cntAfterOptions)); - $this->assertEquals($before->name, $after->name); - $this->assertNull($after->product_category_id); - $this->assertTrue($after->enabled); - // assert saved properly below - } + $this->assertEquals($before->name, $after->name); + $this->assertNull($after->product_category_id); + $this->assertTrue($after->enabled); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutLoggedInFailure(): void - { - //$this->loginUserByRole('admin'); - $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; - $before = $this->ProductCategoryVariants->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'edit', - $id, - ]; - $data = [ - 'name' => '', - 'product_category_id' => 'NOT A VALID ID', - 'enabled' => true, - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->ProductCategoryVariants->get($id); + public function testEditPutLoggedInFailure(): void { + //$this->loginUserByRole('admin'); + $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; + $before = $this->ProductCategoryVariants->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'edit', + $id, + ]; + $data = [ + 'name' => '', + 'product_category_id' => 'NOT A VALID ID', + 'enabled' => true, + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->ProductCategoryVariants->get($id); - // assert save failed below - } + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * * @uses \CakeProducts\Controller\ProductCategoryVariantsController::delete() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testDelete(): void - { - $cntBefore = $this->ProductCategoryVariants->find()->count(); + public function testDelete(): void { + $cntBefore = $this->ProductCategoryVariants->find()->count(); - //$this->loginUserByRole('admin'); - $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; + //$this->loginUserByRole('admin'); + $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductCategoryVariants', - 'action' => 'delete', - $id, - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-category-variants'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductCategoryVariants', + 'action' => 'delete', + $id, + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-category-variants'); + + $cntAfter = $this->ProductCategoryVariants->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + } - $cntAfter = $this->ProductCategoryVariants->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - } } diff --git a/tests/TestCase/Controller/ProductPhotosControllerTest.php b/tests/TestCase/Controller/ProductPhotosControllerTest.php index 246b3ea..414fe39 100644 --- a/tests/TestCase/Controller/ProductPhotosControllerTest.php +++ b/tests/TestCase/Controller/ProductPhotosControllerTest.php @@ -4,653 +4,614 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; use Cake\Core\Configure; -use Cake\ORM\Table; use CakeProducts\Controller\ProductPhotosController; use CakeProducts\Model\Table\ProductPhotosTable; -use CakeProducts\Model\Table\ProductsTable; -use FilesystemIterator; use Laminas\Diactoros\UploadedFile; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; -use RecursiveDirectoryIterator; -use RecursiveIteratorIterator; use const UPLOAD_ERR_OK; /** * CakeProducts\Controller\ProductPhotosController Test Case */ #[CoversClass(ProductPhotosController::class)] -class ProductPhotosControllerTest extends BaseControllerTest -{ - /** +class ProductPhotosControllerTest extends BaseControllerTest { + + /** * Test subject table * - * @var ProductPhotosTable|Table + * @var \CakeProducts\Model\Table\ProductPhotosTable|\Cake\ORM\Table */ - protected $ProductPhotos; + protected $ProductPhotos; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.Products', - 'plugin.CakeProducts.ProductSkus', - 'plugin.CakeProducts.ProductPhotos', - 'plugin.CakeProducts.ProductCategories', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.Products', + 'plugin.CakeProducts.ProductSkus', + 'plugin.CakeProducts.ProductPhotos', + 'plugin.CakeProducts.ProductCategories', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ProductPhotos') ? [] : ['className' => ProductPhotosTable::class]; - $this->ProductPhotos = $this->getTableLocator()->get('ProductPhotos', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ProductPhotos') ? [] : ['className' => ProductPhotosTable::class]; + $this->ProductPhotos = $this->getTableLocator()->get('ProductPhotos', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductPhotos); + protected function tearDown(): void { + unset($this->ProductPhotos); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::index + * @throws Exception + * @return void */ - public function testIndexGetLoggedIn(): void - { - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGetLoggedIn(): void { + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::view + * @throws Exception + * @return void */ - public function testViewGetLoggedIn(): void - { - $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGetLoggedIn(): void { + $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::add + * @throws Exception + * @return void */ - public function testAddGetLoggedIn(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); + public function testAddGetLoggedIn(): void { + $cntBefore = $this->ProductPhotos->find()->count(); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::add + * @throws Exception + * @return void */ - public function testAddPostLoggedInSuccessDefaultPhoto(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); + public function testAddPostLoggedInSuccessDefaultPhoto(): void { + $cntBefore = $this->ProductPhotos->find()->count(); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'add', - ]; - $file = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon.png'; - $toUseFile = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon_copy.png'; - if (!file_exists($file)) { - $this->fail('Test image did not exist'); - } - if (!copy($file, $toUseFile)) { - $this->fail('Failed to copy test image'); - } - $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; - $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $primaryPhotosCountBefore = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->count(); - $primaryPhotoBefore = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->first(); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'add', + ]; + $file = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon.png'; + $toUseFile = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon_copy.png'; + if (!file_exists($file)) { + $this->fail('Test image did not exist'); + } + if (!copy($file, $toUseFile)) { + $this->fail('Failed to copy test image'); + } + $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; + $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $primaryPhotosCountBefore = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->count(); + $primaryPhotoBefore = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->first(); - $this->assertEquals(1, $primaryPhotosCountBefore); + $this->assertEquals(1, $primaryPhotosCountBefore); - $image = new UploadedFile( - $toUseFile, // stream or path to file representing the temp file - 12345, // the filesize in bytes - UPLOAD_ERR_OK, // the upload/error status - 'cake_icon.png', // the filename as sent by the client - 'image/png' // the mimetype as sent by the client - ); - $this->configRequest([ - 'files' => [ - 'photo' => $image, - ], - ]); - $data = [ - 'product_id' => $productId, - 'product_category_id' => $categoryId, - 'primary_photo' => 1, - 'primary_category_photo' => 0, - 'primary_sku_photo' => 0, - 'photo' => $image, - 'enabled' => 1, - ]; - $this->post($url, $data); + $image = new UploadedFile( + $toUseFile, // stream or path to file representing the temp file + 12345, // the filesize in bytes + UPLOAD_ERR_OK, // the upload/error status + 'cake_icon.png', // the filename as sent by the client + 'image/png', // the mimetype as sent by the client + ); + $this->configRequest([ + 'files' => [ + 'photo' => $image, + ], + ]); + $data = [ + 'product_id' => $productId, + 'product_category_id' => $categoryId, + 'primary_photo' => 1, + 'primary_category_photo' => 0, + 'primary_sku_photo' => 0, + 'photo' => $image, + 'enabled' => 1, + ]; + $this->post($url, $data); // dd($this->_response); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-photos'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-photos'); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); - $new = $this->ProductPhotos->find()->where(['product_id' => $productId])->orderBy(['created' => 'DESC'])->first(); + $new = $this->ProductPhotos->find()->where(['product_id' => $productId])->orderBy(['created' => 'DESC'])->first(); - $this->assertTrue($new->primary_photo); - $this->assertFalse($new->primary_category_photo); - $this->assertFalse($new->primary_sku_photo); + $this->assertTrue($new->primary_photo); + $this->assertFalse($new->primary_category_photo); + $this->assertFalse($new->primary_sku_photo); - $this->assertEquals($productId, $new->product_id); - $primaryPhotosCountAfter = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->count(); - $primaryPhotoAfter = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->first(); + $this->assertEquals($productId, $new->product_id); + $primaryPhotosCountAfter = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->count(); + $primaryPhotoAfter = $this->ProductPhotos->find()->where(['product_id' => $productId, 'primary_photo' => true])->first(); - $this->assertEquals(1, $primaryPhotosCountAfter); - $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); - $this->assertEquals($new->id, $primaryPhotoAfter->id); - } + $this->assertEquals(1, $primaryPhotosCountAfter); + $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); + $this->assertEquals($new->id, $primaryPhotoAfter->id); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::add + * @throws Exception + * @return void */ - public function testAddPostLoggedInSuccessDefaultCategoryPhoto(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); + public function testAddPostLoggedInSuccessDefaultCategoryPhoto(): void { + $cntBefore = $this->ProductPhotos->find()->count(); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'add', - ]; - $file = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon.png'; - $toUseFile = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon_copy.png'; - if (!file_exists($file)) { - $this->fail('Test image did not exist'); - } - if (!copy($file, $toUseFile)) { - $this->fail('Failed to copy test image'); - } - $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; - $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'add', + ]; + $file = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon.png'; + $toUseFile = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon_copy.png'; + if (!file_exists($file)) { + $this->fail('Test image did not exist'); + } + if (!copy($file, $toUseFile)) { + $this->fail('Failed to copy test image'); + } + $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; + $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $primaryCategoryPhotosCountBefore = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->count(); - $primaryCategoryPhotoBefore = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->first(); + $primaryCategoryPhotosCountBefore = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->count(); + $primaryCategoryPhotoBefore = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->first(); - $this->assertEquals(1, $primaryCategoryPhotosCountBefore); + $this->assertEquals(1, $primaryCategoryPhotosCountBefore); - - $image = new UploadedFile( - $toUseFile, // stream or path to file representing the temp file - 12345, // the filesize in bytes - UPLOAD_ERR_OK, // the upload/error status - 'cake_icon.png', // the filename as sent by the client - 'image/png' // the mimetype as sent by the client - ); - $this->configRequest([ - 'files' => [ - 'photo' => $image, - ], - ]); - $data = [ - 'product_id' => '', - 'product_category_id' => $categoryId, - 'product_sku_id' => '', - 'primary_photo' => 0, - 'primary_category_photo' => 1, - 'primary_sku_photo' => 0, - 'photo' => $image, - 'enabled' => 1, - ]; - $this->post($url, $data); + $image = new UploadedFile( + $toUseFile, // stream or path to file representing the temp file + 12345, // the filesize in bytes + UPLOAD_ERR_OK, // the upload/error status + 'cake_icon.png', // the filename as sent by the client + 'image/png', // the mimetype as sent by the client + ); + $this->configRequest([ + 'files' => [ + 'photo' => $image, + ], + ]); + $data = [ + 'product_id' => '', + 'product_category_id' => $categoryId, + 'product_sku_id' => '', + 'primary_photo' => 0, + 'primary_category_photo' => 1, + 'primary_sku_photo' => 0, + 'photo' => $image, + 'enabled' => 1, + ]; + $this->post($url, $data); // dd($this->_response); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-photos'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-photos'); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); - $new = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId])->orderBy(['created' => 'DESC'])->first(); + $new = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId])->orderBy(['created' => 'DESC'])->first(); - $this->assertFalse($new->primary_photo); - $this->assertTrue($new->primary_category_photo); - $this->assertEquals($categoryId, $new->product_category_id); + $this->assertFalse($new->primary_photo); + $this->assertTrue($new->primary_category_photo); + $this->assertEquals($categoryId, $new->product_category_id); - $primaryCategoryPhotosCountAfter = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->count(); - $primaryCategoryPhotoAfter = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->first(); + $primaryCategoryPhotosCountAfter = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->count(); + $primaryCategoryPhotoAfter = $this->ProductPhotos->find()->where(['product_category_id' => $categoryId, 'primary_category_photo' => true])->first(); - $this->assertEquals(1, $primaryCategoryPhotosCountAfter); - $this->assertNotEquals($primaryCategoryPhotoBefore->id, $primaryCategoryPhotoAfter->id); + $this->assertEquals(1, $primaryCategoryPhotosCountAfter); + $this->assertNotEquals($primaryCategoryPhotoBefore->id, $primaryCategoryPhotoAfter->id); - } + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * - * @TODO handle toggle behavior when scope field is nullable - * + * @todo handle toggle behavior when scope field is nullable * @uses \CakeProducts\Controller\ProductPhotosController::add + * @throws \PHPUnit\Exception + * @return void */ - public function testAddPostLoggedInSuccessDefaultSkuPhoto(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); + public function testAddPostLoggedInSuccessDefaultSkuPhoto(): void { + $cntBefore = $this->ProductPhotos->find()->count(); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'add', - ]; - $file = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon.png'; - $toUseFile = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon_copy.png'; - if (!file_exists($file)) { - $this->fail('Test image did not exist'); - } - if (!copy($file, $toUseFile)) { - $this->fail('Failed to copy test image'); - } - $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $skuId = '3a477e3e-7977-4813-81f6-f85949613979'; - $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; - $primarySkuPhotosCountBefore = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->count(); - $primarySkuPhotoBefore = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->first(); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'add', + ]; + $file = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon.png'; + $toUseFile = Configure::readOrFail('App.paths.testWebroot') . 'images' . DS . 'cake_icon_copy.png'; + if (!file_exists($file)) { + $this->fail('Test image did not exist'); + } + if (!copy($file, $toUseFile)) { + $this->fail('Failed to copy test image'); + } + $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $skuId = '3a477e3e-7977-4813-81f6-f85949613979'; + $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; + $primarySkuPhotosCountBefore = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->count(); + $primarySkuPhotoBefore = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->first(); - $this->assertEquals(1, $primarySkuPhotosCountBefore); + $this->assertEquals(1, $primarySkuPhotosCountBefore); - - $image = new UploadedFile( - $toUseFile, // stream or path to file representing the temp file - 12345, // the filesize in bytes - UPLOAD_ERR_OK, // the upload/error status - 'cake_icon.png', // the filename as sent by the client - 'image/png' // the mimetype as sent by the client - ); - $this->configRequest([ - 'files' => [ - 'photo' => $image, - ], - ]); - $data = [ - 'product_id' => $productId, - 'product_sku_id' => $skuId, - 'product_category_id' => $categoryId, - 'primary_photo' => 0, - 'primary_category_photo' => 0, - 'primary_sku_photo' => 1, - 'photo' => $image, - 'enabled' => 1, - ]; - $this->post($url, $data); + $image = new UploadedFile( + $toUseFile, // stream or path to file representing the temp file + 12345, // the filesize in bytes + UPLOAD_ERR_OK, // the upload/error status + 'cake_icon.png', // the filename as sent by the client + 'image/png', // the mimetype as sent by the client + ); + $this->configRequest([ + 'files' => [ + 'photo' => $image, + ], + ]); + $data = [ + 'product_id' => $productId, + 'product_sku_id' => $skuId, + 'product_category_id' => $categoryId, + 'primary_photo' => 0, + 'primary_category_photo' => 0, + 'primary_sku_photo' => 1, + 'photo' => $image, + 'enabled' => 1, + ]; + $this->post($url, $data); // dd($this->_response); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-photos'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-photos'); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); - $new = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId])->orderBy(['created' => 'DESC'])->first(); + $new = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId])->orderBy(['created' => 'DESC'])->first(); - $this->assertFalse($new->primary_photo); - $this->assertFalse($new->primary_category_photo); - $this->assertTrue($new->primary_sku_photo); + $this->assertFalse($new->primary_photo); + $this->assertFalse($new->primary_category_photo); + $this->assertTrue($new->primary_sku_photo); - $primarySkuPhotosCountAfter = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->count(); - $primarySkuPhotoAfter = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->first(); + $primarySkuPhotosCountAfter = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->count(); + $primarySkuPhotoAfter = $this->ProductPhotos->find()->where(['product_sku_id' => $skuId, 'primary_sku_photo' => true])->first(); - $this->assertEquals(1, $primarySkuPhotosCountAfter); - $this->assertNotEquals($primarySkuPhotoBefore->id, $primarySkuPhotoAfter->id); - $this->assertEquals($new->id, $primarySkuPhotoAfter->id); + $this->assertEquals(1, $primarySkuPhotosCountAfter); + $this->assertNotEquals($primarySkuPhotoBefore->id, $primarySkuPhotoAfter->id); + $this->assertEquals($new->id, $primarySkuPhotoAfter->id); - } + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::add + * @throws Exception + * @return void */ - public function testAddPostLoggedInFailure(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); + public function testAddPostLoggedInFailure(): void { + $cntBefore = $this->ProductPhotos->find()->count(); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'add', - ]; - $data = [ - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'add', + ]; + $data = []; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::edit + * @throws Exception + * @return void */ - public function testEditGetLoggedIn(): void - { - // $this->loginUserByRole('admin'); - $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; + public function testEditGetLoggedIn(): void { + // $this->loginUserByRole('admin'); + $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'edit', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'edit', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::edit + * @throws Exception + * @return void */ - public function testEditPutLoggedInSuccess(): void - { - // $this->loginUserByRole('admin'); - $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; - $before = $this->ProductPhotos->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'edit', - $id, - ]; - $data = [ - 'enabled' => 1, - 'primary_photo' => 1, - 'photo_position' => 999, - ]; - $this->put($url, $data); + public function testEditPutLoggedInSuccess(): void { + // $this->loginUserByRole('admin'); + $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; + $before = $this->ProductPhotos->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'edit', + $id, + ]; + $data = [ + 'enabled' => 1, + 'primary_photo' => 1, + 'photo_position' => 999, + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-photos'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-photos'); - $after = $this->ProductPhotos->get($id); - $this->assertEquals($data['photo_position'], $after->photo_position); - $this->assertTrue($after->primary_photo); - $this->assertTrue($after->enabled); - // assert saved properly below - } + $after = $this->ProductPhotos->get($id); + $this->assertEquals($data['photo_position'], $after->photo_position); + $this->assertTrue($after->primary_photo); + $this->assertTrue($after->enabled); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::edit + * @throws Exception + * @return void */ - public function testEditPutLoggedInFailure(): void - { - // $this->loginUserByRole('admin'); - $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; - $before = $this->ProductPhotos->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'edit', - $id, - ]; - $data = [ - 'enabled' => 1, - 'primary_photo' => 1, - 'photo_position' => 'not-valid', - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->ProductPhotos->get($id); - $this->assertEquals($before->modified, $after->modified); - $this->assertEquals($before->photo_position, $after->photo_position); + public function testEditPutLoggedInFailure(): void { + // $this->loginUserByRole('admin'); + $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; + $before = $this->ProductPhotos->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'edit', + $id, + ]; + $data = [ + 'enabled' => 1, + 'primary_photo' => 1, + 'photo_position' => 'not-valid', + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->ProductPhotos->get($id); + $this->assertEquals($before->modified, $after->modified); + $this->assertEquals($before->photo_position, $after->photo_position); - // assert save failed below - } + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * + * @uses \CakeProducts\Controller\ProductPhotosController::delete + * @throws Exception * @return void - * @throws Exception - * - * @uses \CakeProducts\Controller\ProductPhotosController::delete */ - public function testDeleteLoggedInDefaultProductPhoto(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); - $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; - $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->first(); - $primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->count(); - $this->assertEquals(1, $primaryPhotosBeforeCnt); + public function testDeleteLoggedInDefaultProductPhoto(): void { + $cntBefore = $this->ProductPhotos->find()->count(); + $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; + $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->first(); + $primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->count(); + $this->assertEquals(1, $primaryPhotosBeforeCnt); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'delete', - $id, - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-photos'); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'delete', + $id, + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-photos'); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); - $primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->first(); - $primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->count(); - $this->assertEquals(1, $primaryPhotosAfterCnt); - $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); - } + $primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->first(); + $primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->count(); + $this->assertEquals(1, $primaryPhotosAfterCnt); + $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::delete + * @throws Exception + * @return void */ - public function testDeleteLoggedInDefaultCategoryPhoto(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); - $id = '2c386086-f4c5-4093-bea5-ee9c29479f51'; - $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; + public function testDeleteLoggedInDefaultCategoryPhoto(): void { + $cntBefore = $this->ProductPhotos->find()->count(); + $id = '2c386086-f4c5-4093-bea5-ee9c29479f51'; + $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23'; - $primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->first(); - $primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->count(); - $this->assertEquals(1, $primaryPhotosBeforeCnt); + $primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->first(); + $primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->count(); + $this->assertEquals(1, $primaryPhotosBeforeCnt); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'delete', - $id, - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-photos'); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'delete', + $id, + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-photos'); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); - $primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->first(); - $primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->count(); - $this->assertEquals(1, $primaryPhotosAfterCnt); - $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); - } + $primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->first(); + $primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->count(); + $this->assertEquals(1, $primaryPhotosAfterCnt); + $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::delete + * @throws Exception + * @return void */ - public function testDeleteLoggedInDefaultSkuPhoto(): void - { - $cntBefore = $this->ProductPhotos->find()->count(); - $id = '2c386086-f4c5-4093-bea5-ee9c29479f11'; - $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $skuId = '3a477e3e-7977-4813-81f6-f85949613979'; + public function testDeleteLoggedInDefaultSkuPhoto(): void { + $cntBefore = $this->ProductPhotos->find()->count(); + $id = '2c386086-f4c5-4093-bea5-ee9c29479f11'; + $productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $skuId = '3a477e3e-7977-4813-81f6-f85949613979'; - $primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->first(); - $primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->count(); - $this->assertEquals(1, $primaryPhotosBeforeCnt); + $primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->first(); + $primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->count(); + $this->assertEquals(1, $primaryPhotosBeforeCnt); - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'delete', - $id, - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-photos'); + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'delete', + $id, + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-photos'); - $cntAfter = $this->ProductPhotos->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); + $cntAfter = $this->ProductPhotos->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); - $primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->first(); - $primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->count(); - $this->assertEquals(1, $primaryPhotosAfterCnt); - $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); - } + $primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->first(); + $primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->count(); + $this->assertEquals(1, $primaryPhotosAfterCnt); + $this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id); + } - /** + /** * Test image method * * Tests the image action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductPhotosController::image + * @throws Exception + * @return void */ - public function testImageGetLoggedIn(): void - { - $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; - // $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductPhotos', - 'action' => 'image', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testImageGetLoggedIn(): void { + $id = '2c386086-f4c5-4093-bea5-ee9c29479f58'; + // $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductPhotos', + 'action' => 'image', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } + } diff --git a/tests/TestCase/Controller/ProductSkusControllerTest.php b/tests/TestCase/Controller/ProductSkusControllerTest.php index 9920990..27b1ef8 100644 --- a/tests/TestCase/Controller/ProductSkusControllerTest.php +++ b/tests/TestCase/Controller/ProductSkusControllerTest.php @@ -3,355 +3,340 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; -use Cake\ORM\Table; -use Cake\TestSuite\IntegrationTestTrait; -use Cake\TestSuite\TestCase; use CakeProducts\Controller\ProductSkusController; use CakeProducts\Model\Table\ProductSkusTable; use CakeProducts\Model\Table\ProductSkuVariantValuesTable; -use CakeProducts\Model\Table\ProductsTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ProductSkusController Test Case */ #[CoversClass(ProductSkusController::class)] -class ProductSkusControllerTest extends BaseControllerTest -{ - /** +class ProductSkusControllerTest extends BaseControllerTest { + + /** * Test subject table * - * @var ProductSkusTable|Table + * @var \CakeProducts\Model\Table\ProductSkusTable|\Cake\ORM\Table */ - protected $ProductSkus; + protected $ProductSkus; - /** + /** * Test subject table * - * @var ProductSkuVariantValuesTable|Table + * @var \CakeProducts\Model\Table\ProductSkuVariantValuesTable|\Cake\ORM\Table */ - protected $ProductSkuVariantValues; + protected $ProductSkuVariantValues; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductSkus', - 'plugin.CakeProducts.Products', - 'plugin.CakeProducts.ProductAttributes', - 'plugin.CakeProducts.ProductVariants', - 'plugin.CakeProducts.ProductCategoryVariants', - 'plugin.CakeProducts.ProductCategoryVariantOptions', - 'plugin.CakeProducts.ProductSkuVariantValues', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductSkus', + 'plugin.CakeProducts.Products', + 'plugin.CakeProducts.ProductAttributes', + 'plugin.CakeProducts.ProductVariants', + 'plugin.CakeProducts.ProductCategoryVariants', + 'plugin.CakeProducts.ProductCategoryVariantOptions', + 'plugin.CakeProducts.ProductSkuVariantValues', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $this->disableErrorHandlerMiddleware(); + $this->disableErrorHandlerMiddleware(); - $config = $this->getTableLocator()->exists('ProductSkus') ? [] : ['className' => ProductSkusTable::class]; - $this->ProductSkus = $this->getTableLocator()->get('ProductSkus', $config); + $config = $this->getTableLocator()->exists('ProductSkus') ? [] : ['className' => ProductSkusTable::class]; + $this->ProductSkus = $this->getTableLocator()->get('ProductSkus', $config); - $config = $this->getTableLocator()->exists('ProductSkuVariantValues') ? [] : ['className' => ProductSkuVariantValuesTable::class]; - $this->ProductSkuVariantValues = $this->getTableLocator()->get('ProductSkuVariantValues', $config); - } + $config = $this->getTableLocator()->exists('ProductSkuVariantValues') ? [] : ['className' => ProductSkuVariantValuesTable::class]; + $this->ProductSkuVariantValues = $this->getTableLocator()->get('ProductSkuVariantValues', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductSkus); + protected function tearDown(): void { + unset($this->ProductSkus); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::index() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testIndexGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::view() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testViewGet(): void - { - $id = '3a477e3e-7977-4813-81f6-f85949613979'; - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGet(): void { + $id = '3a477e3e-7977-4813-81f6-f85949613979'; + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->ProductSkus->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->ProductSkus->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'add', - 'cfc98a9a-29b2-44c8-b587-8156adc05317' - ]; - $this->get($url); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'add', + 'cfc98a9a-29b2-44c8-b587-8156adc05317', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->ProductSkus->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductSkus->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostSuccess(): void - { - $cntBefore = $this->ProductSkus->find()->count(); - $cntVariantValuesBefore = $this->ProductSkuVariantValues->find()->count(); + public function testAddPostSuccess(): void { + $cntBefore = $this->ProductSkus->find()->count(); + $cntVariantValuesBefore = $this->ProductSkuVariantValues->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'add', - 'cfc98a9a-29b2-44c8-b587-8156adc05317', - ]; - $data = [ - 0 => [ - 'sku' => 'cfc98a9a-29b2-44c8-b587-8156a', - 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156a', - 'price' => 1.5, - 'cost' => 1.5, - 'product_sku_variant_values' => [ - 0 => [ - 'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568', - 'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', - ], - ], - ], - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-skus'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'add', + 'cfc98a9a-29b2-44c8-b587-8156adc05317', + ]; + $data = [ + 0 => [ + 'sku' => 'cfc98a9a-29b2-44c8-b587-8156a', + 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156a', + 'price' => 1.5, + 'cost' => 1.5, + 'product_sku_variant_values' => [ + 0 => [ + 'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568', + 'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23', + ], + ], + ], + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-skus'); - $cntAfter = $this->ProductSkus->find()->count(); - $cntVariantValuesAfter = $this->ProductSkuVariantValues->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - $this->assertEquals($cntVariantValuesBefore + 1, $cntVariantValuesAfter); - } + $cntAfter = $this->ProductSkus->find()->count(); + $cntVariantValuesAfter = $this->ProductSkuVariantValues->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); + $this->assertEquals($cntVariantValuesBefore + 1, $cntVariantValuesAfter); + } - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::add() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testAddPostFailure(): void - { - $cntBefore = $this->ProductSkus->find()->count(); + public function testAddPostFailure(): void { + $cntBefore = $this->ProductSkus->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'add', - 'cfc98a9a-29b2-44c8-b587-8156adc05317', - ]; - $data = [ - 0 => [ - 'sku' => '', - 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'price' => 1.5, - 'cost' => 1.5, - ], - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'add', + 'cfc98a9a-29b2-44c8-b587-8156adc05317', + ]; + $data = [ + 0 => [ + 'sku' => '', + 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'price' => 1.5, + 'cost' => 1.5, + ], + ]; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->ProductSkus->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->ProductSkus->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'edit', - '3a477e3e-7977-4813-81f6-f85949613979', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testEditGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'edit', + '3a477e3e-7977-4813-81f6-f85949613979', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutSuccess(): void - { - $this->loginUserByRole('admin'); - $id = '3a477e3e-7977-4813-81f6-f85949613979'; - $before = $this->ProductSkus->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'edit', - $id, - ]; - $data = [ - // test new data here - ]; - $this->put($url, $data); + public function testEditPutSuccess(): void { + $this->loginUserByRole('admin'); + $id = '3a477e3e-7977-4813-81f6-f85949613979'; + $before = $this->ProductSkus->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'edit', + $id, + ]; + $data = [ + // test new data here + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-skus'); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-skus'); - $after = $this->ProductSkus->get($id); - // assert saved properly below - } + $after = $this->ProductSkus->get($id); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::edit() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testEditPutFailure(): void - { - $this->loginUserByRole('admin'); - $id = '3a477e3e-7977-4813-81f6-f85949613979'; - $before = $this->ProductSkus->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'edit', - $id, - ]; - $data = [ - 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'sku' => '', - 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', - 'price' => 1.5, - 'cost' => 1.5, - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->ProductSkus->get($id); + public function testEditPutFailure(): void { + $this->loginUserByRole('admin'); + $id = '3a477e3e-7977-4813-81f6-f85949613979'; + $before = $this->ProductSkus->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'edit', + $id, + ]; + $data = [ + 'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'sku' => '', + 'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317', + 'price' => 1.5, + 'cost' => 1.5, + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->ProductSkus->get($id); - // assert save failed below - } + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * * @uses \CakeProducts\Controller\ProductSkusController::delete() - * @throws Exception + * @throws \PHPUnit\Exception * * @return void */ - public function testDelete(): void - { - $cntBefore = $this->ProductSkus->find()->count(); + public function testDelete(): void { + $cntBefore = $this->ProductSkus->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'ProductSkus', - 'action' => 'delete', - '3a477e3e-7977-4813-81f6-f85949613979', - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('product-skus'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'ProductSkus', + 'action' => 'delete', + '3a477e3e-7977-4813-81f6-f85949613979', + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('product-skus'); + + $cntAfter = $this->ProductSkus->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + } - $cntAfter = $this->ProductSkus->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - } } diff --git a/tests/TestCase/Controller/ProductsControllerTest.php b/tests/TestCase/Controller/ProductsControllerTest.php index 38481d0..75b2a93 100644 --- a/tests/TestCase/Controller/ProductsControllerTest.php +++ b/tests/TestCase/Controller/ProductsControllerTest.php @@ -3,343 +3,318 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Controller; -use Cake\ORM\Table; -use Cake\TestSuite\IntegrationTestTrait; -use Cake\TestSuite\TestCase; use CakeProducts\Controller\ProductsController; -use CakeProducts\Model\Table\ProductCatalogsTable; use CakeProducts\Model\Table\ProductsTable; -use PHPUnit\Exception; use PHPUnit\Framework\Attributes\CoversClass; /** * CakeProducts\Controller\ProductsController Test Case */ #[CoversClass(ProductsController::class)] -class ProductsControllerTest extends BaseControllerTest -{ - /** +class ProductsControllerTest extends BaseControllerTest { + + /** * Test subject table * - * @var ProductsTable|Table + * @var \CakeProducts\Model\Table\ProductsTable|\Cake\ORM\Table */ - protected $Products; + protected $Products; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.Products', - 'plugin.CakeProducts.ProductAttributes', - 'plugin.CakeProducts.ProductCategories', - 'plugin.CakeProducts.ProductCategoryAttributes', - 'plugin.CakeProducts.ProductCategoryAttributeOptions', + protected array $fixtures = [ + 'plugin.CakeProducts.Products', + 'plugin.CakeProducts.ProductAttributes', + 'plugin.CakeProducts.ProductCategories', + 'plugin.CakeProducts.ProductCategoryAttributes', + 'plugin.CakeProducts.ProductCategoryAttributeOptions', // 'plugin.CakeProducts.ProductCatalogs', - ]; + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); + protected function setUp(): void { + parent::setUp(); // $this->enableCsrfToken(); // $this->enableSecurityToken(); - $config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class]; - $this->Products = $this->getTableLocator()->get('Products', $config); - } + $config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class]; + $this->Products = $this->getTableLocator()->get('Products', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->Products); + protected function tearDown(): void { + unset($this->Products); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * Test index method * * Tests the index action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::index + * @throws Exception + * @return void */ - public function testIndexGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'index', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testIndexGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'index', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test view method * * Tests the view action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::view + * @throws Exception + * @return void */ - public function testViewGet(): void - { - $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'view', - $id, - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testViewGet(): void { + $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'view', + $id, + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test add method * * Tests the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::add + * @throws Exception + * @return void */ - public function testAddGet(): void - { - $cntBefore = $this->Products->find()->count(); + public function testAddGet(): void { + $cntBefore = $this->Products->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'add', - ]; - $this->get($url); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'add', + ]; + $this->get($url); + $this->assertResponseCode(200); - $cntAfter = $this->Products->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->Products->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test add method * * Tests the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::add + * @throws Exception + * @return void */ - public function testAddPostSuccess(): void - { - $cntBefore = $this->Products->find()->count(); - $productAttributesCntBefore = $this->Products->ProductAttributes->find()->count(); + public function testAddPostSuccess(): void { + $cntBefore = $this->Products->find()->count(); + $productAttributesCntBefore = $this->Products->ProductAttributes->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'add', - ]; - $data = [ - // test new data here - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'name' => '14AWG Red Wire', - 'product_type_id' => 1, - 'product_attributes' => [ - [ - 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', - 'product_category_attribute_option_id' => 'e06f1723-2456-483a-b3c4-004603e032a2', // green - 'attribute_value' => '', - ], - ], - ]; - $this->post($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('products'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'add', + ]; + $data = [ + // test new data here + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'name' => '14AWG Red Wire', + 'product_type_id' => 1, + 'product_attributes' => [ + [ + 'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c', + 'product_category_attribute_option_id' => 'e06f1723-2456-483a-b3c4-004603e032a2', // green + 'attribute_value' => '', + ], + ], + ]; + $this->post($url, $data); + $this->assertResponseCode(302); + $this->assertRedirectContains('products'); - $cntAfter = $this->Products->find()->count(); - $productAttributesCntAfter = $this->Products->ProductAttributes->find()->count(); - $this->assertEquals($cntBefore + 1, $cntAfter); - $this->assertEquals($productAttributesCntBefore + 1, $productAttributesCntAfter); - } + $cntAfter = $this->Products->find()->count(); + $productAttributesCntAfter = $this->Products->ProductAttributes->find()->count(); + $this->assertEquals($cntBefore + 1, $cntAfter); + $this->assertEquals($productAttributesCntBefore + 1, $productAttributesCntAfter); + } - - /** + /** * Test add method * * Tests a POST request to the add action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::add + * @throws Exception + * @return void */ - public function testAddPostFailure(): void - { - $cntBefore = $this->Products->find()->count(); + public function testAddPostFailure(): void { + $cntBefore = $this->Products->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'add', - ]; - $data = [ - 'product_catalog_id' => '', - 'product_category_id' => '', - 'name' => '', - 'product_type_id' => 1, - 'product_attributes' => [], - ]; - $this->post($url, $data); - $this->assertResponseCode(200); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'add', + ]; + $data = [ + 'product_catalog_id' => '', + 'product_category_id' => '', + 'name' => '', + 'product_type_id' => 1, + 'product_attributes' => [], + ]; + $this->post($url, $data); + $this->assertResponseCode(200); - $cntAfter = $this->Products->find()->count(); - $this->assertEquals($cntBefore, $cntAfter); - } + $cntAfter = $this->Products->find()->count(); + $this->assertEquals($cntBefore, $cntAfter); + } - /** + /** * Test edit method * * Tests the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::edit + * @throws Exception + * @return void */ - public function testEditGet(): void - { - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'edit', - 'cfc98a9a-29b2-44c8-b587-8156adc05317', - ]; - $this->get($url); - $this->assertResponseCode(200); - } + public function testEditGet(): void { + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'edit', + 'cfc98a9a-29b2-44c8-b587-8156adc05317', + ]; + $this->get($url); + $this->assertResponseCode(200); + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::edit + * @throws Exception + * @return void */ - public function testEditPutSuccess(): void - { - $this->loginUserByRole('admin'); - $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $before = $this->Products->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'edit', - $id, - ]; - $data = [ - // test new data here - 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', - 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', - 'name' => 'edited product name', - 'product_type_id' => 1, - ]; - $this->put($url, $data); + public function testEditPutSuccess(): void { + $this->loginUserByRole('admin'); + $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $before = $this->Products->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'edit', + $id, + ]; + $data = [ + // test new data here + 'product_catalog_id' => '115153f3-2f59-4234-8ff8-e1b205761428', + 'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23', + 'name' => 'edited product name', + 'product_type_id' => 1, + ]; + $this->put($url, $data); - $this->assertResponseCode(302); - $this->assertRedirectContains('products'); + $this->assertResponseCode(302); + $this->assertRedirectContains('products'); - $after = $this->Products->get($id); - $this->assertEquals($data['name'], $after->name); - // assert saved properly below - } + $after = $this->Products->get($id); + $this->assertEquals($data['name'], $after->name); + // assert saved properly below + } - /** + /** * Test edit method * * Tests a PUT request to the edit action with a logged in user * - * @return void - * @throws Exception - * * @uses \CakeProducts\Controller\ProductsController::edit + * @throws Exception + * @return void */ - public function testEditPutFailure(): void - { - $this->loginUserByRole('admin'); - $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; - $before = $this->Products->get($id); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'edit', - $id, - ]; - $data = [ - 'product_catalog_id' => '', - 'product_category_id' => '', - 'name' => 'edited name not gonna take', - 'product_type_id' => 1, - ]; - $this->put($url, $data); - $this->assertResponseCode(200); - $after = $this->Products->get($id); - $this->assertEquals($before->name, $after->name); - $this->assertEquals($before->product_category_id, $after->product_category_id); - // assert save failed below - } + public function testEditPutFailure(): void { + $this->loginUserByRole('admin'); + $id = 'cfc98a9a-29b2-44c8-b587-8156adc05317'; + $before = $this->Products->get($id); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'edit', + $id, + ]; + $data = [ + 'product_catalog_id' => '', + 'product_category_id' => '', + 'name' => 'edited name not gonna take', + 'product_type_id' => 1, + ]; + $this->put($url, $data); + $this->assertResponseCode(200); + $after = $this->Products->get($id); + $this->assertEquals($before->name, $after->name); + $this->assertEquals($before->product_category_id, $after->product_category_id); + // assert save failed below + } - /** + /** * Test delete method * * Tests the delete action with a logged in user * - * @return void - *@throws Exception - * * @uses \CakeProducts\Controller\ProductsController::delete + *@throws Exception + * @return void */ - public function testDelete(): void - { - $cntBefore = $this->Products->find()->count(); + public function testDelete(): void { + $cntBefore = $this->Products->find()->count(); - $this->loginUserByRole('admin'); - $url = [ - 'plugin' => 'CakeProducts', - 'controller' => 'Products', - 'action' => 'delete', - 'cfc98a9a-29b2-44c8-b587-8156adc05317', - ]; - $this->delete($url); - $this->assertResponseCode(302); - $this->assertRedirectContains('products'); + $this->loginUserByRole('admin'); + $url = [ + 'plugin' => 'CakeProducts', + 'controller' => 'Products', + 'action' => 'delete', + 'cfc98a9a-29b2-44c8-b587-8156adc05317', + ]; + $this->delete($url); + $this->assertResponseCode(302); + $this->assertRedirectContains('products'); + + $cntAfter = $this->Products->find()->count(); + $this->assertEquals($cntBefore - 1, $cntAfter); + } - $cntAfter = $this->Products->find()->count(); - $this->assertEquals($cntBefore - 1, $cntAfter); - } } diff --git a/tests/TestCase/Model/Table/ExternalProductCatalogsTableTest.php b/tests/TestCase/Model/Table/ExternalProductCatalogsTableTest.php index a0c271f..897a1c7 100644 --- a/tests/TestCase/Model/Table/ExternalProductCatalogsTableTest.php +++ b/tests/TestCase/Model/Table/ExternalProductCatalogsTableTest.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Model\Table; -use Cake\ORM\Table; use Cake\TestSuite\TestCase; use CakeProducts\Model\Table\ExternalProductCatalogsTable; use PHPUnit\Framework\Attributes\CoversClass; @@ -12,102 +11,98 @@ use PHPUnit\Framework\Attributes\CoversClass; * CakeProducts\Model\Table\ExternalProductCatalogsTable Test Case */ #[CoversClass(ExternalProductCatalogsTable::class)] -class ExternalProductCatalogsTableTest extends TestCase -{ - /** +class ExternalProductCatalogsTableTest extends TestCase { + + /** * Test subject * - * @var ExternalProductCatalogsTable + * @var \CakeProducts\Model\Table\ExternalProductCatalogsTable */ - protected $ExternalProductCatalogs; + protected $ExternalProductCatalogs; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ExternalProductCatalogs', - 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', - 'plugin.CakeProducts.ProductCatalogs', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ExternalProductCatalogs', + 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', + 'plugin.CakeProducts.ProductCatalogs', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ExternalProductCatalogs') ? [] : ['className' => ExternalProductCatalogsTable::class]; - $this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ExternalProductCatalogs') ? [] : ['className' => ExternalProductCatalogsTable::class]; + $this->ExternalProductCatalogs = $this->getTableLocator()->get('ExternalProductCatalogs', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ExternalProductCatalogs); + protected function tearDown(): void { + unset($this->ExternalProductCatalogs); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * - * @return void * @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::initialize + * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'ProductCatalogs', - 'ExternalProductCatalogsProductCatalogs', - ]; - $associations = $this->ExternalProductCatalogs->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'ProductCatalogs', + 'ExternalProductCatalogsProductCatalogs', + ]; + $associations = $this->ExternalProductCatalogs->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->ExternalProductCatalogs->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->ExternalProductCatalogs->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = [ - 'Timestamp', - 'Trash', - ]; - $behaviors = $this->ExternalProductCatalogs->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = [ + 'Timestamp', + 'Trash', + ]; + $behaviors = $this->ExternalProductCatalogs->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->ExternalProductCatalogs->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->ExternalProductCatalogs->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::validationDefault + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } - /** + /** * Test buildRules method * - * @return void * @uses \CakeProducts\Model\Table\ExternalProductCatalogsTable::buildRules + * @return void */ - public function testBuildRules(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testBuildRules(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/TestCase/Model/Table/ProductCatalogsTableTest.php b/tests/TestCase/Model/Table/ProductCatalogsTableTest.php index f680cbc..de425a5 100644 --- a/tests/TestCase/Model/Table/ProductCatalogsTableTest.php +++ b/tests/TestCase/Model/Table/ProductCatalogsTableTest.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Model\Table; -use Cake\ORM\Table; use Cake\TestSuite\TestCase; use CakeProducts\Model\Table\ProductCatalogsTable; use PHPUnit\Framework\Attributes\CoversClass; @@ -12,90 +11,87 @@ use PHPUnit\Framework\Attributes\CoversClass; * CakeProducts\Model\Table\ProductCatalogsTable Test Case */ #[CoversClass(ProductCatalogsTable::class)] -class ProductCatalogsTableTest extends TestCase -{ - /** +class ProductCatalogsTableTest extends TestCase { + + /** * Test subject * - * @var ProductCatalogsTable|Table + * @var \CakeProducts\Model\Table\ProductCatalogsTable|\Cake\ORM\Table */ - protected $ProductCatalogs; + protected $ProductCatalogs; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCatalogs', - 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', - 'plugin.CakeProducts.ProductCategories', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCatalogs', + 'plugin.CakeProducts.ExternalProductCatalogsProductCatalogs', + 'plugin.CakeProducts.ProductCategories', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class]; - $this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ProductCatalogs') ? [] : ['className' => ProductCatalogsTable::class]; + $this->ProductCatalogs = $this->getTableLocator()->get('ProductCatalogs', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCatalogs); + protected function tearDown(): void { + unset($this->ProductCatalogs); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * - * @return void * @uses \CakeProducts\Model\Table\ProductCatalogsTable::initialize + * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'ProductCategories', - 'ExternalProductCatalogs', - ]; - $associations = $this->ProductCatalogs->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'ProductCategories', + 'ExternalProductCatalogs', + ]; + $associations = $this->ProductCatalogs->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->ProductCatalogs->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->ProductCatalogs->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = [ - 'Trash', - ]; - $behaviors = $this->ProductCatalogs->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = [ + 'Trash', + ]; + $behaviors = $this->ProductCatalogs->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->ProductCatalogs->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->ProductCatalogs->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \CakeProducts\Model\Table\ProductCatalogsTable::validationDefault + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/TestCase/Model/Table/ProductCategoriesTableTest.php b/tests/TestCase/Model/Table/ProductCategoriesTableTest.php index bff1d5b..71ed94c 100644 --- a/tests/TestCase/Model/Table/ProductCategoriesTableTest.php +++ b/tests/TestCase/Model/Table/ProductCategoriesTableTest.php @@ -11,107 +11,103 @@ use PHPUnit\Framework\Attributes\CoversClass; * CakeProducts\Model\Table\ProductCategoriesTable Test Case */ #[CoversClass(ProductCategoriesTable::class)] -class ProductCategoriesTableTest extends TestCase -{ - /** +class ProductCategoriesTableTest extends TestCase { + + /** * Test subject * * @var \CakeProducts\Model\Table\ProductCategoriesTable */ - protected $ProductCategories; + protected $ProductCategories; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCategories', - 'plugin.CakeProducts.ProductCatalogs', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCategories', + 'plugin.CakeProducts.ProductCatalogs', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ProductCategories') ? [] : ['className' => ProductCategoriesTable::class]; - $this->ProductCategories = $this->getTableLocator()->get('ProductCategories', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ProductCategories') ? [] : ['className' => ProductCategoriesTable::class]; + $this->ProductCategories = $this->getTableLocator()->get('ProductCategories', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategories); + protected function tearDown(): void { + unset($this->ProductCategories); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoriesTable::initialize() + * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'ProductCatalogs', - 'ParentProductCategories', - 'ChildProductCategories', - 'Products', - 'ProductCategoryAttributes', - 'ProductCategoryVariants', - 'ProductPhotos', - 'PrimaryProductPhotos', - ]; - $associations = $this->ProductCategories->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'ProductCatalogs', + 'ParentProductCategories', + 'ChildProductCategories', + 'Products', + 'ProductCategoryAttributes', + 'ProductCategoryVariants', + 'ProductPhotos', + 'PrimaryProductPhotos', + ]; + $associations = $this->ProductCategories->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->ProductCategories->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->ProductCategories->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = [ - 'Tree', - 'Trash', - ]; - $behaviors = $this->ProductCategories->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = [ + 'Tree', + 'Trash', + ]; + $behaviors = $this->ProductCategories->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->ProductCategories->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->ProductCategories->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoriesTable::validationDefault() + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } - /** + /** * Test buildRules method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoriesTable::buildRules() + * @return void */ - public function testBuildRules(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testBuildRules(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/TestCase/Model/Table/ProductCategoryAttributeOptionsTableTest.php b/tests/TestCase/Model/Table/ProductCategoryAttributeOptionsTableTest.php index 9f70430..975494d 100644 --- a/tests/TestCase/Model/Table/ProductCategoryAttributeOptionsTableTest.php +++ b/tests/TestCase/Model/Table/ProductCategoryAttributeOptionsTableTest.php @@ -11,98 +11,94 @@ use PHPUnit\Framework\Attributes\CoversClass; * CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable Test Case */ #[CoversClass(ProductCategoryAttributeOptionsTable::class)] -class ProductCategoryAttributeOptionsTableTest extends TestCase -{ - /** +class ProductCategoryAttributeOptionsTableTest extends TestCase { + + /** * Test subject * - * @var ProductCategoryAttributeOptionsTable + * @var \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable */ - protected $ProductCategoryAttributeOptions; + protected $ProductCategoryAttributeOptions; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCategoryAttributeOptions', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCategoryAttributeOptions', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class]; - $this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ProductCategoryAttributeOptions') ? [] : ['className' => ProductCategoryAttributeOptionsTable::class]; + $this->ProductCategoryAttributeOptions = $this->getTableLocator()->get('ProductCategoryAttributeOptions', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategoryAttributeOptions); + protected function tearDown(): void { + unset($this->ProductCategoryAttributeOptions); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::initialize + * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'ProductCategoryAttributes', - ]; - $associations = $this->ProductCategoryAttributeOptions->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'ProductCategoryAttributes', + ]; + $associations = $this->ProductCategoryAttributeOptions->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->ProductCategoryAttributeOptions->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->ProductCategoryAttributeOptions->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = [ - 'Trash', - ]; - $behaviors = $this->ProductCategoryAttributeOptions->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = [ + 'Trash', + ]; + $behaviors = $this->ProductCategoryAttributeOptions->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->ProductCategoryAttributeOptions->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->ProductCategoryAttributeOptions->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::validationDefault + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } - /** + /** * Test buildRules method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryAttributeOptionsTable::buildRules + * @return void */ - public function testBuildRules(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testBuildRules(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/TestCase/Model/Table/ProductCategoryAttributesTableTest.php b/tests/TestCase/Model/Table/ProductCategoryAttributesTableTest.php index 4cc4d09..afde9a7 100644 --- a/tests/TestCase/Model/Table/ProductCategoryAttributesTableTest.php +++ b/tests/TestCase/Model/Table/ProductCategoryAttributesTableTest.php @@ -11,101 +11,97 @@ use PHPUnit\Framework\Attributes\CoversClass; * CakeProducts\Model\Table\ProductCategoryAttributesTable Test Case */ #[CoversClass(ProductCategoryAttributesTable::class)] -class ProductCategoryAttributesTableTest extends TestCase -{ - /** +class ProductCategoryAttributesTableTest extends TestCase { + + /** * Test subject * - * @var ProductCategoryAttributesTable + * @var \CakeProducts\Model\Table\ProductCategoryAttributesTable */ - protected $ProductCategoryAttributes; + protected $ProductCategoryAttributes; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCategoryAttributes', - 'plugin.CakeProducts.ProductCategoryAttributeOptions', - 'plugin.CakeProducts.ProductCategories', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCategoryAttributes', + 'plugin.CakeProducts.ProductCategoryAttributeOptions', + 'plugin.CakeProducts.ProductCategories', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class]; - $this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ProductCategoryAttributes') ? [] : ['className' => ProductCategoryAttributesTable::class]; + $this->ProductCategoryAttributes = $this->getTableLocator()->get('ProductCategoryAttributes', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategoryAttributes); + protected function tearDown(): void { + unset($this->ProductCategoryAttributes); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::initialize + * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'ProductCategories', - 'ProductCategoryAttributeOptions', - ]; - $associations = $this->ProductCategoryAttributes->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'ProductCategories', + 'ProductCategoryAttributeOptions', + ]; + $associations = $this->ProductCategoryAttributes->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->ProductCategoryAttributes->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->ProductCategoryAttributes->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = [ - 'Trash', - ]; - $behaviors = $this->ProductCategoryAttributes->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = [ + 'Trash', + ]; + $behaviors = $this->ProductCategoryAttributes->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->ProductCategoryAttributes->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->ProductCategoryAttributes->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::validationDefault + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } - /** + /** * Test buildRules method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryAttributesTable::buildRules + * @return void */ - public function testBuildRules(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testBuildRules(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/TestCase/Model/Table/ProductCategoryVariantOptionsTableTest.php b/tests/TestCase/Model/Table/ProductCategoryVariantOptionsTableTest.php index dcb7be6..bb75d47 100644 --- a/tests/TestCase/Model/Table/ProductCategoryVariantOptionsTableTest.php +++ b/tests/TestCase/Model/Table/ProductCategoryVariantOptionsTableTest.php @@ -3,107 +3,103 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Model\Table; -use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable; use Cake\TestSuite\TestCase; +use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable; use PHPUnit\Framework\Attributes\CoversClass; /** * App\Model\Table\ProductCategoryVariantOptionsTable Test Case */ #[CoversClass(ProductCategoryVariantOptionsTable::class)] -class ProductCategoryVariantOptionsTableTest extends TestCase -{ - /** +class ProductCategoryVariantOptionsTableTest extends TestCase { + + /** * Test subject * * @var \App\Model\Table\ProductCategoryVariantOptionsTable */ - protected $ProductCategoryVariantOptions; + protected $ProductCategoryVariantOptions; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.ProductCategoryVariants', - 'plugin.CakeProducts.ProductCategoryVariantOptions', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.ProductCategoryVariants', + 'plugin.CakeProducts.ProductCategoryVariantOptions', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class]; - $this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ProductCategoryVariantOptions') ? [] : ['className' => ProductCategoryVariantOptionsTable::class]; + $this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductCategoryVariantOptions); + protected function tearDown(): void { + unset($this->ProductCategoryVariantOptions); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::initialize() + * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'ProductCategoryVariants', - ]; - $associations = $this->ProductCategoryVariantOptions->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'ProductCategoryVariants', + ]; + $associations = $this->ProductCategoryVariantOptions->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->ProductCategoryVariantOptions->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->ProductCategoryVariantOptions->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = [ - 'Timestamp', - ]; - $behaviors = $this->ProductCategoryVariantOptions->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = [ + 'Timestamp', + ]; + $behaviors = $this->ProductCategoryVariantOptions->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->ProductCategoryVariantOptions->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->ProductCategoryVariantOptions->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::validationDefault() + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } - /** + /** * Test buildRules method * - * @return void * @uses \CakeProducts\Model\Table\ProductCategoryVariantOptionsTable::buildRules() + * @return void */ - public function testBuildRules(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testBuildRules(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/TestCase/Model/Table/ProductVariantsTableTest.php b/tests/TestCase/Model/Table/ProductVariantsTableTest.php index 0829c6e..331fb19 100644 --- a/tests/TestCase/Model/Table/ProductVariantsTableTest.php +++ b/tests/TestCase/Model/Table/ProductVariantsTableTest.php @@ -3,105 +3,101 @@ declare(strict_types=1); namespace CakeProducts\Test\TestCase\Model\Table; -use CakeProducts\Model\Table\ProductVariantsTable; use Cake\TestSuite\TestCase; +use CakeProducts\Model\Table\ProductVariantsTable; /** * CakeProducts\Model\Table\ProductVariantsTable Test Case */ -class ProductVariantsTableTest extends TestCase -{ - /** +class ProductVariantsTableTest extends TestCase { + + /** * Test subject * * @var \App\Model\Table\ProductVariantsTable */ - protected $ProductVariants; + protected $ProductVariants; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.Products', - 'plugin.CakeProducts.ProductCategoryVariants', - 'plugin.CakeProducts.ProductCategoryVariantOptions', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.Products', + 'plugin.CakeProducts.ProductCategoryVariants', + 'plugin.CakeProducts.ProductCategoryVariantOptions', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('ProductVariants') ? [] : ['className' => ProductVariantsTable::class]; - $this->ProductVariants = $this->getTableLocator()->get('ProductVariants', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('ProductVariants') ? [] : ['className' => ProductVariantsTable::class]; + $this->ProductVariants = $this->getTableLocator()->get('ProductVariants', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->ProductVariants); + protected function tearDown(): void { + unset($this->ProductVariants); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'Products', - 'ProductCategoryVariants', - 'ProductSkuVariantValues', - ]; - $associations = $this->ProductVariants->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'Products', + 'ProductCategoryVariants', + 'ProductSkuVariantValues', + ]; + $associations = $this->ProductVariants->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->ProductVariants->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->ProductVariants->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = []; - $behaviors = $this->ProductVariants->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = []; + $behaviors = $this->ProductVariants->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->ProductVariants->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->ProductVariants->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \App\Model\Table\ProductVariantsTable::validationDefault() + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } - /** + /** * Test buildRules method * - * @return void * @uses \App\Model\Table\ProductVariantsTable::buildRules() + * @return void */ - public function testBuildRules(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testBuildRules(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/TestCase/Model/Table/ProductsTableTest.php b/tests/TestCase/Model/Table/ProductsTableTest.php index 292ff92..84789cd 100644 --- a/tests/TestCase/Model/Table/ProductsTableTest.php +++ b/tests/TestCase/Model/Table/ProductsTableTest.php @@ -11,107 +11,103 @@ use PHPUnit\Framework\Attributes\CoversClass; * CakeProducts\Model\Table\ProductsTable Test Case */ #[CoversClass(ProductsTable::class)] -class ProductsTableTest extends TestCase -{ - /** +class ProductsTableTest extends TestCase { + + /** * Test subject * - * @var ProductsTable + * @var \CakeProducts\Model\Table\ProductsTable */ - protected $Products; + protected $Products; - /** + /** * Fixtures * * @var array */ - protected array $fixtures = [ - 'plugin.CakeProducts.Products', - 'plugin.CakeProducts.ProductCategories', - 'plugin.CakeProducts.ProductSkus', - 'plugin.CakeProducts.ProductSkuVariantValues', - ]; + protected array $fixtures = [ + 'plugin.CakeProducts.Products', + 'plugin.CakeProducts.ProductCategories', + 'plugin.CakeProducts.ProductSkus', + 'plugin.CakeProducts.ProductSkuVariantValues', + ]; - /** + /** * setUp method * * @return void */ - protected function setUp(): void - { - parent::setUp(); - $config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class]; - $this->Products = $this->getTableLocator()->get('Products', $config); - } + protected function setUp(): void { + parent::setUp(); + $config = $this->getTableLocator()->exists('Products') ? [] : ['className' => ProductsTable::class]; + $this->Products = $this->getTableLocator()->get('Products', $config); + } - /** + /** * tearDown method * * @return void */ - protected function tearDown(): void - { - unset($this->Products); + protected function tearDown(): void { + unset($this->Products); - parent::tearDown(); - } + parent::tearDown(); + } - /** + /** * TestInitialize method * - * @return void * @uses \CakeProducts\Model\Table\ProductsTable::initialize + * @return void */ - public function testInitialize(): void - { - // verify all associations loaded - $expectedAssociations = [ - 'ProductCategories', - 'ProductAttributes', - 'ProductVariants', - 'ProductSkus', - 'ProductPhotos', - 'PrimaryProductPhotos', - 'DefaultProductSkus', - ]; - $associations = $this->Products->associations(); + public function testInitialize(): void { + // verify all associations loaded + $expectedAssociations = [ + 'ProductCategories', + 'ProductAttributes', + 'ProductVariants', + 'ProductSkus', + 'ProductPhotos', + 'PrimaryProductPhotos', + 'DefaultProductSkus', + ]; + $associations = $this->Products->associations(); - $this->assertCount(count($expectedAssociations), $associations); - foreach ($expectedAssociations as $expectedAssociation) { - $this->assertTrue($this->Products->hasAssociation($expectedAssociation)); - } + $this->assertCount(count($expectedAssociations), $associations); + foreach ($expectedAssociations as $expectedAssociation) { + $this->assertTrue($this->Products->hasAssociation($expectedAssociation)); + } - // verify all behaviors loaded - $expectedBehaviors = [ - 'Trash', - ]; - $behaviors = $this->Products->behaviors(); + // verify all behaviors loaded + $expectedBehaviors = [ + 'Trash', + ]; + $behaviors = $this->Products->behaviors(); - $this->assertCount(count($expectedBehaviors), $behaviors); - foreach ($expectedBehaviors as $expectedBehavior) { - $this->assertTrue($this->Products->hasBehavior($expectedBehavior)); - } - } + $this->assertCount(count($expectedBehaviors), $behaviors); + foreach ($expectedBehaviors as $expectedBehavior) { + $this->assertTrue($this->Products->hasBehavior($expectedBehavior)); + } + } - /** + /** * Test validationDefault method * - * @return void * @uses \CakeProducts\Model\Table\ProductsTable::validationDefault + * @return void */ - public function testValidationDefault(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testValidationDefault(): void { + $this->markTestIncomplete('Not implemented yet.'); + } - /** + /** * Test buildRules method * - * @return void * @uses \CakeProducts\Model\Table\ProductsTable::buildRules + * @return void */ - public function testBuildRules(): void - { - $this->markTestIncomplete('Not implemented yet.'); - } + public function testBuildRules(): void { + $this->markTestIncomplete('Not implemented yet.'); + } + } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 209c47c..6451218 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,20 +7,19 @@ 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); + define('DS', DIRECTORY_SEPARATOR); } if (!defined('WINDOWS')) { - if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') { - define('WINDOWS', true); - } else { - define('WINDOWS', false); - } + if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') { + define('WINDOWS', true); + } else { + define('WINDOWS', false); + } } define('PLUGIN_ROOT', dirname(__DIR__)); @@ -45,23 +44,23 @@ 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, - ], - ], + '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('CakeProducts', [ - 'photos' => [ - 'directory' => PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS . 'images' . DS . 'products' . DS, - ], - /** + 'photos' => [ + 'directory' => PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS . 'uploads' . DS . 'images' . DS . 'products' . DS, + ], + /** * internal CakeProducts settings - used in the source of truth/internal only system. * Can optionally manage external catalogs * @@ -69,39 +68,39 @@ Configure::write('CakeProducts', [ * which will receive changes to the catalogs and optionally allow for external API access. * Will have no effect if true but no external catalogs have been added or none are enabled */ - 'internal' => [ - 'enabled' => true, - /** + 'internal' => [ + 'enabled' => true, + /** * syncExternally defaults to false - product catalogs can have 1 or more external catalogs linked to them * which will receive changes to the catalogs and optionally allow for external API access. * Will have no effect if true but no external catalogs have been added or none are enabled */ - 'syncExternally' => false, - ], - 'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example) - 'enabled' => false, - ], + 'syncExternally' => false, + ], + 'external' => [ // product catalog settings for external use (as an API server to power an ecommerce site for example) + 'enabled' => false, + ], ]); $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', - ], + '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); @@ -113,15 +112,15 @@ Plugin::getCollection()->add(new CakeProductsPlugin()); Chronos::setTestNow(Chronos::now()); if (!getenv('DB_URL')) { - putenv('DB_URL=sqlite:///:memory:'); + putenv('DB_URL=sqlite:///:memory:'); } ConnectionManager::setConfig('test', [ - 'className' => Connection::class, - 'url' => getenv('DB_URL') ?: null, - 'timezone' => 'UTC', - 'quoteIdentifiers' => false, - 'cacheMetadata' => true, + 'className' => Connection::class, + 'url' => getenv('DB_URL') ?: null, + 'timezone' => 'UTC', + 'quoteIdentifiers' => false, + 'cacheMetadata' => true, ]); /** diff --git a/tests/schema.php b/tests/schema.php index d38e179..5319ee6 100644 --- a/tests/schema.php +++ b/tests/schema.php @@ -1,4 +1,5 @@