Skip to content

Commit 5341e43

Browse files
author
Oleksii Korshenko
authored
MAGETWO-84018: #11691: Wrong return type for getAttributeText($attributeCode) #12003
2 parents 2b78994 + 21a891f commit 5341e43

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ public function isInStock()
17121712
* Get attribute text by its code
17131713
*
17141714
* @param string $attributeCode Code of the attribute
1715-
* @return string
1715+
* @return string|array|null
17161716
*/
17171717
public function getAttributeText($attributeCode)
17181718
{

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductGettersTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model;
77

8+
use Magento\Catalog\Api\ProductRepositoryInterface;
89
use Magento\Framework\App\Filesystem\DirectoryList;
910

1011
/**
@@ -25,11 +26,19 @@ class ProductGettersTest extends \PHPUnit\Framework\TestCase
2526
*/
2627
protected $_model;
2728

29+
/**
30+
* @var ProductRepositoryInterface
31+
*/
32+
private $productRepository;
33+
2834
protected function setUp()
2935
{
3036
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
3137
\Magento\Catalog\Model\Product::class
3238
);
39+
$this->productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
40+
ProductRepositoryInterface::class
41+
);
3342
}
3443

3544
public function testGetResourceCollection()
@@ -198,6 +207,24 @@ public function testGetAttributeText()
198207
$this->assertEquals('Enabled', $this->_model->getAttributeText('status'));
199208
}
200209

210+
/**
211+
* @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
212+
*/
213+
public function testGetAttributeTextArray()
214+
{
215+
$product = $this->productRepository->get('simple_ms_2');
216+
$product->getAttributeText('multiselect_attribute');
217+
$expected = [
218+
'Option 2',
219+
'Option 3',
220+
'Option 4 "!@#$%^&*'
221+
];
222+
self::assertEquals(
223+
$expected,
224+
$product->getAttributeText('multiselect_attribute')
225+
);
226+
}
227+
201228
public function testGetCustomDesignDate()
202229
{
203230
$this->assertEquals(['from' => null, 'to' => null], $this->_model->getCustomDesignDate());

0 commit comments

Comments
 (0)