Skip to content

Commit 892abe1

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-2522-V2' into Tier4-PR-Delivery-11-18-23
2 parents 07d7db9 + 3a1e56d commit 892abe1

File tree

4 files changed

+90
-11
lines changed

4 files changed

+90
-11
lines changed

app/code/Magento/Catalog/Helper/Product/View.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,7 @@ private function preparePageMetadata(ResultPage $resultPage, $product)
130130
$pageConfig->setKeywords($product->getName());
131131
}
132132

133-
$description = $product->getMetaDescription();
134-
if ($description) {
135-
$pageConfig->setDescription($description);
136-
} else {
137-
$productDescription = is_string($product->getDescription()) ?
138-
$this->string->substr(strip_tags($product->getDescription()), 0, 255) : '';
139-
$pageConfig->setDescription($productDescription);
140-
}
133+
$pageConfig->setDescription($product->getMetaDescription());
141134

142135
if ($this->_catalogProduct->canUseCanonicalTag()) {
143136
$pageConfig->addRemotePageAsset(

dev/tests/integration/testsuite/Magento/Catalog/Helper/Product/ViewTest.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
*/
66
namespace Magento\Catalog\Helper\Product;
77

8+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
89
use Magento\Customer\Model\Context;
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\TestFramework\Fixture\AppIsolation;
13+
use Magento\TestFramework\Fixture\DataFixture;
14+
use Magento\TestFramework\Fixture\DataFixtureStorage;
15+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
916

1017
/**
1118
* @magentoAppArea frontend
@@ -33,10 +40,15 @@ class ViewTest extends \PHPUnit\Framework\TestCase
3340
*/
3441
protected $objectManager;
3542

43+
/**
44+
* @var DataFixtureStorage
45+
*/
46+
private $fixtures;
47+
3648
protected function setUp(): void
3749
{
3850
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
39-
51+
$this->fixtures = DataFixtureStorageManager::getStorage();
4052
$this->objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
4153
$this->objectManager->get(\Magento\Framework\App\Http\Context::class)
4254
->setValue(Context::CONTEXT_AUTH, false, false);
@@ -124,6 +136,71 @@ public function testPrepareAndRender()
124136
);
125137
}
126138

139+
/**
140+
* Product meta description should be rendered on the product HTML sources as is, without changes or substitutions
141+
*
142+
* @return void
143+
* @throws LocalizedException
144+
* @throws NoSuchEntityException
145+
*/
146+
#[
147+
AppIsolation(true),
148+
DataFixture(ProductFixture::class, ['meta_description' => 'Product Meta Description'], 'p1'),
149+
]
150+
public function testProductMetaDescriptionShouldBeRenderedAsIs()
151+
{
152+
$product = $this->fixtures->get('p1');
153+
$metaDescription = '<meta name="description" content="Product Meta Description"/>';
154+
155+
$this->objectManager->get(\Magento\Framework\App\RequestInterface::class)->setParam('id', $product->getId());
156+
$this->_helper->prepareAndRender($this->page, $product->getId(), $this->_controller);
157+
158+
/** @var \Magento\TestFramework\Response $response */
159+
$response = $this->objectManager->get(\Magento\TestFramework\Response::class);
160+
161+
$this->page->renderResult($response);
162+
163+
$this->assertNotEmpty($response->getBody());
164+
$this->assertStringContainsString(
165+
$metaDescription,
166+
$response->getBody(),
167+
'Empty meta description should be rendered as is'
168+
);
169+
}
170+
171+
/**
172+
* If the product meta description is empty, it should not be substituted with any other data and should not be
173+
* rendered on the product HTML sources
174+
*
175+
* @return void
176+
* @throws LocalizedException
177+
* @throws NoSuchEntityException
178+
*/
179+
#[
180+
AppIsolation(true),
181+
DataFixture(ProductFixture::class, ['meta_description' => ''], 'p1'),
182+
]
183+
public function testEmptyProductMetaDescriptionShouldNotBeSubstitutedAndRendered()
184+
{
185+
$product = $this->fixtures->get('p1');
186+
$metaDescription = '<meta name="description" content="';
187+
188+
$this->objectManager->get(\Magento\Framework\App\RequestInterface::class)->setParam('id', $product->getId());
189+
$this->_helper->prepareAndRender($this->page, $product->getId(), $this->_controller);
190+
191+
/** @var \Magento\TestFramework\Response $response */
192+
$response = $this->objectManager->get(\Magento\TestFramework\Response::class);
193+
194+
$this->page->renderResult($response);
195+
196+
$this->assertNotEmpty($response->getBody());
197+
$this->assertStringNotContainsStringIgnoringCase(
198+
$metaDescription,
199+
$response->getBody(),
200+
'Empty meta description should not be substituted or rendered'
201+
);
202+
}
203+
127204
/**
128205
* @magentoAppIsolation enabled
129206
*/

setup/src/Magento/Setup/Fixtures/SimpleProductsFixture.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SimpleProductsFixture extends Fixture
3939
/**
4040
* Simple product sku pattern
4141
*/
42-
const SKU_PATTERN = 'product_dynamic_%s';
42+
public const SKU_PATTERN = 'product_dynamic_%s';
4343

4444
/**
4545
* @var int
@@ -257,6 +257,12 @@ public function execute()
257257
'category_ids' => function ($index, $entityNumber) {
258258
return $this->websiteCategoryProvider->getCategoryId($index);
259259
},
260+
'meta_keyword' => function ($productId) {
261+
return sprintf($this->getSkuPattern(), $productId);
262+
},
263+
'meta_title' => function ($productId) {
264+
return sprintf($this->getSkuPattern(), $productId);
265+
},
260266
'attribute_set_id' => $attributeSet,
261267
'additional_attributes' => $additionalAttributes,
262268
'status' => function () {

setup/src/Magento/Setup/Model/FixtureGenerator/SimpleProductTemplateGenerator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(ProductFactory $productFactory, array $fixture)
3939
}
4040

4141
/**
42-
* {@inheritdoc}
42+
* @inheritdoc
4343
*/
4444
public function generateEntity()
4545
{
@@ -70,6 +70,9 @@ private function getProductTemplate($attributeSet, $additionalAttributes = [])
7070
'name' => 'template name' . $productRandomizerNumber,
7171
'url_key' => 'template-url' . $productRandomizerNumber,
7272
'sku' => 'template_sku_simple' . $productRandomizerNumber,
73+
'meta_description' => 'Simple Product',
74+
'meta_keyword' => $productRandomizerNumber,
75+
'meta_title' => $productRandomizerNumber,
7376
'price' => 10,
7477
'visibility' => Visibility::VISIBILITY_BOTH,
7578
'status' => Status::STATUS_ENABLED,

0 commit comments

Comments
 (0)