test additions variants table
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s
Details
CI / Coding Standard & Static Analysis (push) Failing after 0s
Details
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s
Details
CI / Coding Standard & Static Analysis (push) Failing after 0s
Details
This commit is contained in:
parent
5bb1110e7f
commit
5cba7de890
|
@ -32,7 +32,7 @@ class CreateProductCategoryVariants extends AbstractMigration
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'null' => true,
|
'null' => true,
|
||||||
]);
|
]);
|
||||||
$table->addColumn('attribute_type_id', 'integer', [
|
$table->addColumn('variant_type_id', 'integer', [
|
||||||
'default' => null,
|
'default' => null,
|
||||||
'limit' => 11,
|
'limit' => 11,
|
||||||
'null' => false,
|
'null' => false,
|
||||||
|
@ -44,20 +44,21 @@ class CreateProductCategoryVariants extends AbstractMigration
|
||||||
$table->addIndex([
|
$table->addIndex([
|
||||||
'product_category_id',
|
'product_category_id',
|
||||||
], [
|
], [
|
||||||
'name' => 'BY_PRODUCT_CATEGORY_ID',
|
'name' => 'VARIANTS_BY_PRODUCT_CATEGORY_ID',
|
||||||
'unique' => false,
|
'unique' => false,
|
||||||
]);
|
]);
|
||||||
$table->addIndex([
|
$table->addIndex([
|
||||||
'product_id',
|
'product_id',
|
||||||
], [
|
], [
|
||||||
'name' => 'BY_PRODUCT_ID',
|
'name' => 'VARIANTS_BY_PRODUCT_ID',
|
||||||
'unique' => false,
|
'unique' => false,
|
||||||
]);
|
]);
|
||||||
$table->addIndex([
|
$table->addIndex([
|
||||||
'name',
|
'name',
|
||||||
'product_category_id',
|
'product_category_id',
|
||||||
|
'product_id',
|
||||||
], [
|
], [
|
||||||
'name' => 'BY_NAME_AND_PRODUCT_CATEGORY_ID_UNIQUE',
|
'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
]);
|
]);
|
||||||
$table->create();
|
$table->create();
|
||||||
|
|
|
@ -12,7 +12,7 @@ use Cake\ORM\Entity;
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string|null $product_category_id
|
* @property string|null $product_category_id
|
||||||
* @property string|null $product_id
|
* @property string|null $product_id
|
||||||
* @property int $attribute_type_id
|
* @property int $variant_type_id
|
||||||
* @property bool $enabled
|
* @property bool $enabled
|
||||||
*
|
*
|
||||||
* @property \App\Model\Entity\ProductCategory $product_category
|
* @property \App\Model\Entity\ProductCategory $product_category
|
||||||
|
@ -33,7 +33,7 @@ class ProductCategoryVariant extends Entity
|
||||||
'name' => true,
|
'name' => true,
|
||||||
'product_category_id' => true,
|
'product_category_id' => true,
|
||||||
'product_id' => true,
|
'product_id' => true,
|
||||||
'attribute_type_id' => true,
|
'variant_type_id' => true,
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'product_category' => true,
|
'product_category' => true,
|
||||||
'product' => true,
|
'product' => true,
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
namespace CakeProducts\Model\Enum;
|
||||||
|
|
||||||
|
use Cake\Database\Type\EnumLabelInterface;
|
||||||
|
use Tools\Model\Enum\EnumOptionsTrait;
|
||||||
|
|
||||||
|
enum ProductCategoryVariantTypeId: int implements EnumLabelInterface
|
||||||
|
{
|
||||||
|
use EnumOptionsTrait;
|
||||||
|
|
||||||
|
case AutoAdd = 1;
|
||||||
|
case ManualAdd = 2;
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match($this) {
|
||||||
|
self::AutoAdd => 'All Variant Combinations Created Automatically',
|
||||||
|
self::ManualAdd => 'Variants Manually Managed',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace CakeProducts\Model\Table;
|
namespace CakeProducts\Model\Table;
|
||||||
|
|
||||||
|
use Cake\Database\Type\EnumType;
|
||||||
use Cake\ORM\Query\SelectQuery;
|
use Cake\ORM\Query\SelectQuery;
|
||||||
use Cake\ORM\RulesChecker;
|
use Cake\ORM\RulesChecker;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
use Cake\Validation\Validator;
|
use Cake\Validation\Validator;
|
||||||
|
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||||
|
use CakeProducts\Model\Enum\ProductCategoryVariantTypeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductCategoryVariants Model
|
* ProductCategoryVariants Model
|
||||||
|
@ -53,6 +56,8 @@ class ProductCategoryVariantsTable extends Table
|
||||||
'foreignKey' => 'product_id',
|
'foreignKey' => 'product_id',
|
||||||
'className' => 'CakeProducts.Products',
|
'className' => 'CakeProducts.Products',
|
||||||
]);
|
]);
|
||||||
|
$this->getSchema()->setColumnType('variant_type_id', EnumType::from(ProductCategoryVariantTypeId::class));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,9 +83,9 @@ class ProductCategoryVariantsTable extends Table
|
||||||
->allowEmptyString('product_id');
|
->allowEmptyString('product_id');
|
||||||
|
|
||||||
$validator
|
$validator
|
||||||
->integer('attribute_type_id')
|
->integer('variant_type_id')
|
||||||
->requirePresence('attribute_type_id', 'create')
|
->requirePresence('variant_type_id', 'create')
|
||||||
->notEmptyString('attribute_type_id');
|
->notEmptyString('variant_type_id');
|
||||||
|
|
||||||
$validator
|
$validator
|
||||||
->boolean('enabled')
|
->boolean('enabled')
|
||||||
|
|
|
@ -18,13 +18,7 @@
|
||||||
<?= $this->Form->create($productCategoryVariant) ?>
|
<?= $this->Form->create($productCategoryVariant) ?>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><?= __('Add Product Category Variant') ?></legend>
|
<legend><?= __('Add Product Category Variant') ?></legend>
|
||||||
<?php
|
<?= $this->element('ProductCategoryVariants/form'); ?>
|
||||||
echo $this->Form->control('name');
|
|
||||||
echo $this->Form->control('product_category_id', ['options' => $productCategories, 'empty' => true]);
|
|
||||||
echo $this->Form->control('product_id', ['options' => $products, 'empty' => true]);
|
|
||||||
echo $this->Form->control('attribute_type_id');
|
|
||||||
echo $this->Form->control('enabled');
|
|
||||||
?>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<?= $this->Form->button(__('Submit')) ?>
|
<?= $this->Form->button(__('Submit')) ?>
|
||||||
<?= $this->Form->end() ?>
|
<?= $this->Form->end() ?>
|
||||||
|
|
|
@ -23,13 +23,7 @@
|
||||||
<?= $this->Form->create($productCategoryVariant) ?>
|
<?= $this->Form->create($productCategoryVariant) ?>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><?= __('Edit Product Category Variant') ?></legend>
|
<legend><?= __('Edit Product Category Variant') ?></legend>
|
||||||
<?php
|
<?= $this->element('ProductCategoryVariants/form'); ?>
|
||||||
echo $this->Form->control('name');
|
|
||||||
echo $this->Form->control('product_category_id', ['options' => $productCategories, 'empty' => true]);
|
|
||||||
echo $this->Form->control('product_id', ['options' => $products, 'empty' => true]);
|
|
||||||
echo $this->Form->control('attribute_type_id');
|
|
||||||
echo $this->Form->control('enabled');
|
|
||||||
?>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<?= $this->Form->button(__('Submit')) ?>
|
<?= $this->Form->button(__('Submit')) ?>
|
||||||
<?= $this->Form->end() ?>
|
<?= $this->Form->end() ?>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var array $productCategories
|
||||||
|
* @var array $products
|
||||||
|
*/
|
||||||
|
echo $this->Form->control('name');
|
||||||
|
echo $this->Form->control('product_category_id', ['options' => $productCategories, 'empty' => true]);
|
||||||
|
echo $this->Form->control('product_id', ['options' => $products, 'empty' => true]);
|
||||||
|
echo $this->Form->control('attribute_type_id');
|
||||||
|
echo $this->Form->control('enabled');
|
||||||
|
?>
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CakeProducts\Test\Fixture;
|
||||||
|
|
||||||
|
use Cake\TestSuite\Fixture\TestFixture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProductCategoryVariantsFixture
|
||||||
|
*/
|
||||||
|
class ProductCategoryVariantsFixture extends TestFixture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Init method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->records = [
|
||||||
|
[
|
||||||
|
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||||
|
'name' => 'Color',
|
||||||
|
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||||
|
'product_id' => null,
|
||||||
|
'variant_type_id' => 1,
|
||||||
|
'enabled' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||||
|
'name' => 'Color',
|
||||||
|
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||||
|
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||||
|
'variant_type_id' => 1,
|
||||||
|
'enabled' => 1,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
parent::init();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,325 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CakeProducts\Test\TestCase\Controller;
|
||||||
|
|
||||||
|
use CakeProducts\Controller\ProductCategoryVariantsController;
|
||||||
|
use Cake\TestSuite\IntegrationTestTrait;
|
||||||
|
use Cake\TestSuite\TestCase;
|
||||||
|
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
|
||||||
|
use PHPUnit\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CakeProducts\Controller\ProductCategoryVariantsController Test Case
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController
|
||||||
|
*/
|
||||||
|
class ProductCategoryVariantsControllerTest extends BaseControllerTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test subject
|
||||||
|
*
|
||||||
|
* @var ProductCategoryVariantsTable|Table
|
||||||
|
*/
|
||||||
|
protected $ProductCategoryVariants;
|
||||||
|
/**
|
||||||
|
* Fixtures
|
||||||
|
*
|
||||||
|
* @var array<string>
|
||||||
|
*/
|
||||||
|
protected array $fixtures = [
|
||||||
|
'plugin.CakeProducts.ProductCategoryVariants',
|
||||||
|
'plugin.CakeProducts.ProductCategories',
|
||||||
|
'plugin.CakeProducts.Products',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tearDown method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
unset($this->ProductCategoryVariants);
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test index method
|
||||||
|
*
|
||||||
|
* Tests the index action with a logged in user
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::index()
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIndexGet(): void
|
||||||
|
{
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'index',
|
||||||
|
];
|
||||||
|
$this->get($url);
|
||||||
|
$this->assertResponseCode(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test view method
|
||||||
|
*
|
||||||
|
* Tests the view action with a logged in user
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::view()
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testViewGet(): void
|
||||||
|
{
|
||||||
|
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'view',
|
||||||
|
$id,
|
||||||
|
];
|
||||||
|
$this->get($url);
|
||||||
|
$this->assertResponseCode(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test add method
|
||||||
|
*
|
||||||
|
* Tests the add action with a logged in user
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddGet(): void
|
||||||
|
{
|
||||||
|
$cntBefore = $this->ProductCategoryVariants->find()->count();
|
||||||
|
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'add',
|
||||||
|
];
|
||||||
|
$this->get($url);
|
||||||
|
$this->assertResponseCode(200);
|
||||||
|
|
||||||
|
$cntAfter = $this->ProductCategoryVariants->find()->count();
|
||||||
|
$this->assertEquals($cntBefore, $cntAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test add method
|
||||||
|
*
|
||||||
|
* Tests a POST request to the add action with a logged in user
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddPostLoggedInSuccess(): void
|
||||||
|
{
|
||||||
|
$cntBefore = $this->ProductCategoryVariants->find()->count();
|
||||||
|
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'add',
|
||||||
|
];
|
||||||
|
$data = [
|
||||||
|
'name' => 'Size',
|
||||||
|
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||||
|
'variant_type_id' => 1,
|
||||||
|
'enabled' => true,
|
||||||
|
];
|
||||||
|
$this->post($url, $data);
|
||||||
|
$this->assertResponseCode(302);
|
||||||
|
$this->assertRedirectContains('product-category-variants');
|
||||||
|
|
||||||
|
$cntAfter = $this->ProductCategoryVariants->find()->count();
|
||||||
|
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test add method
|
||||||
|
*
|
||||||
|
* Tests a POST request to the add action with a logged in user
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::add()
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAddPostLoggedInFailure(): void
|
||||||
|
{
|
||||||
|
$cntBefore = $this->ProductCategoryVariants->find()->count();
|
||||||
|
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'add',
|
||||||
|
];
|
||||||
|
$data = [
|
||||||
|
'name' => '',
|
||||||
|
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||||
|
'variant_type_id' => 1,
|
||||||
|
'enabled' => true,
|
||||||
|
];
|
||||||
|
$this->post($url, $data);
|
||||||
|
$this->assertResponseCode(200);
|
||||||
|
|
||||||
|
$cntAfter = $this->ProductCategoryVariants->find()->count();
|
||||||
|
$this->assertEquals($cntBefore, $cntAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test edit method
|
||||||
|
*
|
||||||
|
* Tests the edit action with a logged in user
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::edit()
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEditGet(): void
|
||||||
|
{
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
|
||||||
|
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'edit',
|
||||||
|
$id,
|
||||||
|
];
|
||||||
|
$this->get($url);
|
||||||
|
$this->assertResponseCode(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 testEditPutLoggedInSuccess(): void
|
||||||
|
{
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
|
||||||
|
$before = $this->ProductCategoryVariants->get($id);
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'edit',
|
||||||
|
$id,
|
||||||
|
];
|
||||||
|
$data = [
|
||||||
|
// test new data here
|
||||||
|
'name' => 'updated name',
|
||||||
|
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||||
|
'variant_type_id' => 1,
|
||||||
|
'enabled' => true,
|
||||||
|
];
|
||||||
|
$this->put($url, $data);
|
||||||
|
|
||||||
|
$this->assertResponseCode(302);
|
||||||
|
$this->assertRedirectContains('product-category-variants');
|
||||||
|
|
||||||
|
$after = $this->ProductCategoryVariants->get($id);
|
||||||
|
// 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 testEditPutLoggedInFailure(): void
|
||||||
|
{
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
|
||||||
|
$before = $this->ProductCategoryVariants->get($id);
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'edit',
|
||||||
|
$id,
|
||||||
|
];
|
||||||
|
$data = [
|
||||||
|
'name' => '',
|
||||||
|
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||||
|
'variant_type_id' => 1,
|
||||||
|
'enabled' => true,
|
||||||
|
];
|
||||||
|
$this->put($url, $data);
|
||||||
|
$this->assertResponseCode(200);
|
||||||
|
$after = $this->ProductCategoryVariants->get($id);
|
||||||
|
|
||||||
|
// assert save failed below
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test delete method
|
||||||
|
*
|
||||||
|
* Tests the delete action with a logged in user
|
||||||
|
*
|
||||||
|
* @uses \CakeProducts\Controller\ProductCategoryVariantsController::delete()
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDelete(): void
|
||||||
|
{
|
||||||
|
$cntBefore = $this->ProductCategoryVariants->find()->count();
|
||||||
|
|
||||||
|
$this->loginUserByRole('admin');
|
||||||
|
$id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93';
|
||||||
|
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeProducts',
|
||||||
|
'controller' => 'ProductCategoryVariants',
|
||||||
|
'action' => 'delete',
|
||||||
|
$id,
|
||||||
|
];
|
||||||
|
$this->delete($url);
|
||||||
|
$this->assertResponseCode(302);
|
||||||
|
$this->assertRedirectContains('product-category-variants');
|
||||||
|
|
||||||
|
$cntAfter = $this->ProductCategoryVariants->find()->count();
|
||||||
|
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue