more thorogh testing of toggle behavior on product photos
CI / testsuite (mysql, 8.2, ) (push) Waiting to run Details
CI / testsuite (mysql, 8.4, ) (push) Waiting to run Details
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Waiting to run Details
CI / Coding Standard & Static Analysis (push) Waiting to run Details

This commit is contained in:
Brandon Shipley 2025-11-01 17:00:15 -07:00
parent b145e901ef
commit 2041fc78d3
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
1 changed files with 93 additions and 1 deletions

View File

@ -515,10 +515,15 @@ class ProductPhotosControllerTest extends BaseControllerTest
*
* @uses \CakeProducts\Controller\ProductPhotosController::delete
*/
public function testDeleteLoggedIn(): void
public function testDeleteLoggedInDefaultProductPhoto(): void
{
$cntBefore = $this->ProductPhotos->find()->count();
$id = '2c386086-f4c5-4093-bea5-ee9c29479f58';
$productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->first();
$primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->count();
$this->assertEquals(1, $primaryPhotosBeforeCnt);
// $this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
@ -532,6 +537,93 @@ class ProductPhotosControllerTest extends BaseControllerTest
$cntAfter = $this->ProductPhotos->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
$primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->first();
$primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_photo' => true, 'product_id' => $productId])->count();
$this->assertEquals(1, $primaryPhotosAfterCnt);
$this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id);
}
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductPhotosController::delete
*/
public function testDeleteLoggedInDefaultCategoryPhoto(): void
{
$cntBefore = $this->ProductPhotos->find()->count();
$id = '2c386086-f4c5-4093-bea5-ee9c29479f51';
$productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$categoryId = '6d223283-361b-4f9f-a7f1-c97aa0ca4c23';
$primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->first();
$primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->count();
$this->assertEquals(1, $primaryPhotosBeforeCnt);
// $this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductPhotos',
'action' => 'delete',
$id,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-photos');
$cntAfter = $this->ProductPhotos->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
$primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->first();
$primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_category_photo' => true, 'product_category_id' => $categoryId])->count();
$this->assertEquals(1, $primaryPhotosAfterCnt);
$this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id);
}
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @return void
* @throws Exception
*
* @uses \CakeProducts\Controller\ProductPhotosController::delete
*/
public function testDeleteLoggedInDefaultSkuPhoto(): void
{
$cntBefore = $this->ProductPhotos->find()->count();
$id = '2c386086-f4c5-4093-bea5-ee9c29479f11';
$productId = 'cfc98a9a-29b2-44c8-b587-8156adc05317';
$skuId = '3a477e3e-7977-4813-81f6-f85949613979';
$primaryPhotoBefore = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->first();
$primaryPhotosBeforeCnt = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->count();
$this->assertEquals(1, $primaryPhotosBeforeCnt);
// $this->loginUserByRole('admin');
$url = [
'plugin' => 'CakeProducts',
'controller' => 'ProductPhotos',
'action' => 'delete',
$id,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('product-photos');
$cntAfter = $this->ProductPhotos->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
$primaryPhotoAfter = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->first();
$primaryPhotosAfterCnt = $this->ProductPhotos->find()->where(['primary_sku_photo' => true, 'product_sku_id' => $skuId])->count();
$this->assertEquals(1, $primaryPhotosAfterCnt);
$this->assertNotEquals($primaryPhotoBefore->id, $primaryPhotoAfter->id);
}
/**