product attributes

This commit is contained in:
2025-04-05 02:06:23 -07:00
parent 4e6b7ca1ac
commit bb1dab1f43
12 changed files with 319 additions and 12 deletions

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace CakeProducts\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* ProductAttributesFixture
*/
class ProductAttributesFixture extends TestFixture
{
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
];
parent::init();
}
}

View File

@@ -21,10 +21,24 @@ class ProductCategoryAttributeOptionsFixture extends TestFixture
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a8',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Lorem ipsum dolor sit amet',
'attribute_label' => 'Lorem ipsum dolor sit amet',
'attribute_value' => 'Red',
'attribute_label' => 'Red',
'enabled' => 1,
],
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a1',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Blue',
'attribute_label' => 'Blue',
'enabled' => 1,
],
[
'id' => 'e06f1723-2456-483a-b3c4-004603e032a2',
'product_category_attribute_id' => '37078cf0-0130-4b93-bb7e-abe7d665ed2c',
'attribute_value' => 'Green',
'attribute_label' => 'Green',
'enabled' => 1,
]
];
parent::init();
}

View File

@@ -32,7 +32,10 @@ class ProductsControllerTest extends BaseControllerTest
*/
protected array $fixtures = [
'plugin.CakeProducts.Products',
'plugin.CakeProducts.ProductAttributes',
'plugin.CakeProducts.ProductCategories',
'plugin.CakeProducts.ProductCategoryAttributes',
'plugin.CakeProducts.ProductCategoryAttributeOptions',
// 'plugin.CakeProducts.ProductCatalogs',
];
@@ -135,6 +138,52 @@ class ProductsControllerTest extends BaseControllerTest
$this->assertEquals($cntBefore, $cntAfter);
}
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @return void
* @throws Exception
*
* @uses ProductsController::add
*/
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');
$cntAfter = $this->Products->find()->count();
$productAttributesCntAfter = $this->Products->ProductAttributes->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
$this->assertEquals($productAttributesCntBefore + 1, $productAttributesCntAfter);
}
/**
* Test add method
*
@@ -160,6 +209,7 @@ class ProductsControllerTest extends BaseControllerTest
'product_category_id' => '',
'name' => '',
'product_type_id' => 1,
'product_attributes' => [],
];
$this->post($url, $data);
$this->assertResponseCode(200);

View File

@@ -63,6 +63,7 @@ class ProductsTableTest extends TestCase
// verify all associations loaded
$expectedAssociations = [
'ProductCategories',
'ProductAttributes',
];
$associations = $this->Products->associations();