variant options coming along - add test passing

This commit is contained in:
2025-07-05 20:48:40 -07:00
parent 5adc791c20
commit 59a38758e9
11 changed files with 110 additions and 24 deletions

View File

@@ -19,8 +19,8 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
{
$this->records = [
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'variant_value' => 'Color',
'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',
@@ -28,8 +28,8 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'variant_value' => 'Size',
'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',

View File

@@ -21,18 +21,17 @@ class ProductCategoryVariantsFixture extends TestFixture
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
'name' => 'Color',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_id' => null,
'enabled' => 1,
],
[
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
'name' => 'Color',
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
'enabled' => 1,
],
];
parent::init();
}

View File

@@ -6,6 +6,7 @@ namespace CakeProducts\Test\TestCase\Controller;
use CakeProducts\Controller\ProductCategoryVariantsController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
use PHPUnit\Exception;
@@ -22,6 +23,13 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
* @var ProductCategoryVariantsTable|Table
*/
protected $ProductCategoryVariants;
/**
* Test subject
*
* @var ProductCategoryVariantOptionsTable|Table
*/
protected $ProductCategoryVariantOptions;
/**
* Fixtures
*
@@ -42,6 +50,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
{
parent::setUp();
$this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants');
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions');
}
/**
@@ -52,6 +61,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
protected function tearDown(): void
{
unset($this->ProductCategoryVariants);
unset($this->ProductCategoryVariantOptions);
parent::tearDown();
}
@@ -142,6 +152,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
public function testAddPostLoggedInSuccess(): void
{
$cntBefore = $this->ProductCategoryVariants->find()->count();
$cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count();
$this->loginUserByRole('admin');
$url = [
@@ -152,14 +163,29 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
$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);
}
/**

View File

@@ -24,8 +24,8 @@ class ProductCategoryVariantOptionsTableTest extends TestCase
* @var array<string>
*/
protected array $fixtures = [
// 'ProductCategoryVariantOptions',
// 'ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariants',
'plugin.CakeProducts.ProductCategoryVariantOptions',
];
/**