|
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;
|
13 | 18 | use Magento\Catalog\Test\Fixture\Category;
|
14 | 19 | use Magento\Catalog\Test\Fixture\Product;
|
@@ -267,32 +272,73 @@ public function testViewWithCustomUpdate(): void
|
267 | 272 | $this->assertContains("catalog_product_view_selectable_{$sku}_{$file}", $handles);
|
268 | 273 | }
|
269 | 274 |
|
| 275 | + /** |
| 276 | + * Validate itemprop generation on different product types' page |
| 277 | + * |
| 278 | + * @return void |
| 279 | + */ |
270 | 280 | #[
|
271 | 281 | DataFixture(Category::class, as: 'category'),
|
272 | 282 | DataFixture(
|
273 | 283 | Product::class,
|
274 | 284 | ['category_ids' => ['$category.id$'], 'short_description' => 'Product Short Description'],
|
275 |
| - as: 'product' |
276 |
| - ) |
| 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 | + ), |
277 | 308 | ]
|
278 | 309 | public function testItempropOnProductPage()
|
279 | 310 | {
|
280 |
| - $product = $this->fixture->get('product'); |
281 |
| - $this->dispatch(sprintf('catalog/product/view/id/%s', $product->getEntityId())); |
| 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())); |
282 | 328 | $html = $this->getResponse()->getBody();
|
283 |
| - $this->assertEquals( |
284 |
| - 1, |
| 329 | + $this->assertNotEmpty( |
285 | 330 | Xpath::getElementsCountForXpath(
|
286 | 331 | '//*[@itemprop="image"]',
|
287 | 332 | $html
|
288 |
| - ) |
| 333 | + ), |
| 334 | + 'itemprop image doesn\'t match for product type '.$product->getTypeId() |
289 | 335 | );
|
290 |
| - $this->assertEquals( |
291 |
| - 1, |
| 336 | + $this->assertNotEmpty( |
292 | 337 | Xpath::getElementsCountForXpath(
|
293 | 338 | '//*[@itemprop="description"]',
|
294 | 339 | $html
|
295 |
| - ) |
| 340 | + ), |
| 341 | + 'itemprop description doesn\'t match for product type '.$product->getTypeId() |
296 | 342 | );
|
297 | 343 | }
|
298 | 344 | }
|
0 commit comments