77
88namespace 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 ;
1013use Magento \Catalog \Api \Data \ProductInterface ;
1114use Magento \Catalog \Api \ProductRepositoryInterface ;
15+ use Magento \ConfigurableProduct \Test \Fixture \Attribute as AttributeFixture ;
16+ use Magento \ConfigurableProduct \Test \Fixture \Product as ConfigurableProductFixture ;
1217use Magento \Catalog \Model \Session ;
18+ use Magento \Catalog \Test \Fixture \Category ;
19+ use Magento \Catalog \Test \Fixture \Product ;
1320use Magento \Framework \Registry ;
1421use Magento \TestFramework \Catalog \Model \ProductLayoutUpdateManager ;
22+ use Magento \TestFramework \Fixture \DataFixture ;
23+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
24+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
1525use Magento \TestFramework \Helper \Bootstrap ;
1626use Magento \TestFramework \Helper \Xpath ;
1727use 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