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

@@ -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);