product variants table split off from category variants table, variant values table updated to reflect

This commit is contained in:
2025-10-03 02:16:24 -07:00
parent d49a8784e6
commit 49912abd3a
21 changed files with 477 additions and 46 deletions

View File

@@ -36,9 +36,11 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
'modified' => '2025-07-04 12:00:00',
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d25',
'variant_value' => 'Blue',
'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',
@@ -46,8 +48,8 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d26',
'variant_value' => 'Red',
'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',

View File

@@ -22,14 +22,12 @@ class ProductCategoryVariantsFixture extends TestFixture
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'name' => 'Color',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_id' => null,
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'name' => 'Color',
'name' => 'AWG',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'enabled' => 1,
],
];

View File

@@ -28,7 +28,7 @@ class ProductSkuVariantValuesFixture extends TestFixture
[
'id' => '98b609d8-1d4f-484c-a13a-6adb7102da56',
'product_sku_id' => '3a477e3e-7977-4813-81f6-f85949613979',
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72569',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
],
];

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductVariantsFixture
*/
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();
}
}

View File

@@ -25,6 +25,13 @@ class ProductsFixture extends TestFixture
'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();
}

View File

@@ -37,6 +37,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductSkus',
@@ -51,6 +52,8 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
protected function setUp(): void
{
parent::setUp();
$this->disableErrorHandlerMiddleware();
$config = $this->getTableLocator()->exists('ProductCategoryVariants') ? [] : ['className' => ProductCategoryVariantsTable::class];
$this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants', $config);

View File

@@ -42,6 +42,10 @@ class ProductSkusControllerTest extends BaseControllerTest
'plugin.CakeProducts.ProductSkus',
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductSkuVariantValues',
];
/**
@@ -173,15 +177,14 @@ class ProductSkusControllerTest extends BaseControllerTest
];
$data = [
0 => [
'add' => '1',
'sku' => 'cfc98a9a-29b2-44c8-b587-8156a',
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156a',
'price' => 1.5,
'cost' => 1.5,
'product_sku_variant_values' => [
0 => [
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d26',
'product_variant_id' => '2e6e4031-c430-4d07-b8d6-a4e759b72568',
'product_category_variant_option_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
],
],
],

View File

@@ -0,0 +1,108 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\TestCase\Model\Table;
use CakeProducts\Model\Table\ProductVariantsTable;
use Cake\TestSuite\TestCase;
/**
* CakeProducts\Model\Table\ProductVariantsTable Test Case
*/
class ProductVariantsTableTest extends TestCase
{
/**
* Test subject
*
* @var \App\Model\Table\ProductVariantsTable
*/
protected $ProductVariants;
/**
* Fixtures
*
* @var array<string>
*/
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);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->ProductVariants);
parent::tearDown();
}
/**
* TestInitialize method
*
* @return void
* @uses \App\Model\Table\ProductVariantsTable::initialize()
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'Products',
'ProductCategoryVariants',
'ProductCategoryVariantOptions',
];
$associations = $this->ProductVariants->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->ProductVariants->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [];
$behaviors = $this->ProductVariants->behaviors();
$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()
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test buildRules method
*
* @return void
* @uses \App\Model\Table\ProductVariantsTable::buildRules()
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@@ -64,8 +64,10 @@ class ProductsTableTest extends TestCase
$expectedAssociations = [
'ProductCategories',
'ProductAttributes',
'ProductCategoryVariants',
'ProductVariants',
'ProductSkus',
'ProductPhotos',
'PrimaryProductPhotos',
];
$associations = $this->Products->associations();