subscribtion category variants / system category variants

This commit is contained in:
2025-11-04 01:50:05 -08:00
parent 868f9dbcce
commit a471be8ff9
13 changed files with 254 additions and 12 deletions

View File

@@ -56,6 +56,43 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
'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();
}

View File

@@ -18,17 +18,34 @@ class ProductCategoryVariantsFixture extends TestFixture
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' => 1,
'enabled' => true,
'is_system_variant' => false,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'name' => 'AWG',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'enabled' => 1,
'enabled' => true,
'is_system_variant' => false,
],
];
parent::init();

View File

@@ -37,6 +37,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
*/
protected array $fixtures = [
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
'plugin.CakeProducts.ProductVariants',
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.Products',
@@ -289,6 +290,77 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
// 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
*
* @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();
// $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);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-category-variants');
$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($before->name, $after->name);
$this->assertNull($after->product_category_id);
$this->assertTrue($after->enabled);
// assert saved properly below
}
/**
* Test edit method
*
@@ -312,7 +384,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
];
$data = [
'name' => '',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_category_id' => 'NOT A VALID ID',
'enabled' => true,
];
$this->put($url, $data);