Skip to content

Commit 8e43958

Browse files
committed
Merge remote-tracking branch 'origin/MC-20682' into 2.3-develop-com-pr5
2 parents b3b7eac + 3f77466 commit 8e43958

File tree

6 files changed

+376
-72
lines changed

6 files changed

+376
-72
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ViewTest.php

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Block\Product\View\Description;
1213
use Magento\Framework\ObjectManagerInterface;
1314
use Magento\Framework\Registry;
1415
use Magento\Framework\Serialize\Serializer\Json;
1516
use Magento\Framework\View\LayoutInterface;
17+
use Magento\Store\Model\StoreManagerInterface;
1618
use Magento\TestFramework\Helper\Bootstrap;
1719
use PHPUnit\Framework\TestCase;
1820

@@ -43,17 +45,35 @@ class ViewTest extends TestCase
4345
/** @var Json */
4446
private $json;
4547

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+
4664
/**
4765
* @inheritdoc
4866
*/
4967
protected function setUp()
5068
{
5169
$this->objectManager = Bootstrap::getObjectManager();
52-
$this->block = $this->objectManager->create(View::class);
5370
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
5471
$this->layout = $this->objectManager->get(LayoutInterface::class);
72+
$this->block = $this->layout->createBlock(View::class);
5573
$this->registry = $this->objectManager->get(Registry::class);
5674
$this->json = $this->objectManager->get(Json::class);
75+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
76+
$this->descriptionBlock = $this->layout->createBlock(Description::class);
5777
}
5878

5979
/**
@@ -179,6 +199,68 @@ public function testAddToCartBlockVisibility(): void
179199
$this->assertContains((string)__('Add to Cart'), $output);
180200
}
181201

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+
182264
/**
183265
* Register the product
184266
*

0 commit comments

Comments
 (0)