Skip to content

Commit 9b53b7a

Browse files
committed
MC-15533: Product attribute template incorrectly handles data
1 parent eafcbfe commit 9b53b7a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/attribute.phtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<?php
1616
$_helper = $this->helper('Magento\Catalog\Helper\Output');
1717
$_product = $block->getProduct();
18+
19+
if (!$_product instanceof \Magento\Catalog\Model\Product) {
20+
return;
21+
}
22+
1823
$_call = $block->getAtCall();
1924
$_code = $block->getAtCode();
2025
$_className = $block->getCssClass();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Block\Product;
7+
8+
use Magento\Framework\Registry;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
/**
12+
* @magentoAppArea frontend
13+
*/
14+
class DescriptionTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var View\Description
18+
*/
19+
private $block;
20+
21+
/**
22+
* @var Registry
23+
*/
24+
private $registry;
25+
26+
protected function setUp()
27+
{
28+
$objectManager = Bootstrap::getObjectManager();
29+
$this->block = $objectManager->create(View\Description::class, [
30+
'data' => [
31+
'template' => 'Magento_Catalog::product/view/attribute.phtml'
32+
]
33+
]);
34+
35+
$this->registry = $objectManager->get(Registry::class);
36+
$this->registry->unregister('product');
37+
}
38+
39+
public function testGetProductWhenNoProductIsRegistered()
40+
{
41+
$html = $this->block->toHtml();
42+
$this->assertEmpty($html);
43+
}
44+
45+
public function testGetProductWhenInvalidProductIsRegistered()
46+
{
47+
$this->registry->register('product', new \stdClass());
48+
$html = $this->block->toHtml();
49+
$this->assertEmpty($html);
50+
}
51+
}

0 commit comments

Comments
 (0)