more thorogh testing of toggle behavior on product photos
This commit is contained in:
parent
b145e901ef
commit
2041fc78d3
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue