7
7
8
8
namespace Magento \Catalog \Controller ;
9
9
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 ;
10
13
use Magento \Catalog \Api \Data \ProductInterface ;
11
14
use Magento \Catalog \Api \ProductRepositoryInterface ;
15
+ use Magento \ConfigurableProduct \Test \Fixture \Attribute as AttributeFixture ;
16
+ use Magento \ConfigurableProduct \Test \Fixture \Product as ConfigurableProductFixture ;
12
17
use Magento \Catalog \Model \Session ;
18
+ use Magento \Catalog \Test \Fixture \Category ;
19
+ use Magento \Catalog \Test \Fixture \Product ;
13
20
use Magento \Framework \Registry ;
14
21
use Magento \TestFramework \Catalog \Model \ProductLayoutUpdateManager ;
22
+ use Magento \TestFramework \Fixture \DataFixture ;
23
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
24
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
15
25
use Magento \TestFramework \Helper \Bootstrap ;
16
26
use Magento \TestFramework \Helper \Xpath ;
17
27
use Magento \TestFramework \TestCase \AbstractController ;
@@ -34,6 +44,11 @@ class ProductTest extends AbstractController
34
44
/** @var Session */
35
45
private $ session ;
36
46
47
+ /**
48
+ * @var DataFixtureStorage
49
+ */
50
+ private $ fixture ;
51
+
37
52
/**
38
53
* @inheritdoc
39
54
*/
@@ -53,6 +68,7 @@ protected function setUp(): void
53
68
$ this ->registry = $ this ->_objectManager ->get (Registry::class);
54
69
$ this ->productRepository = $ this ->_objectManager ->get (ProductRepositoryInterface::class);
55
70
$ this ->session = $ this ->_objectManager ->get (Session::class);
71
+ $ this ->fixture = DataFixtureStorageManager::getStorage ();
56
72
}
57
73
58
74
/**
@@ -255,4 +271,74 @@ public function testViewWithCustomUpdate(): void
255
271
->getHandles ();
256
272
$ this ->assertContains ("catalog_product_view_selectable_ {$ sku }_ {$ file }" , $ handles );
257
273
}
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
+ }
258
344
}
0 commit comments