Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magento/magento2#11691: Wrong return type for getAttributeText($attributeCode) #12003

Merged
merged 1 commit into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Catalog\Model;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\Filesystem\DirectoryList;

/**
Expand All @@ -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()
Expand Down Expand Up @@ -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());
Expand Down