Skip to content

Commit 764b00c

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #17693: Review: Adding missing unit test for Observer (by @eduard13) - #17690: Integration test for reviews delete observer (by @rogyar) - #17521: Translated admin menu titles (by @yogeshks)
2 parents 3c77057 + af23bf4 commit 764b00c

File tree

10 files changed

+173
-9
lines changed

10 files changed

+173
-9
lines changed

app/code/Magento/AdminNotification/etc/adminhtml/menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
99
<menu>
10-
<add id="Magento_AdminNotification::system_adminnotification" title="Notifications" translate="title" module="Magento_AdminNotification" sortOrder="10" parent="Magento_Backend::system_other_settings" action="adminhtml/notification" resource="Magento_AdminNotification::adminnotification"/>
10+
<add id="Magento_AdminNotification::system_adminnotification" title="Notifications" translate="title" module="Magento_AdminNotification" sortOrder="10" parent="Magento_Backend::system_other_settings" action="adminhtml/notification" resource="Magento_AdminNotification::adminnotification"/>
1111
</menu>
1212
</config>

app/code/Magento/Braintree/etc/acl.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<resource id="Magento_Backend::admin">
1212
<resource id="Magento_Reports::report">
1313
<resource id="Magento_Reports::salesroot">
14-
<resource id="Magento_Braintree::settlement_report" title="Braintree Settlement" sortOrder="80" />
14+
<resource id="Magento_Braintree::settlement_report" title="Braintree Settlement" translate="title" sortOrder="80" />
1515
</resource>
1616
</resource>
1717
</resource>

app/code/Magento/Braintree/etc/adminhtml/menu.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<add
1111
id="Magento_Braintree::settlement_report"
1212
title="Braintree Settlement"
13+
translate="title"
1314
module="Magento_Braintree"
1415
sortOrder="80"
1516
parent="Magento_Reports::report_salesroot"

app/code/Magento/Braintree/i18n/en_US.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,5 @@ Currency,Currency
190190
"Partial settlements are not supported by this processor.","Partial settlements are not supported by this processor."
191191
"Transaction can not be voided if status of a PayPal partial settlement child transaction is settlement_pending.","Transaction can not be voided if status of a PayPal partial settlement child transaction is settlement_pending."
192192
"Too many concurrent attempts to refund this transaction. Try again later.","Too many concurrent attempts to refund this transaction. Try again later."
193-
"Too many concurrent attempts to void this transaction. Try again later.","Too many concurrent attempts to void this transaction. Try again later."
193+
"Too many concurrent attempts to void this transaction. Try again later.","Too many concurrent attempts to void this transaction. Try again later."
194+
"Braintree Settlement","Braintree Settlement"

