product photos controller test fixes, test out

This commit is contained in:
2025-08-11 23:35:46 -07:00
parent 3a47f09e8c
commit 0181c48907
3 changed files with 50 additions and 32 deletions

View File

@@ -3,31 +3,38 @@ declare(strict_types=1);
namespace CakeProducts\Model\Table;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Association\BelongsTo;
use Cake\ORM\Behavior\TimestampBehavior;
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use CakeProducts\Model\Entity\ProductPhoto;
use Closure;
use Psr\SimpleCache\CacheInterface;
/**
* ProductPhotos Model
*
* @property \CakeProducts\Model\Table\ProductsTable&\Cake\ORM\Association\BelongsTo $Products
* @property ProductsTable&BelongsTo $Products
*
* @method \CakeProducts\Model\Entity\ProductPhoto newEmptyEntity()
* @method \CakeProducts\Model\Entity\ProductPhoto newEntity(array $data, array $options = [])
* @method array<\CakeProducts\Model\Entity\ProductPhoto> newEntities(array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', \Psr\SimpleCache\CacheInterface|string|null $cache = null, \Closure|string|null $cacheKey = null, mixed ...$args)
* @method \CakeProducts\Model\Entity\ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method array<\CakeProducts\Model\Entity\ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto|false save(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method \CakeProducts\Model\Entity\ProductPhoto saveOrFail(\Cake\Datasource\EntityInterface $entity, array $options = [])
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false saveMany(iterable $entities, array $options = [])
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<\CakeProducts\Model\Entity\ProductPhoto>|\Cake\Datasource\ResultSetInterface<\CakeProducts\Model\Entity\ProductPhoto> deleteManyOrFail(iterable $entities, array $options = [])
* @method ProductPhoto newEmptyEntity()
* @method ProductPhoto newEntity(array $data, array $options = [])
* @method array<ProductPhoto> newEntities(array $data, array $options = [])
* @method ProductPhoto get(mixed $primaryKey, array|string $finder = 'all', CacheInterface|string|null $cache = null, Closure|string|null $cacheKey = null, mixed ...$args)
* @method ProductPhoto findOrCreate($search, ?callable $callback = null, array $options = [])
* @method ProductPhoto patchEntity(EntityInterface $entity, array $data, array $options = [])
* @method array<ProductPhoto> patchEntities(iterable $entities, array $data, array $options = [])
* @method ProductPhoto|false save(EntityInterface $entity, array $options = [])
* @method ProductPhoto saveOrFail(EntityInterface $entity, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false saveMany(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> saveManyOrFail(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto>|false deleteMany(iterable $entities, array $options = [])
* @method iterable<ProductPhoto>|ResultSetInterface<ProductPhoto> deleteManyOrFail(iterable $entities, array $options = [])
*
* @mixin \Cake\ORM\Behavior\TimestampBehavior
* @mixin TimestampBehavior
*/
class ProductPhotosTable extends Table
{
@@ -52,13 +59,19 @@ class ProductPhotosTable extends Table
'joinType' => 'INNER',
'className' => 'CakeProducts.Products',
]);
$this->belongsTo('ProductSkus', [
'foreignKey' => 'product_sku_id',
'joinType' => 'LEFT',
'className' => 'CakeProducts.ProductSkus',
]);
}
/**
* Default validation rules.
*
* @param \Cake\Validation\Validator $validator Validator instance.
* @return \Cake\Validation\Validator
* @param Validator $validator Validator instance.
* @return Validator
*/
public function validationDefault(Validator $validator): Validator
{
@@ -68,8 +81,7 @@ class ProductPhotosTable extends Table
$validator
->uuid('product_sku_id')
->allowEmptyString('product_sku_id')
->add('product_sku_id', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
->allowEmptyString('product_sku_id');
$validator
->scalar('photo_dir')
@@ -106,13 +118,13 @@ class ProductPhotosTable extends Table
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
* @param RulesChecker $rules The rules object to be modified.
* @return RulesChecker
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['product_sku_id'], ['allowMultipleNulls' => true]), ['errorField' => '0']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => '1']);
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
$rules->add($rules->existsIn(['product_sku_id'], 'ProductSkus'), ['errorField' => 'product_sku_id']);
return $rules;
}