Skip to content

Commit dfff468

Browse files
author
Stanislav Idolov
authored
ENGCOM-2849: [Forwardport] Integration test for reviews delete observer #17712
2 parents 9cca919 + b179cf6 commit dfff468

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Review\Observer;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
12+
use Magento\Review\Model\ResourceModel\Review\CollectionFactory as ReviewCollectionFactory;
13+
use Magento\TestFramework\TestCase\AbstractController;
14+
15+
/**
16+
* Test checks that product review is removed when the corresponding product is removed
17+
*/
18+
class ProcessProductAfterDeleteEventObserverTest extends AbstractController
19+
{
20+
/**
21+
* @magentoDataFixture Magento/Review/_files/customer_review.php
22+
*/
23+
public function testReviewIsRemovedWhenProductDeleted()
24+
{
25+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
26+
27+
/** @var ProductRepositoryInterface $productRepository */
28+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
29+
$product = $productRepository->get('simple');
30+
31+
/** @var ReviewCollection $reviewsCollection */
32+
$reviewsCollection = $objectManager->get(ReviewCollectionFactory::class)->create();
33+
$reviewsCollection->addEntityFilter('product', $product->getId());
34+
35+
self::assertEquals(1, $reviewsCollection->count());
36+
37+
/* Remove product and ensure that the product review is removed as well */
38+
$productRepository->delete($product);
39+
$reviewsCollection->clear();
40+
41+
self::assertEquals(0, $reviewsCollection->count());
42+
}
43+
}

0 commit comments

Comments
 (0)