app/code/Magento/Marketplace/etc/adminhtml/menu.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
99
<menu>
10-
<add id="Magento_Marketplace::partners" title="Find Partners &amp; Extensions" module="Magento_Marketplace" sortOrder="80"
11-
action="marketplace/index" resource="Magento_Marketplace::partners"/>
10+
<add id="Magento_Marketplace::partners" title="Find Partners &amp; Extensions" translate="title" module="Magento_Marketplace" sortOrder="80" action="marketplace/index" resource="Magento_Marketplace::partners"/>
1211
</menu>
1312
</config>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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\Test\Unit\Observer;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\Event;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Review\Model\ResourceModel\Rating;
14+
use Magento\Review\Model\ResourceModel\Review;
15+
use Magento\Review\Observer\ProcessProductAfterDeleteEventObserver;
16+
use PHPUnit\Framework\TestCase;
17+
use PHPUnit_Framework_MockObject_MockObject;
18+
19+
/**
20+
* Class ProcessProductAfterDeleteEventObserverTest
21+
*/
22+
class ProcessProductAfterDeleteEventObserverTest extends TestCase
23+
{
24+
/**
25+
* Testable Object
26+
*
27+
* @var ProcessProductAfterDeleteEventObserver
28+
*/
29+
private $observer;
30+
31+
/**
32+
* @var Review|PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $_resourceReviewMock;
35+
36+
/**
37+
* @var Rating|PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $_resourceRatingMock;
40+
41+
/**
42+
* Set up
43+
*/
44+
protected function setUp()
45+
{
46+
$this->_resourceReviewMock = $this->createMock(Review::class);
47+
$this->_resourceRatingMock = $this->createMock(Rating::class);
48+
49+
$this->observer = new ProcessProductAfterDeleteEventObserver(
50+
$this->_resourceReviewMock,
51+
$this->_resourceRatingMock
52+
);
53+
}
54+
55+
/**
56+
* Test cleanup product reviews after product delete
57+
*
58+
* @return void
59+
*/
60+
public function testCleanupProductReviewsWithProduct()
61+
{
62+
$productId = 1;
63+
$observerMock = $this->createMock(Observer::class);
64+
$eventMock = $this->getMockBuilder(Event::class)
65+
->disableOriginalConstructor()
66+
->setMethods(['getProduct'])
67+
->getMock();
68+
69+
$productMock = $this->getMockBuilder(Product::class)
70+
->disableOriginalConstructor()
71+
->setMethods(['getId'])
72+
->getMock();
73+
74+
$productMock->expects(self::exactly(3))
75+
->method('getId')
76+
->willReturn($productId);
77+
$eventMock->expects($this->once())
78+
->method('getProduct')
79+
->willReturn($productMock);
80+
$observerMock->expects($this->once())
81+
->method('getEvent')
82+
->willReturn($eventMock);
83+
$this->_resourceReviewMock->expects($this->once())
84+
->method('deleteReviewsByProductId')
85+
->willReturnSelf();
86+
$this->_resourceRatingMock->expects($this->once())
87+
->method('deleteAggregatedRatingsByProductId')
88+
->willReturnSelf();
89+
90+
$this->observer->execute($observerMock);
91+
}
92+
93+
/**
94+
* Test with no event product
95+
*
96+
* @return void
97+
*/
98+
public function testCleanupProductReviewsWithoutProduct()
99+
{
100+
$observerMock = $this->createMock(Observer::class);
101+
$eventMock = $this->getMockBuilder(Event::class)
102+
->disableOriginalConstructor()
103+
->setMethods(['getProduct'])
104+
->getMock();
105+
106+
$eventMock->expects($this->once())
107+
->method('getProduct')
108+
->willReturn(null);
109+
$observerMock->expects($this->once())
110+
->method('getEvent')
111+
->willReturn($eventMock);
112+
$this->_resourceReviewMock->expects($this->never())
113+
->method('deleteReviewsByProductId')
114+
->willReturnSelf();
115+
$this->_resourceRatingMock->expects($this->never())
116+
->method('deleteAggregatedRatingsByProductId')
117+
->willReturnSelf();
118+
119+
$this->observer->execute($observerMock);
120+
}
121+
}

app/code/Magento/TaxImportExport/etc/acl.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<resource id="Magento_Backend::admin">
1212
<resource id="Magento_Backend::system">
1313
<resource id="Magento_Backend::convert">
14-
<resource id="Magento_TaxImportExport::import_export" title="Import/Export Tax Rates" sortOrder="30" />
14+
<resource id="Magento_TaxImportExport::import_export" title="Import/Export Tax Rates" translate="title" sortOrder="30" />
1515
</resource>
1616
</resource>
1717
</resource>

app/code/Magento/TaxImportExport/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Rate,Rate
1717
"Export Tax Rates","Export Tax Rates"
1818
CSV,CSV
1919
"Excel XML","Excel XML"
20+
"Import/Export Tax Rates","Import/Export Tax Rates"

app/code/Magento/UrlRewrite/etc/adminhtml/menu.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
99
<menu>
10-
<add id="Magento_UrlRewrite::urlrewrite" title="URL Rewrites" translate="title" module="Magento_UrlRewrite"
11-
sortOrder="20" parent="Magento_Backend::marketing_seo"
12-
action="adminhtml/url_rewrite/index" resource="Magento_UrlRewrite::urlrewrite"/>
10+
<add id="Magento_UrlRewrite::urlrewrite" title="URL Rewrites" translate="title" module="Magento_UrlRewrite" sortOrder="20" parent="Magento_Backend::marketing_seo" action="adminhtml/url_rewrite/index" resource="Magento_UrlRewrite::urlrewrite"/>
1311
</menu>
1412
</config>
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)