Skip to content

Commit

Permalink
#11691: Wrong return type for getAttributeText($attributeCode)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Nov 20, 2017
1 parent b05a957 commit bd9054a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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

0 comments on commit bd9054a

Please sign in to comment.