product skus v1
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
4868064c44
commit
a01805dc53
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateProductSkus extends BaseMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* More information on this method is available here:
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table('product_skus', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('product_id', 'uuid', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('sku', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('barcode', 'string', [
|
||||
'default' => null,
|
||||
'limit' => 255,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('price', 'decimal', [
|
||||
'default' => null,
|
||||
'precision' => 15,
|
||||
'scale' => 6,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('cost', 'decimal', [
|
||||
'default' => null,
|
||||
'precision' => 15,
|
||||
'scale' => 6,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('created', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => false,
|
||||
]);
|
||||
$table->addColumn('modified', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->addColumn('deleted', 'datetime', [
|
||||
'default' => null,
|
||||
'null' => true,
|
||||
]);
|
||||
$table->create();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Controller;
|
||||
|
||||
use Cake\Log\Log;
|
||||
use CakeProducts\Controller\AppController;
|
||||
use CheeseCake\Controller\Traits\OverrideTableTrait;
|
||||
|
||||
/**
|
||||
* ProductSkus Controller
|
||||
*
|
||||
* @property \CakeProducts\Model\Table\ProductSkusTable $ProductSkus
|
||||
*/
|
||||
class ProductSkusController extends AppController
|
||||
{
|
||||
use OverrideTableTrait;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
// $this->_defaultTable = 'CakeProducts.ProductSkus';
|
||||
// $this->_tableConfigKey = 'CakeProducts.ProductSkus.table';
|
||||
}
|
||||
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->ProductSkus->find()
|
||||
->contain(['Products']);
|
||||
$productSkus = $this->paginate($query);
|
||||
|
||||
$this->set(compact('productSkus'));
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$productSku = $this->ProductSkus->get($id, contain: ['Products']);
|
||||
$this->set(compact('productSku'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$productSku = $this->ProductSkus->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
// Log::debug(print_r('$postData', true));
|
||||
// Log::debug(print_r($postData, true));
|
||||
// Log::debug(print_r('$saveOptions', true));
|
||||
// Log::debug(print_r($saveOptions, true));
|
||||
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
|
||||
if ($this->ProductSkus->save($productSku)) {
|
||||
$this->Flash->success(__('The product sku has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/add', true));
|
||||
Log::debug(print_r($productSku->getErrors(), true));
|
||||
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productSku', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$productSku = $this->ProductSkus->get($id, contain: []);
|
||||
if ($this->request->is(['patch', 'post', 'put'])) {
|
||||
$postData = $this->request->getData();
|
||||
$saveOptions = [
|
||||
'associated' => [],
|
||||
];
|
||||
// Log::debug(print_r('$postData', true));
|
||||
// Log::debug(print_r($postData, true));
|
||||
// Log::debug(print_r('$saveOptions', true));
|
||||
// Log::debug(print_r($saveOptions, true));
|
||||
$productSku = $this->ProductSkus->patchEntity($productSku, $postData, $saveOptions);
|
||||
if ($this->ProductSkus->save($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug(print_r('$productSku->getErrors() next - failed in productSkus/edit', true));
|
||||
Log::debug(print_r($productSku->getErrors(), true));
|
||||
$this->Flash->error(__('The product skus could not be saved. Please, try again.'));
|
||||
}
|
||||
$products = $this->ProductSkus->Products->find('list', limit: 200)->all();
|
||||
$this->set(compact('productSku', 'products'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Product Skus id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$productSku = $this->ProductSkus->get($id);
|
||||
if ($this->ProductSkus->delete($productSku)) {
|
||||
$this->Flash->success(__('The product skus has been deleted.'));
|
||||
} else {
|
||||
$this->Flash->error(__('The product skus could not be deleted. Please, try again.'));
|
||||
}
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* ProductSkus Entity
|
||||
*
|
||||
* @property string $id
|
||||
* @property string $product_id
|
||||
* @property string $sku
|
||||
* @property string|null $barcode
|
||||
* @property string|null $price
|
||||
* @property string|null $cost
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $modified
|
||||
* @property \Cake\I18n\DateTime|null $deleted
|
||||
*
|
||||
* @property \App\Model\Entity\Product $product
|
||||
*/
|
||||
class ProductSku extends Entity
|
||||
{
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
* Note that when '*' is set to true, this allows all unspecified fields to
|
||||
* be mass assigned. For security purposes, it is advised to set '*' to false
|
||||
* (or remove it), and explicitly make individual fields accessible as needed.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'product_id' => true,
|
||||
'sku' => true,
|
||||
'barcode' => true,
|
||||
'price' => true,
|
||||
'cost' => true,
|
||||
'created' => true,
|
||||
'modified' => true,
|
||||
'deleted' => true,
|
||||
'product' => false,
|
||||
];
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Model\Table;
|
||||
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Datasource\ResultSetInterface;
|
||||
use Cake\ORM\Association\BelongsTo;
|
||||
use Cake\ORM\Behavior\TimestampBehavior;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeProducts\Model\Entity\ProductSku;
|
||||
use Closure;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
/**
|
||||
* ProductSkus Model
|
||||
*
|
||||
* @property ProductsTable&BelongsTo $Products
|
||||
*
|
||||
* @method ProductSku newEmptyEntity()
|
||||
* @method ProductSku newEntity(array $data, array $options = [])
|
||||
* @method array<ProductSku> newEntities(array $data, array $options = [])
|
||||
* @method ProductSku get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
|
||||
* @method ProductSku findOrCreate($search, ?callable $callback = null, array $options = [])
|
||||
* @method ProductSku patchEntity(EntityInterface $entity, array $data, array $options = [])
|
||||
* @method array<ProductSku> patchEntities(iterable $entities, array $data, array $options = [])
|
||||
* @method ProductSku|false save(EntityInterface $entity, array $options = [])
|
||||
* @method ProductSku saveOrFail(EntityInterface $entity, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false saveMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> saveManyOrFail(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<ProductSku>|ResultSetInterface<ProductSku> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*
|
||||
* @mixin TimestampBehavior
|
||||
*/
|
||||
class ProductSkusTable extends Table
|
||||
{
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('product_skus');
|
||||
$this->setDisplayField('sku');
|
||||
$this->setPrimaryKey('id');
|
||||
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->belongsTo('Products', [
|
||||
'foreignKey' => 'product_id',
|
||||
'joinType' => 'INNER',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default validation rules.
|
||||
*
|
||||
* @param Validator $validator Validator instance.
|
||||
* @return Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->uuid('product_id')
|
||||
->notEmptyString('product_id');
|
||||
|
||||
$validator
|
||||
->scalar('sku')
|
||||
->maxLength('sku', 255)
|
||||
->requirePresence('sku', 'create')
|
||||
->notEmptyString('sku');
|
||||
|
||||
$validator
|
||||
->scalar('barcode')
|
||||
->maxLength('barcode', 255)
|
||||
->allowEmptyString('barcode');
|
||||
|
||||
$validator
|
||||
->decimal('price')
|
||||
->allowEmptyString('price');
|
||||
|
||||
$validator
|
||||
->decimal('cost')
|
||||
->allowEmptyString('cost');
|
||||
|
||||
$validator
|
||||
->dateTime('deleted')
|
||||
->allowEmptyDateTime('deleted');
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a rules checker object that will be used for validating
|
||||
* application integrity.
|
||||
*
|
||||
* @param RulesChecker $rules The rules object to be modified.
|
||||
* @return RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
* @var \Cake\Datasource\EntityInterface $productSku
|
||||
*/
|
||||
?>
|
||||
<div class="row">
|
||||
<aside class="column">
|
||||
<div class="side-nav">
|
||||
<h4 class="heading"><?= __('Actions') ?></h4>
|
||||
<?= $this->Html->link(__('List Product Skus'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="column column-80">
|
||||
<div class="productSkus form content">
|
||||
<?= $this->Form->create($productSku) ?>
|
||||
<fieldset>
|
||||
<legend><?= __('Add Product Sku') ?></legend>
|
||||
<?php
|
||||
echo $this->Form->control('product_id');
|
||||
echo $this->Form->control('sku');
|
||||
echo $this->Form->control('barcode');
|
||||
echo $this->Form->control('price');
|
||||
echo $this->Form->control('cost');
|
||||
echo $this->Form->control('deleted', ['empty' => true]);
|
||||
?>
|
||||
</fieldset>
|
||||
<?= $this->Form->button(__('Submit')) ?>
|
||||
<?= $this->Form->end() ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
* @var \Cake\Datasource\EntityInterface $productSku
|
||||
*/
|
||||
?>
|
||||
<div class="row">
|
||||
<aside class="column">
|
||||
<div class="side-nav">
|
||||
<h4 class="heading"><?= __('Actions') ?></h4>
|
||||
<?= $this->Form->postLink(
|
||||
__('Delete'),
|
||||
['action' => 'delete', $productSku->id],
|
||||
['confirm' => __('Are you sure you want to delete # {0}?', $productSku->id), 'class' => 'side-nav-item']
|
||||
) ?>
|
||||
<?= $this->Html->link(__('List Product Skus'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="column column-80">
|
||||
<div class="productSkus form content">
|
||||
<?= $this->Form->create($productSku) ?>
|
||||
<fieldset>
|
||||
<legend><?= __('Edit Product Skus') ?></legend>
|
||||
<?php
|
||||
echo $this->Form->control('product_id');
|
||||
echo $this->Form->control('sku');
|
||||
echo $this->Form->control('barcode');
|
||||
echo $this->Form->control('price');
|
||||
echo $this->Form->control('cost');
|
||||
?>
|
||||
</fieldset>
|
||||
<?= $this->Form->button(__('Submit')) ?>
|
||||
<?= $this->Form->end() ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
* @var iterable<\Cake\Datasource\EntityInterface> $productSkus
|
||||
*/
|
||||
?>
|
||||
<div class="productSkus index content">
|
||||
<?= $this->Html->link(__('New Product Skus'), ['action' => 'add'], ['class' => 'button float-right']) ?>
|
||||
<h3><?= __('Product Skus') ?></h3>
|
||||
<div class="table-responsive">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= $this->Paginator->sort('id') ?></th>
|
||||
<th><?= $this->Paginator->sort('product_id') ?></th>
|
||||
<th><?= $this->Paginator->sort('sku') ?></th>
|
||||
<th><?= $this->Paginator->sort('barcode') ?></th>
|
||||
<th><?= $this->Paginator->sort('price') ?></th>
|
||||
<th><?= $this->Paginator->sort('cost') ?></th>
|
||||
<th><?= $this->Paginator->sort('created') ?></th>
|
||||
<th><?= $this->Paginator->sort('modified') ?></th>
|
||||
<th><?= $this->Paginator->sort('deleted') ?></th>
|
||||
<th class="actions"><?= __('Actions') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($productSkus as $productSku): ?>
|
||||
<tr>
|
||||
<td><?= h($productSku->id) ?></td>
|
||||
<td><?= h($productSku->product_id) ?></td>
|
||||
<td><?= h($productSku->sku) ?></td>
|
||||
<td><?= h($productSku->barcode) ?></td>
|
||||
<td><?= $productSku->price === null ? '' : $this->Number->format($productSku->price) ?></td>
|
||||
<td><?= $productSku->cost === null ? '' : $this->Number->format($productSku->cost) ?></td>
|
||||
<td><?= h($productSku->created) ?></td>
|
||||
<td><?= h($productSku->modified) ?></td>
|
||||
<td><?= h($productSku->deleted) ?></td>
|
||||
<td class="actions">
|
||||
<?= $this->Html->link(__('View'), ['action' => 'view', $productSku->id]) ?>
|
||||
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $productSku->id]) ?>
|
||||
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $productSku->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productSku->id)]) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="paginator">
|
||||
<ul class="pagination">
|
||||
<?= $this->Paginator->first('<< ' . __('first')) ?>
|
||||
<?= $this->Paginator->prev('< ' . __('previous')) ?>
|
||||
<?= $this->Paginator->numbers() ?>
|
||||
<?= $this->Paginator->next(__('next') . ' >') ?>
|
||||
<?= $this->Paginator->last(__('last') . ' >>') ?>
|
||||
</ul>
|
||||
<p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
* @var \Cake\Datasource\EntityInterface $productSku
|
||||
*/
|
||||
?>
|
||||
<div class="row">
|
||||
<aside class="column">
|
||||
<div class="side-nav">
|
||||
<h4 class="heading"><?= __('Actions') ?></h4>
|
||||
<?= $this->Html->link(__('Edit Product Skus'), ['action' => 'edit', $productSku->id], ['class' => 'side-nav-item']) ?>
|
||||
<?= $this->Form->postLink(__('Delete Product Skus'), ['action' => 'delete', $productSku->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productSku->id), 'class' => 'side-nav-item']) ?>
|
||||
<?= $this->Html->link(__('List Product Skus'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
|
||||
<?= $this->Html->link(__('New Product Skus'), ['action' => 'add'], ['class' => 'side-nav-item']) ?>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="column column-80">
|
||||
<div class="productSkus view content">
|
||||
<h3><?= h($productSku->sku) ?></h3>
|
||||
<table>
|
||||
<tr>
|
||||
<th><?= __('Id') ?></th>
|
||||
<td><?= h($productSku->id) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Product Id') ?></th>
|
||||
<td><?= h($productSku->product_id) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Sku') ?></th>
|
||||
<td><?= h($productSku->sku) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Barcode') ?></th>
|
||||
<td><?= h($productSku->barcode) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Price') ?></th>
|
||||
<td><?= $productSku->price === null ? '' : $this->Number->format($productSku->price) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Cost') ?></th>
|
||||
<td><?= $productSku->cost === null ? '' : $this->Number->format($productSku->cost) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Created') ?></th>
|
||||
<td><?= h($productSku->created) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Modified') ?></th>
|
||||
<td><?= h($productSku->modified) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= __('Deleted') ?></th>
|
||||
<td><?= h($productSku->deleted) ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\Fixture;
|
||||
|
||||
use Cake\TestSuite\Fixture\TestFixture;
|
||||
|
||||
/**
|
||||
* ProductSkusFixture
|
||||
*/
|
||||
class ProductSkusFixture extends TestFixture
|
||||
{
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public string $table = 'product_skus';
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'sku' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'barcode' => '3a477e3e-7977-4813-81f6-f85949613979',
|
||||
'price' => 1.5,
|
||||
'cost' => 1.5,
|
||||
'created' => '2025-04-15 09:09:15',
|
||||
'modified' => '2025-04-15 09:09:15',
|
||||
'deleted' => null,
|
||||
],
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,326 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CakeProducts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\ORM\Table;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Controller\ProductSkusController;
|
||||
use CakeProducts\Model\Table\ProductSkusTable;
|
||||
use CakeProducts\Model\Table\ProductsTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
/**
|
||||
* App\Controller\ProductSkusController Test Case
|
||||
*
|
||||
* @uses \CakeProducts\Controller\ProductSkusController
|
||||
*/
|
||||
class ProductSkusControllerTest extends BaseControllerTest
|
||||
{
|
||||
/**
|
||||
* Test subject table
|
||||
*
|
||||
* @var ProductSkusTable|Table
|
||||
*/
|
||||
protected $ProductSkus;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
'plugin.CakeProducts.ProductSkus',
|
||||
'plugin.CakeProducts.Products',
|
||||
'plugin.CakeProducts.ProductAttributes',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
// $this->enableCsrfToken();
|
||||
// $this->enableSecurityToken();
|
||||
$config = $this->getTableLocator()->exists('ProductSkus') ? [] : ['className' => ProductSkusTable::class];
|
||||
$this->ProductSkus = $this->getTableLocator()->get('ProductSkus', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductSkus);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* Tests the index action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::index()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndexGet(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'index',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* Tests the view action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::view()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testViewGet(): void
|
||||
{
|
||||
$id = '3a477e3e-7977-4813-81f6-f85949613979';
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'view',
|
||||
$id,
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests the add action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddGet(): void
|
||||
{
|
||||
$cntBefore = $this->ProductSkus->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'add',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductSkus->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ProductSkus->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'sku' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'price' => 1.5,
|
||||
'cost' => 1.5,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-skus');
|
||||
|
||||
$cntAfter = $this->ProductSkus->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* Tests a POST request to the add action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::add()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddPostFailure(): void
|
||||
{
|
||||
$cntBefore = $this->ProductSkus->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'add',
|
||||
];
|
||||
$data = [
|
||||
'product_id' => '999999999', //does not exist
|
||||
'sku' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'price' => 1.5,
|
||||
'cost' => 1.5,
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
|
||||
$cntAfter = $this->ProductSkus->find()->count();
|
||||
$this->assertEquals($cntBefore, $cntAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests the edit action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditGet(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'edit',
|
||||
'3a477e3e-7977-4813-81f6-f85949613979',
|
||||
];
|
||||
$this->get($url);
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutSuccess(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '3a477e3e-7977-4813-81f6-f85949613979';
|
||||
$before = $this->ProductSkus->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
// test new data here
|
||||
];
|
||||
$this->put($url, $data);
|
||||
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-skus');
|
||||
|
||||
$after = $this->ProductSkus->get($id);
|
||||
// assert saved properly below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* Tests a PUT request to the edit action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::edit()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEditPutFailure(): void
|
||||
{
|
||||
$this->loginUserByRole('admin');
|
||||
$id = '3a477e3e-7977-4813-81f6-f85949613979';
|
||||
$before = $this->ProductSkus->get($id);
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'edit',
|
||||
$id,
|
||||
];
|
||||
$data = [
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'sku' => '',
|
||||
'barcode' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'price' => 1.5,
|
||||
'cost' => 1.5,
|
||||
];
|
||||
$this->put($url, $data);
|
||||
$this->assertResponseCode(200);
|
||||
$after = $this->ProductSkus->get($id);
|
||||
|
||||
// assert save failed below
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* Tests the delete action with a logged in user
|
||||
*
|
||||
* @uses \App\Controller\ProductSkusController::delete()
|
||||
* @throws Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$cntBefore = $this->ProductSkus->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
'plugin' => 'CakeProducts',
|
||||
'controller' => 'ProductSkus',
|
||||
'action' => 'delete',
|
||||
'3a477e3e-7977-4813-81f6-f85949613979',
|
||||
];
|
||||
$this->delete($url);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-skus');
|
||||
|
||||
$cntAfter = $this->ProductSkus->find()->count();
|
||||
$this->assertEquals($cntBefore - 1, $cntAfter);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue