From b9bf47f38572b43e009c1add4232a8ff5eb5c29c Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Thu, 21 Aug 2025 22:43:06 -0700 Subject: [PATCH] variants controller tests failing --- .../ProductCategoryVariantsController.php | 6 +++- src/Controller/ProductPhotosController.php | 31 +++++++++++-------- src/Model/Table/ProductPhotosTable.php | 1 - .../ProductCategoryVariantsControllerTest.php | 20 ++++++------ 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/Controller/ProductCategoryVariantsController.php b/src/Controller/ProductCategoryVariantsController.php index 1615bf6..beb6843 100644 --- a/src/Controller/ProductCategoryVariantsController.php +++ b/src/Controller/ProductCategoryVariantsController.php @@ -52,7 +52,11 @@ class ProductCategoryVariantsController extends AppController */ public function view($id = null) { - $productCategoryVariant = $this->getTable()->get($id, contain: ['ProductCategories', 'Products', 'ProductCategoryVariantOptions']); + $productCategoryVariant = $this->getTable()->get($id, contain: [ + 'ProductCategories', + 'Products', + 'ProductCategoryVariantOptions', + ]); $this->set(compact('productCategoryVariant')); } diff --git a/src/Controller/ProductPhotosController.php b/src/Controller/ProductPhotosController.php index 1d929f9..48eb315 100644 --- a/src/Controller/ProductPhotosController.php +++ b/src/Controller/ProductPhotosController.php @@ -4,16 +4,19 @@ declare(strict_types=1); namespace CakeProducts\Controller; use Cake\Core\Configure; +use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Http\Exception\ForbiddenException; +use Cake\Http\Response; use Cake\Utility\Text; use CakeProducts\Controller\AppController; +use CakeProducts\Model\Table\ProductPhotosTable; use CheeseCake\Controller\Traits\OverrideTableTrait; use Psr\Http\Message\UploadedFileInterface; /** * ProductPhotos Controller * - * @property \CakeProducts\Model\Table\ProductPhotosTable $ProductPhotos + * @property ProductPhotosTable $ProductPhotos */ class ProductPhotosController extends AppController { @@ -22,12 +25,12 @@ class ProductPhotosController extends AppController /** * Index method * - * @return \Cake\Http\Response|null|void Renders view + * @return Response|null|void Renders view */ public function index() { $query = $this->getTable()->find() - ->contain(['Products']); + ->contain(['Products', 'ProductSkus']); $productPhotos = $this->paginate($query); $this->set(compact('productPhotos')); @@ -37,19 +40,19 @@ class ProductPhotosController extends AppController * View method * * @param string|null $id Product Photo id. - * @return \Cake\Http\Response|null|void Renders view - * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return Response|null|void Renders view + * @throws RecordNotFoundException When record not found. */ public function view($id = null) { - $productPhoto = $this->getTable()->get($id, contain: ['Products']); + $productPhoto = $this->getTable()->get($id, contain: ['Products', 'ProductSkus']); $this->set(compact('productPhoto')); } /** * Add method * - * @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. + * @return Response|null|void Redirects on successful add, renders view otherwise. */ public function add() { @@ -101,16 +104,17 @@ class ProductPhotosController extends AppController $this->Flash->error(__('The product photo could not be saved. Please, try again.')); } $products = $productPhotosTable->Products->find('list', limit: 200)->all(); + $productSkus = $productPhotosTable->Products->ProductSkus->find('list', limit: 200)->all(); - $this->set(compact('productPhoto', 'products')); + $this->set(compact('productPhoto', 'products', 'productSkus')); } /** * Edit method * * @param string|null $id Product Photo id. - * @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise. - * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return Response|null|void Redirects on successful edit, renders view otherwise. + * @throws RecordNotFoundException When record not found. */ public function edit($id = null) { @@ -128,15 +132,16 @@ class ProductPhotosController extends AppController $this->Flash->error(__('The product photo could not be saved. Please, try again.')); } $products = $productPhotosTable->Products->find('list', limit: 200)->all(); - $this->set(compact('productPhoto', 'products')); + $productSkus = $productPhotosTable->Products->ProductSkus->find('list', limit: 200)->all(); + $this->set(compact('productPhoto', 'products', 'productSkus')); } /** * Delete method * * @param string|null $id Product Photo id. - * @return \Cake\Http\Response|null Redirects to index. - * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + * @return Response|null Redirects to index. + * @throws RecordNotFoundException When record not found. */ public function delete($id = null) { diff --git a/src/Model/Table/ProductPhotosTable.php b/src/Model/Table/ProductPhotosTable.php index 254e655..57c5b40 100644 --- a/src/Model/Table/ProductPhotosTable.php +++ b/src/Model/Table/ProductPhotosTable.php @@ -7,7 +7,6 @@ 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; diff --git a/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php b/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php index a192828..5974889 100644 --- a/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php +++ b/tests/TestCase/Controller/ProductCategoryVariantsControllerTest.php @@ -39,6 +39,8 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest 'plugin.CakeProducts.ProductCategoryVariants', 'plugin.CakeProducts.ProductCategories', 'plugin.CakeProducts.Products', + 'plugin.CakeProducts.ProductSkus', + 'plugin.CakeProducts.ProductPhotos', ]; /** @@ -78,7 +80,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest */ public function testIndexGet(): void { - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants', @@ -101,7 +103,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest public function testViewGet(): void { $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants', @@ -126,7 +128,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest { $cntBefore = $this->ProductCategoryVariants->find()->count(); - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants', @@ -154,7 +156,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest $cntBefore = $this->ProductCategoryVariants->find()->count(); $cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count(); - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants', @@ -202,7 +204,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest { $cntBefore = $this->ProductCategoryVariants->find()->count(); - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $url = [ 'plugin' => 'CakeProducts', 'controller' => 'ProductCategoryVariants', @@ -232,7 +234,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest */ public function testEditGet(): void { - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; $url = [ @@ -257,7 +259,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest */ public function testEditPutLoggedInSuccess(): void { - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; $before = $this->ProductCategoryVariants->get($id); $url = [ @@ -293,7 +295,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest */ public function testEditPutLoggedInFailure(): void { - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; $before = $this->ProductCategoryVariants->get($id); $url = [ @@ -328,7 +330,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest { $cntBefore = $this->ProductCategoryVariants->find()->count(); - $this->loginUserByRole('admin'); + //$this->loginUserByRole('admin'); $id = '5a386e9f-6e7a-4ae7-9360-c8e529f78d93'; $url = [