Skip to content

Commit a342b00

Browse files
committed
Merge remote-tracking branch 'origin/AC-2719' into gl_pr_arrows_april21_2022
2 parents 33205df + 3250559 commit a342b00

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

app/code/Magento/Catalog/Block/Product/Compare/ListCompare.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class ListCompare extends \Magento\Catalog\Block\Product\AbstractProduct
4040
protected $_useLinkForAsLowAs = false;
4141

4242
/**
43-
* Customer id
44-
*
4543
* @var null|int
4644
*/
4745
protected $_customerId = null;
@@ -52,22 +50,16 @@ class ListCompare extends \Magento\Catalog\Block\Product\AbstractProduct
5250
protected $httpContext;
5351

5452
/**
55-
* Customer visitor
56-
*
5753
* @var \Magento\Customer\Model\Visitor
5854
*/
5955
protected $_customerVisitor;
6056

6157
/**
62-
* Catalog product visibility
63-
*
6458
* @var \Magento\Catalog\Model\Product\Visibility
6559
*/
6660
protected $_catalogProductVisibility;
6761

6862
/**
69-
* Item collection factory
70-
*
7163
* @var \Magento\Catalog\Model\ResourceModel\Product\Compare\Item\CollectionFactory
7264
*/
7365
protected $_itemCollectionFactory;
@@ -205,6 +197,9 @@ public function getProductAttributeValue($product, $attribute)
205197
} else {
206198
$value = $product->getData($attribute->getAttributeCode());
207199
}
200+
if (is_array($value)) {
201+
return __('N/A');
202+
}
208203
return (string)$value == '' ? __('No') : $value;
209204
}
210205

app/code/Magento/Catalog/Test/Unit/Block/Product/Compare/ListCompareTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Catalog\Block\Product\Compare\ListCompare;
1111
use Magento\Catalog\Block\Product\Context;
1212
use Magento\Catalog\Model\Product;
13+
use Magento\Eav\Model\Entity\Attribute\AttributeInterface;
14+
use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
1315
use Magento\Framework\Pricing\Render;
1416
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1517
use Magento\Framework\View\Layout;
@@ -50,6 +52,48 @@ protected function tearDown(): void
5052
$this->block = null;
5153
}
5254

55+
/**
56+
* @dataProvider attributeDataProvider
57+
* @param array $attributeData
58+
* @param string $expectedResult
59+
*/
60+
public function testProductAttributeValue($attributeData, $expectedResult)
61+
{
62+
$attribute = $this->getMockBuilder(AttributeInterface::class)
63+
->addMethods(['getAttributeCode', 'getSourceModel', 'getFrontendInput', 'getFrontend'])
64+
->getMockForAbstractClass();
65+
$frontEndModel = $this->createPartialMock(AbstractFrontend::class, ['getValue']);
66+
$productMock = $this->createPartialMock(Product::class, ['getId', 'getData', 'hasData']);
67+
$productMock->expects($this->any())
68+
->method('hasData')
69+
->with($attributeData['attribute_code'])
70+
->willReturn(true);
71+
$productMock->expects($this->any())
72+
->method('getData')
73+
->with($attributeData['attribute_code'])
74+
->willReturn($attributeData['attribute_value']);
75+
$attribute->expects($this->any())
76+
->method('getAttributeCode')
77+
->willReturn($attributeData['attribute_code']);
78+
$attribute->expects($this->any())
79+
->method('getSourceModel')
80+
->willReturn($attributeData['source_model']);
81+
$attribute->expects($this->any())
82+
->method('getFrontendInput')
83+
->willReturn($attributeData['frontend_input']);
84+
$frontEndModel->expects($this->any())
85+
->method('getValue')
86+
->with($productMock)
87+
->willReturn($attributeData['attribute_value']);
88+
$attribute->expects($this->any())
89+
->method('getFrontend')
90+
->willReturn($frontEndModel);
91+
$this->assertEquals(
92+
$expectedResult,
93+
$this->block->getProductAttributeValue($productMock, $attribute)
94+
);
95+
}
96+
5397
public function testGetProductPrice()
5498
{
5599
//Data
@@ -84,4 +128,31 @@ public function testGetProductPrice()
84128

85129
$this->assertEquals($expectedResult, $this->block->getProductPrice($product, '-compare-list-top'));
86130
}
131+
132+
/**
133+
* @return array
134+
*/
135+
public function attributeDataProvider(): array
136+
{
137+
return [
138+
[
139+
'attributeData' => [
140+
'attribute_code' => 'tier_price',
141+
'source_model' => null,
142+
'frontend_input' => 'text',
143+
'attribute_value' => []
144+
],
145+
'expectedResult' => __('N/A')
146+
],
147+
[
148+
'attributeData' => [
149+
'attribute_code' => 'special_price',
150+
'source_model' => null,
151+
'frontend_input' => 'decimal',
152+
'attribute_value' => 50.00
153+
],
154+
'expectedResult' => '50.00'
155+
]
156+
];
157+
}
87158
}

0 commit comments

Comments
 (0)