Skip to content

Commit 6235bb4

Browse files
committed
Merge branch 'ACP2E-2266' of https://github.com/magento-l3/magento2ce into Tier4-PR-10-30-2023
2 parents b4d2d0e + 19dbedd commit 6235bb4

File tree

2 files changed

+87
-0
lines changed
  • app/code/Magento/Catalog/view/frontend/templates/product/view
  • dev/tests/integration/testsuite/Magento/Catalog/Controller

2 files changed

+87
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ $mainImageData = $mainImage ?
3939
<?= $imageWidth ? 'width="'. $escaper->escapeHtmlAttr($imageWidth) .'"' : '' ?>
4040
<?= $imageHeight ? 'height="'. $escaper->escapeHtmlAttr($imageHeight) .'"' : '' ?>
4141
/>
42+
<link itemprop="image" href="<?= /* @noEscape */ $mainImageData ?>">
4243
</div>
4344
<?php // phpcs:ignore Magento2.Legacy.PhtmlTemplate ?>
4445
<script type="text/x-magento-init">

dev/tests/integration/testsuite/Magento/Catalog/Controller/ProductTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77

88
namespace Magento\Catalog\Controller;
99

10+
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
11+
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
12+
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
1013
use Magento\Catalog\Api\Data\ProductInterface;
1114
use Magento\Catalog\Api\ProductRepositoryInterface;
15+
use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture;
16+
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
1217
use Magento\Catalog\Model\Session;
18+
use Magento\Catalog\Test\Fixture\Category;
19+
use Magento\Catalog\Test\Fixture\Product;
1320
use Magento\Framework\Registry;
1421
use Magento\TestFramework\Catalog\Model\ProductLayoutUpdateManager;
22+
use Magento\TestFramework\Fixture\DataFixture;
23+
use Magento\TestFramework\Fixture\DataFixtureStorage;
24+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1525
use Magento\TestFramework\Helper\Bootstrap;
1626
use Magento\TestFramework\Helper\Xpath;
1727
use Magento\TestFramework\TestCase\AbstractController;
@@ -34,6 +44,11 @@ class ProductTest extends AbstractController
3444
/** @var Session */
3545
private $session;
3646

47+
/**
48+
* @var DataFixtureStorage
49+
*/
50+
private $fixture;
51+
3752
/**
3853
* @inheritdoc
3954
*/
@@ -53,6 +68,7 @@ protected function setUp(): void
5368
$this->registry = $this->_objectManager->get(Registry::class);
5469
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
5570
$this->session = $this->_objectManager->get(Session::class);
71+
$this->fixture = DataFixtureStorageManager::getStorage();
5672
}
5773

5874
/**
@@ -255,4 +271,74 @@ public function testViewWithCustomUpdate(): void
255271
->getHandles();
256272
$this->assertContains("catalog_product_view_selectable_{$sku}_{$file}", $handles);
257273
}
274+
275+
/**
276+
* Validate itemprop generation on different product types' page
277+
*
278+
* @return void
279+
*/
280+
#[
281+
DataFixture(Category::class, as: 'category'),
282+
DataFixture(
283+
Product::class,
284+
['category_ids' => ['$category.id$'], 'short_description' => 'Product Short Description'],
285+
as: 'sp'
286+
),
287+
DataFixture(AttributeFixture::class, ['options' => [['label' => 'option1', 'sort_order' => 0]]], as: 'attr'),
288+
DataFixture(
289+
ConfigurableProductFixture::class,
290+
[
291+
'short_description' => 'Configurable Product Short Description',
292+
'_options' => ['$attr$'],
293+
'_links' => ['$sp$']
294+
],
295+
as: 'cp'
296+
),
297+
DataFixture(BundleSelectionFixture::class, ['sku' => '$sp.sku$'], 'link1'),
298+
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$']], 'opt1'),
299+
DataFixture(
300+
BundleProductFixture::class,
301+
[
302+
'short_description' => 'Bundle Product Short Description',
303+
'sku' => 'bundle1',
304+
'_options' => ['$opt1$']
305+
],
306+
as:'bp'
307+
),
308+
]
309+
public function testItempropOnProductPage()
310+
{
311+
$product = $this->fixture->get('sp');
312+
$this->checkItemProp($product);
313+
$bundleProduct = $this->fixture->get('bp');
314+
$this->checkItemProp($bundleProduct);
315+
$configurableProduct = $this->fixture->get('cp');
316+
$this->checkItemProp($configurableProduct);
317+
}
318+
319+
/**
320+
* Validate presence of itemprop for image and description
321+
*
322+
* @param ProductInterface $product
323+
* @return void
324+
*/
325+
private function checkItemProp(ProductInterface $product)
326+
{
327+
$this->dispatch(sprintf('catalog/product/view/id/%s', $product->getId()));
328+
$html = $this->getResponse()->getBody();
329+
$this->assertNotEmpty(
330+
Xpath::getElementsCountForXpath(
331+
'//*[@itemprop="image"]',
332+
$html
333+
),
334+
'itemprop image doesn\'t match for product type '.$product->getTypeId()
335+
);
336+
$this->assertNotEmpty(
337+
Xpath::getElementsCountForXpath(
338+
'//*[@itemprop="description"]',
339+
$html
340+
),
341+
'itemprop description doesn\'t match for product type '.$product->getTypeId()
342+
);
343+
}
258344
}

0 commit comments

Comments
 (0)