|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Api\Data\ProductInterface;
|
11 | 11 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
| 12 | +use Magento\Catalog\Block\Product\View\Description; |
12 | 13 | use Magento\Framework\ObjectManagerInterface;
|
13 | 14 | use Magento\Framework\Registry;
|
14 | 15 | use Magento\Framework\Serialize\Serializer\Json;
|
15 | 16 | use Magento\Framework\View\LayoutInterface;
|
| 17 | +use Magento\Store\Model\StoreManagerInterface; |
16 | 18 | use Magento\TestFramework\Helper\Bootstrap;
|
17 | 19 | use PHPUnit\Framework\TestCase;
|
18 | 20 |
|
@@ -43,17 +45,35 @@ class ViewTest extends TestCase
|
43 | 45 | /** @var Json */
|
44 | 46 | private $json;
|
45 | 47 |
|
| 48 | + /** @var StoreManagerInterface */ |
| 49 | + private $storeManager; |
| 50 | + |
| 51 | + /** @var Description */ |
| 52 | + private $descriptionBlock; |
| 53 | + |
| 54 | + /** @var array */ |
| 55 | + private const SHORT_DESCRIPTION_BLOCK_DATA = [ |
| 56 | + 'at_call' => 'getShortDescription', |
| 57 | + 'at_code' => 'short_description', |
| 58 | + 'overview' => 'overview', |
| 59 | + 'at_label' => 'none', |
| 60 | + 'title' => 'Overview', |
| 61 | + 'add_attribute' => 'description', |
| 62 | + ]; |
| 63 | + |
46 | 64 | /**
|
47 | 65 | * @inheritdoc
|
48 | 66 | */
|
49 | 67 | protected function setUp()
|
50 | 68 | {
|
51 | 69 | $this->objectManager = Bootstrap::getObjectManager();
|
52 |
| - $this->block = $this->objectManager->create(View::class); |
53 | 70 | $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
|
54 | 71 | $this->layout = $this->objectManager->get(LayoutInterface::class);
|
| 72 | + $this->block = $this->layout->createBlock(View::class); |
55 | 73 | $this->registry = $this->objectManager->get(Registry::class);
|
56 | 74 | $this->json = $this->objectManager->get(Json::class);
|
| 75 | + $this->storeManager = $this->objectManager->get(StoreManagerInterface::class); |
| 76 | + $this->descriptionBlock = $this->layout->createBlock(Description::class); |
57 | 77 | }
|
58 | 78 |
|
59 | 79 | /**
|
@@ -179,6 +199,68 @@ public function testAddToCartBlockVisibility(): void
|
179 | 199 | $this->assertContains((string)__('Add to Cart'), $output);
|
180 | 200 | }
|
181 | 201 |
|
| 202 | + /** |
| 203 | + * @magentoDbIsolation disabled |
| 204 | + * @magentoAppArea frontend |
| 205 | + * @magentoDataFixture Magento/Catalog/_files/product_multistore_different_short_description.php |
| 206 | + * @return void |
| 207 | + */ |
| 208 | + public function testProductShortDescription(): void |
| 209 | + { |
| 210 | + $product = $this->productRepository->get('simple-different-short-description'); |
| 211 | + $currentStoreId = $this->storeManager->getStore()->getId(); |
| 212 | + $output = $this->renderDescriptionBlock($product); |
| 213 | + |
| 214 | + $this->assertContains('First store view short description', $output); |
| 215 | + |
| 216 | + $secondStore = $this->storeManager->getStore('fixturestore'); |
| 217 | + $this->storeManager->setCurrentStore($secondStore->getId()); |
| 218 | + |
| 219 | + try { |
| 220 | + $product = $this->productRepository->get( |
| 221 | + 'simple-different-short-description', |
| 222 | + false, |
| 223 | + $secondStore->getId(), |
| 224 | + true |
| 225 | + ); |
| 226 | + $newBlockOutput = $this->renderDescriptionBlock($product, true); |
| 227 | + |
| 228 | + $this->assertContains('Second store view short description', $newBlockOutput); |
| 229 | + } finally { |
| 230 | + $this->storeManager->setCurrentStore($currentStoreId); |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + /** |
| 235 | + * @param ProductInterface $product |
| 236 | + * @param bool $refreshBlock |
| 237 | + * @return string |
| 238 | + */ |
| 239 | + private function renderDescriptionBlock(ProductInterface $product, bool $refreshBlock = false): string |
| 240 | + { |
| 241 | + $this->registerProduct($product); |
| 242 | + $descriptionBlock = $this->getDescriptionBlock($refreshBlock); |
| 243 | + $descriptionBlock->addData(self::SHORT_DESCRIPTION_BLOCK_DATA); |
| 244 | + $descriptionBlock->setTemplate('Magento_Catalog::product/view/attribute.phtml'); |
| 245 | + |
| 246 | + return $this->descriptionBlock->toHtml(); |
| 247 | + } |
| 248 | + |
| 249 | + /** |
| 250 | + * Get description block |
| 251 | + * |
| 252 | + * @param bool $refreshBlock |
| 253 | + * @return Description |
| 254 | + */ |
| 255 | + private function getDescriptionBlock(bool $refreshBlock): Description |
| 256 | + { |
| 257 | + if ($refreshBlock) { |
| 258 | + $this->descriptionBlock = $this->layout->createBlock(Description::class); |
| 259 | + } |
| 260 | + |
| 261 | + return $this->descriptionBlock; |
| 262 | + } |
| 263 | + |
182 | 264 | /**
|
183 | 265 | * Register the product
|
184 | 266 | *
|
|
0 commit comments