Skip to content

Commit 81d0497

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #21872: [Backport] [TASK] Remove translation of attribute store label in getA� (by @mage2pratik) - #21859: [Backport] [Wishlist] Covering the Wishlist classes by integration and unit tests (by @eduard13) - #21435: [Backport] #20773: Do not throw exception during autoload (by @amol2jcommerce) - #21849: [Backport][Review] Fix Pending Reviews label, add menu for pending review (by @eduard13) Fixed GitHub Issues: - #20773: The autoloader throws an exception on class_exists (reported by @sidolov) has been fixed in #21435 by @amol2jcommerce in 2.2-develop branch Related commits: 1. 2e58ab6 2. 3de1647 - #20924: Reviews ACL issue - showing Reviews menu two times under System > User Roles > Add New Role > Role Resources (reported by @dankhrapiyush) has been fixed in #21849 by @eduard13 in 2.2-develop branch Related commits: 1. dd3a94a 2. 5c8dba8 3. 95c1bc8
2 parents f44720a + d1013b9 commit 81d0497

File tree

9 files changed

+433
-14
lines changed

9 files changed

+433
-14
lines changed

app/code/Magento/Catalog/Block/Product/View/Attributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getAdditionalData(array $excludeAttr = [])
9797

9898
if (is_string($value) && strlen(trim($value))) {
9999
$data[$attribute->getAttributeCode()] = [
100-
'label' => __($attribute->getStoreLabel()),
100+
'label' => $attribute->getStoreLabel(),
101101
'value' => $value,
102102
'code' => $attribute->getAttributeCode(),
103103
];

app/code/Magento/Review/Block/Adminhtml/Edit.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Review\Block\Adminhtml;
78

89
/**
@@ -56,6 +57,7 @@ public function __construct(
5657
*
5758
* @return void
5859
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
60+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
5961
*/
6062
protected function _construct()
6163
{
@@ -159,13 +161,13 @@ protected function _construct()
159161
}
160162

161163
if ($this->getRequest()->getParam('ret', false) == 'pending') {
162-
$this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getUrl('catalog/*/pending') . '\')');
164+
$this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getUrl('review/*/pending') . '\')');
163165
$this->buttonList->update(
164166
'delete',
165167
'onclick',
166168
'deleteConfirm(' . '\'' . __(
167169
'Are you sure you want to do this?'
168-
) . '\' ' . '\'' . $this->getUrl(
170+
) . '\', ' . '\'' . $this->getUrl(
169171
'*/*/delete',
170172
[$this->_objectId => $this->getRequest()->getParam($this->_objectId), 'ret' => 'pending']
171173
) . '\'' . ')'

app/code/Magento/Review/Controller/Adminhtml/Product/Save.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
use Magento\Framework\Controller\ResultFactory;
1010
use Magento\Framework\Exception\LocalizedException;
1111

12+
/**
13+
* Save Review action.
14+
*/
1215
class Save extends ProductController
1316
{
1417
/**
18+
* Save Review action.
19+
*
1520
* @return \Magento\Backend\Model\View\Result\Redirect
1621
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
1722
*/
@@ -63,7 +68,7 @@ public function execute()
6368
if ($nextId) {
6469
$resultRedirect->setPath('review/*/edit', ['id' => $nextId]);
6570
} elseif ($this->getRequest()->getParam('ret') == 'pending') {
66-
$resultRedirect->setPath('*/*/pending');
71+
$resultRedirect->setPath('review/*/pending');
6772
} else {
6873
$resultRedirect->setPath('*/*/');
6974
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<resource id="Magento_Backend::marketing">
1818
<resource id="Magento_Backend::marketing_user_content">
1919
<resource id="Magento_Review::reviews_all" title="Reviews" translate="title" sortOrder="10"/>
20-
<resource id="Magento_Review::pending" title="Reviews" translate="title" sortOrder="20"/>
20+
<resource id="Magento_Review::pending" title="Pending Reviews" translate="title" sortOrder="20"/>
2121
</resource>
2222
</resource>
2323
</resource>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<menu>
1010
<add id="Magento_Review::catalog_reviews_ratings_ratings" title="Rating" translate="title" module="Magento_Review" sortOrder="60" parent="Magento_Backend::stores_attributes" action="review/rating/" resource="Magento_Review::ratings"/>
1111
<add id="Magento_Review::catalog_reviews_ratings_reviews_all" title="Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="10" action="review/product/index" resource="Magento_Review::reviews_all"/>
12+
<add id="Magento_Review::catalog_reviews_ratings_pending" title="Pending Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="15" action="review/product/pending" resource="Magento_Review::pending"/>
1213
<add id="Magento_Review::report_review" title="Reviews" translate="title" module="Magento_Reports" sortOrder="20" parent="Magento_Reports::report" resource="Magento_Reports::review"/>
1314
<add id="Magento_Review::report_review_customer" title="By Customers" translate="title" sortOrder="10" module="Magento_Review" parent="Magento_Review::report_review" action="reports/report_review/customer" resource="Magento_Reports::review_customer"/>
1415
<add id="Magento_Review::report_review_product" title="By Products" translate="title" sortOrder="20" module="Magento_Review" parent="Magento_Review::report_review" action="reports/report_review/product" resource="Magento_Reports::review_product"/>
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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\Wishlist\Test\Unit\Model\Product;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
12+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13+
use Magento\Framework\DB\Adapter\AdapterInterface;
14+
use Magento\Wishlist\Model\Product\AttributeValueProvider;
15+
use PHPUnit\Framework\TestCase;
16+
use PHPUnit_Framework_MockObject_MockObject;
17+
18+
/**
19+
* AttributeValueProviderTest
20+
*/
21+
class AttributeValueProviderTest extends TestCase
22+
{
23+
/**
24+
* @var AttributeValueProvider|PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $attributeValueProvider;
27+
28+
/**
29+
* @var CollectionFactory|PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $productCollectionFactoryMock;
32+
33+
/**
34+
* @var Product|PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $productMock;
37+
38+
/**
39+
* @var AdapterInterface|PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $connectionMock;
42+
43+
/**
44+
* Set Up
45+
*
46+
* @return void
47+
*/
48+
protected function setUp()
49+
{
50+
$this->productCollectionFactoryMock = $this->createPartialMock(
51+
CollectionFactory::class,
52+
['create']
53+
);
54+
$this->attributeValueProvider = new AttributeValueProvider(
55+
$this->productCollectionFactoryMock
56+
);
57+
}
58+
59+
/**
60+
* Get attribute text when the flat table is disabled
61+
*
62+
* @param int $productId
63+
* @param string $attributeCode
64+
* @param string $attributeText
65+
* @return void
66+
* @dataProvider attributeDataProvider
67+
*/
68+
public function testGetAttributeTextWhenFlatIsDisabled(int $productId, string $attributeCode, string $attributeText)
69+
{
70+
$this->productMock = $this->getMockBuilder(Product::class)
71+
->disableOriginalConstructor()
72+
->setMethods(['getData'])
73+
->getMock();
74+
75+
$this->productMock->expects($this->any())
76+
->method('getData')
77+
->with($attributeCode)
78+
->willReturn($attributeText);
79+
80+
$productCollection = $this->getMockBuilder(Collection::class)
81+
->disableOriginalConstructor()
82+
->setMethods([
83+
'addIdFilter', 'addStoreFilter', 'addAttributeToSelect', 'isEnabledFlat', 'getFirstItem'
84+
])->getMock();
85+
86+
$productCollection->expects($this->any())
87+
->method('addIdFilter')
88+
->willReturnSelf();
89+
$productCollection->expects($this->any())
90+
->method('addStoreFilter')
91+
->willReturnSelf();
92+
$productCollection->expects($this->any())
93+
->method('addAttributeToSelect')
94+
->willReturnSelf();
95+
$productCollection->expects($this->any())
96+
->method('isEnabledFlat')
97+
->willReturn(false);
98+
$productCollection->expects($this->any())
99+
->method('getFirstItem')
100+
->willReturn($this->productMock);
101+
102+
$this->productCollectionFactoryMock->expects($this->atLeastOnce())
103+
->method('create')
104+
->willReturn($productCollection);
105+
106+
$actual = $this->attributeValueProvider->getRawAttributeValue($productId, $attributeCode);
107+
108+
$this->assertEquals($attributeText, $actual);
109+
}
110+
111+
/**
112+
* Get attribute text when the flat table is enabled
113+
*
114+
* @dataProvider attributeDataProvider
115+
* @param int $productId
116+
* @param string $attributeCode
117+
* @param string $attributeText
118+
* @return void
119+
*/
120+
public function testGetAttributeTextWhenFlatIsEnabled(int $productId, string $attributeCode, string $attributeText)
121+
{
122+
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass();
123+
$this->connectionMock->expects($this->any())
124+
->method('fetchRow')
125+
->willReturn([
126+
$attributeCode => $attributeText
127+
]);
128+
$this->productMock = $this->getMockBuilder(Product::class)
129+
->disableOriginalConstructor()
130+
->setMethods(['getData'])
131+
->getMock();
132+
$this->productMock->expects($this->any())
133+
->method('getData')
134+
->with($attributeCode)
135+
->willReturn($attributeText);
136+
137+
$productCollection = $this->getMockBuilder(Collection::class)
138+
->disableOriginalConstructor()
139+
->setMethods([
140+
'addIdFilter', 'addStoreFilter', 'addAttributeToSelect', 'isEnabledFlat', 'getConnection'
141+
])->getMock();
142+
143+
$productCollection->expects($this->any())
144+
->method('addIdFilter')
145+
->willReturnSelf();
146+
$productCollection->expects($this->any())
147+
->method('addStoreFilter')
148+
->willReturnSelf();
149+
$productCollection->expects($this->any())
150+
->method('addAttributeToSelect')
151+
->willReturnSelf();
152+
$productCollection->expects($this->any())
153+
->method('isEnabledFlat')
154+
->willReturn(true);
155+
$productCollection->expects($this->any())
156+
->method('getConnection')
157+
->willReturn($this->connectionMock);
158+
159+
$this->productCollectionFactoryMock->expects($this->atLeastOnce())
160+
->method('create')
161+
->willReturn($productCollection);
162+
163+
$actual = $this->attributeValueProvider->getRawAttributeValue($productId, $attributeCode);
164+
165+
$this->assertEquals($attributeText, $actual);
166+
}
167+
168+
/**
169+
* @return array
170+
*/
171+
public function attributeDataProvider(): array
172+
{
173+
return [
174+
[1, 'attribute_code', 'Attribute Text']
175+
];
176+
}
177+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Code\Generator;
8+
9+
use Magento\Framework\Code\Generator;
10+
use Magento\Framework\Logger\Monolog as MagentoMonologLogger;
11+
use Magento\TestFramework\ObjectManager;
12+
use PHPUnit\Framework\TestCase;
13+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
14+
use Psr\Log\LoggerInterface;
15+
16+
class AutoloaderTest extends TestCase
17+
{
18+
/**
19+
* This method exists to fix the wrong return type hint on \Magento\Framework\App\ObjectManager::getInstance.
20+
* This way the IDE knows it's dealing with an instance of \Magento\TestFramework\ObjectManager and
21+
* not \Magento\Framework\App\ObjectManager. The former has the method addSharedInstance, the latter does not.
22+
*
23+
* @return ObjectManager|\Magento\Framework\App\ObjectManager
24+
* @SuppressWarnings(PHPMD.StaticAccess)
25+
*/
26+
private function getTestFrameworkObjectManager()
27+
{
28+
return ObjectManager::getInstance();
29+
}
30+
31+
/**
32+
* @before
33+
*/
34+
public function setupLoggerTestDouble(): void
35+
{
36+
$loggerTestDouble = $this->createMock(LoggerInterface::class);
37+
$this->getTestFrameworkObjectManager()->addSharedInstance($loggerTestDouble, MagentoMonologLogger::class);
38+
}
39+
40+
/**
41+
* @after
42+
*/
43+
public function removeLoggerTestDouble(): void
44+
{
45+
$this->getTestFrameworkObjectManager()->removeSharedInstance(MagentoMonologLogger::class);
46+
}
47+
48+
/**
49+
* @param \RuntimeException $testException
50+
* @return Generator|MockObject
51+
*/
52+
private function createExceptionThrowingGeneratorTestDouble(\RuntimeException $testException)
53+
{
54+
/** @var Generator|MockObject $generatorStub */
55+
$generatorStub = $this->createMock(Generator::class);
56+
$generatorStub->method('generateClass')->willThrowException($testException);
57+
58+
return $generatorStub;
59+
}
60+
61+
public function testLogsExceptionDuringGeneration(): void
62+
{
63+
$exceptionMessage = 'Test exception thrown during generation';
64+
$testException = new \RuntimeException($exceptionMessage);
65+
66+
$loggerMock = ObjectManager::getInstance()->get(LoggerInterface::class);
67+
$loggerMock->expects($this->once())->method('debug')->with($exceptionMessage, ['exception' => $testException]);
68+
69+
$autoloader = new Autoloader($this->createExceptionThrowingGeneratorTestDouble($testException));
70+
$this->assertNull($autoloader->load(NonExistingClassName::class));
71+
}
72+
73+
public function testFiltersDuplicateExceptionMessages(): void
74+
{
75+
$exceptionMessage = 'Test exception thrown during generation';
76+
$testException = new \RuntimeException($exceptionMessage);
77+
78+
$loggerMock = ObjectManager::getInstance()->get(LoggerInterface::class);
79+
$loggerMock->expects($this->once())->method('debug')->with($exceptionMessage, ['exception' => $testException]);
80+
81+
$autoloader = new Autoloader($this->createExceptionThrowingGeneratorTestDouble($testException));
82+
$autoloader->load(OneNonExistingClassName::class);
83+
$autoloader->load(AnotherNonExistingClassName::class);
84+
}
85+
}

0 commit comments

Comments
 (0)