|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\PageBuilder\Block\Catalog\Product; |
| 9 | + |
| 10 | +use Magento\Framework\View\LayoutInterface; |
| 11 | +use Magento\Review\Block\Product\Review; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | +use Magento\Framework\View\Element\Template; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * PageBuilder Product view integration tests. |
| 18 | + * |
| 19 | + * @magentoAppArea frontend |
| 20 | + */ |
| 21 | +class ViewTest extends TestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @var string |
| 25 | + */ |
| 26 | + private $wrapperTemplatePath = 'Magento_PageBuilder::catalog/product/view/%s'; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var LayoutInterface |
| 30 | + */ |
| 31 | + private $layout; |
| 32 | + |
| 33 | + /** |
| 34 | + * @inheritDoc |
| 35 | + */ |
| 36 | + protected function setUp(): void |
| 37 | + { |
| 38 | + $this->layout = Bootstrap::getObjectManager()->get(LayoutInterface::class); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Check that Section Wrapper page contains section ID if it was provided. |
| 43 | + * |
| 44 | + * @param string $sectionId |
| 45 | + * @return void |
| 46 | + * @dataProvider sectionWrapperDataProvider |
| 47 | + */ |
| 48 | + public function testSectionWrapperWithProvidedSectionId(string $sectionId): void |
| 49 | + { |
| 50 | + $wrapperBlock = $this->prepareSectionWrapperBlock(); |
| 51 | + $wrapperBlock->setSectionId($sectionId); |
| 52 | + |
| 53 | + $this->assertStringContainsString(sprintf('id="%s"', $sectionId), $wrapperBlock->toHtml()); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Check that Section Wrapper page does NOT contain section ID if it was NOT provided. |
| 58 | + * |
| 59 | + * @param string $sectionId |
| 60 | + * @return void |
| 61 | + * @dataProvider sectionWrapperDataProvider |
| 62 | + */ |
| 63 | + public function testSectionWrapperWithoutSectionId(string $sectionId): void |
| 64 | + { |
| 65 | + $wrapperBlock = $this->prepareSectionWrapperBlock(); |
| 66 | + |
| 67 | + $this->assertStringNotContainsString(sprintf('id="%s"', $sectionId), $wrapperBlock->toHtml()); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * DataProvider for testSectionWrapper(). |
| 72 | + * |
| 73 | + * @return array |
| 74 | + */ |
| 75 | + public function sectionWrapperDataProvider(): array |
| 76 | + { |
| 77 | + return [ |
| 78 | + ['description'], |
| 79 | + ['additional'], |
| 80 | + ['reviews'], |
| 81 | + ]; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Create and retrieve Section Wrapper block instance. |
| 86 | + * |
| 87 | + * @return Template |
| 88 | + */ |
| 89 | + private function prepareSectionWrapperBlock(): Template |
| 90 | + { |
| 91 | + /** @var Template $wrapperBlock */ |
| 92 | + $wrapperBlock = $this->layout->createBlock(Template::class); |
| 93 | + $wrapperBlock->setTemplate( |
| 94 | + sprintf( |
| 95 | + $this->wrapperTemplatePath, |
| 96 | + 'section_wrapper.phtml' |
| 97 | + ) |
| 98 | + ); |
| 99 | + /** @var Review $childReviewBlock */ |
| 100 | + $childReviewBlock = $this->layout->createBlock(Review::class); |
| 101 | + $childReviewBlock->setTemplate('Magento_Review::review.phtml'); |
| 102 | + $wrapperBlock->setChild('child.review', $childReviewBlock); |
| 103 | + |
| 104 | + return $wrapperBlock; |
| 105 | + } |
| 106 | +} |
0 commit comments