From bd9054a4891bf9e78fdeac54e3136e28df4758a0 Mon Sep 17 00:00:00 2001
From: Pavel Bystritsky
Date: Mon, 20 Nov 2017 11:00:20 +0200
Subject: [PATCH] magento/magento2#11691: Wrong return type for
getAttributeText($attributeCode)
---
app/code/Magento/Catalog/Model/Product.php | 2 +-
.../Catalog/Model/ProductGettersTest.php | 27 +++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php
index cf1392a7e9e8c..cb5669a4bb42e 100644
--- a/app/code/Magento/Catalog/Model/Product.php
+++ b/app/code/Magento/Catalog/Model/Product.php
@@ -1712,7 +1712,7 @@ public function isInStock()
* Get attribute text by its code
*
* @param string $attributeCode Code of the attribute
- * @return string
+ * @return string|array|null
*/
public function getAttributeText($attributeCode)
{
diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductGettersTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductGettersTest.php
index 74f640a021284..1ed0057ca2486 100644
--- a/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductGettersTest.php
+++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ProductGettersTest.php
@@ -5,6 +5,7 @@
*/
namespace Magento\Catalog\Model;
+use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
/**
@@ -25,11 +26,19 @@ class ProductGettersTest extends \PHPUnit\Framework\TestCase
*/
protected $_model;
+ /**
+ * @var ProductRepositoryInterface
+ */
+ private $productRepository;
+
protected function setUp()
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\Product::class
);
+ $this->productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
+ ProductRepositoryInterface::class
+ );
}
public function testGetResourceCollection()
@@ -198,6 +207,24 @@ public function testGetAttributeText()
$this->assertEquals('Enabled', $this->_model->getAttributeText('status'));
}
+ /**
+ * @magentoDataFixture Magento/Catalog/_files/products_with_multiselect_attribute.php
+ */
+ public function testGetAttributeTextArray()
+ {
+ $product = $this->productRepository->get('simple_ms_2');
+ $product->getAttributeText('multiselect_attribute');
+ $expected = [
+ 'Option 2',
+ 'Option 3',
+ 'Option 4 "!@#$%^&*'
+ ];
+ self::assertEquals(
+ $expected,
+ $product->getAttributeText('multiselect_attribute')
+ );
+ }
+
public function testGetCustomDesignDate()
{
$this->assertEquals(['from' => null, 'to' => null], $this->_model->getCustomDesignDate());