Skip to content

Commit e18ee73

Browse files
authored
Merge pull request #6050 from magento-tsg/2.3-develop-com-pr24
[TSG-Commerce] Tests for 2.3 (pr24)
2 parents f5fba63 + 2ef1774 commit e18ee73

File tree

40 files changed

+1703
-188
lines changed

40 files changed

+1703
-188
lines changed

dev/tests/integration/testsuite/Magento/Checkout/_files/ValidatorFileMock.php renamed to dev/tests/integration/framework/Magento/TestFramework/Catalog/Model/Product/Option/Type/File/ValidatorFileMock.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Checkout\_files;
8+
namespace Magento\TestFramework\Catalog\Model\Product\Option\Type\File;
99

1010
use Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile;
11+
use PHPUnit\Framework\TestCase;
1112

1213
/**
1314
* Creates mock for ValidatorFile to replace real instance in fixtures.
1415
*/
15-
class ValidatorFileMock extends \PHPUnit\Framework\TestCase
16+
class ValidatorFileMock extends TestCase
1617
{
1718
/**
1819
* Returns mock.
20+
*
1921
* @param array|null $fileData
2022
* @return ValidatorFile|\PHPUnit_Framework_MockObject_MockObject
2123
*/

dev/tests/integration/testsuite/Magento/Bundle/Block/Catalog/Product/View/Type/AbstractBundleOptionsViewTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Registry;
1515
use Magento\Framework\Serialize\SerializerInterface;
1616
use Magento\Framework\View\Result\PageFactory;
17+
use Magento\Store\Model\StoreManagerInterface;
1718
use Magento\TestFramework\Helper\Bootstrap;
1819
use Magento\TestFramework\Helper\Xpath;
1920
use PHPUnit\Framework\TestCase;
@@ -24,7 +25,7 @@
2425
abstract class AbstractBundleOptionsViewTest extends TestCase
2526
{
2627
/** @var ObjectManagerInterface */
27-
private $objectManager;
28+
protected $objectManager;
2829

2930
/** @var ProductRepositoryInterface */
3031
private $productRepository;
@@ -41,6 +42,9 @@ abstract class AbstractBundleOptionsViewTest extends TestCase
4142
/** @var ProductResource */
4243
private $productResource;
4344

45+
/** @var StoreManagerInterface */
46+
private $storeManager;
47+
4448
/** @var string */
4549
private $selectLabelXpath = "//fieldset[contains(@class, 'fieldset-bundle-options')]"
4650
. "//label/span[normalize-space(text()) = '%s']";
@@ -68,6 +72,7 @@ protected function setUp()
6872
$this->registry = $this->objectManager->get(Registry::class);
6973
$this->pageFactory = $this->objectManager->get(PageFactory::class);
7074
$this->productResource = $this->objectManager->get(ProductResource::class);
75+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
7176
}
7277

7378
/**
@@ -90,13 +95,13 @@ protected function tearDown()
9095
* @param bool $requiredOption
9196
* @return void
9297
*/
93-
protected function processMultiSelectionsView(
98+
public function processMultiSelectionsView(
9499
string $sku,
95100
string $optionsSelectLabel,
96101
array $expectedSelectionsNames,
97102
bool $requiredOption = false
98103
): void {
99-
$product = $this->productRepository->get($sku);
104+
$product = $this->productRepository->get($sku, false, $this->storeManager->getStore()->getId(), true);
100105
$result = $this->renderProductOptionsBlock($product);
101106
$this->assertEquals(
102107
1,
@@ -132,7 +137,7 @@ protected function processMultiSelectionsView(
132137
*/
133138
protected function processSingleSelectionView(string $sku, string $optionsSelectLabel): void
134139
{
135-
$product = $this->productRepository->get($sku);
140+
$product = $this->productRepository->get($sku, false, $this->storeManager->getStore()->getId(), true);
136141
$result = $this->renderProductOptionsBlock($product);
137142
$this->assertEquals(1, Xpath::getElementsCountForXpath($this->backToProductDetailButtonXpath, $result));
138143
$this->assertEquals(

dev/tests/integration/testsuite/Magento/Bundle/Block/Catalog/Product/View/Type/BundleProductPriceTest.php

Lines changed: 155 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
99

10+
use Magento\Bundle\Pricing\Price\BundleOptions;
1011
use Magento\Catalog\Api\ProductRepositoryInterface;
1112
use Magento\Framework\ObjectManagerInterface;
1213
use Magento\Framework\Registry;
1314
use Magento\Framework\Serialize\SerializerInterface;
14-
use Magento\Framework\View\LayoutInterface;
15+
use Magento\Framework\View\Result\Page;
16+
use Magento\Framework\View\Result\PageFactory;
17+
use Magento\Store\Model\StoreManagerInterface;
1518
use Magento\TestFramework\Helper\Bootstrap;
19+
use Magento\TestFramework\Store\ExecuteInStoreContext;
1620
use PHPUnit\Framework\TestCase;
1721

1822
/**
@@ -36,8 +40,14 @@ class BundleProductPriceTest extends TestCase
3640
/** @var SerializerInterface */
3741
private $json;
3842

39-
/** @var Bundle */
40-
private $block;
43+
/** @var ExecuteInStoreContext */
44+
private $executeInStoreContext;
45+
46+
/** @var StoreManagerInterface */
47+
private $storeManager;
48+
49+
/** @var PageFactory */
50+
private $pageFactory;
4151

4252
/**
4353
* @inheritdoc
@@ -49,9 +59,11 @@ protected function setUp()
4959
$this->objectManager = Bootstrap::getObjectManager();
5060
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
5161
$this->productRepository->cleanCache();
52-
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Bundle::class);
5362
$this->registry = $this->objectManager->get(Registry::class);
5463
$this->json = $this->objectManager->get(SerializerInterface::class);
64+
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
65+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
66+
$this->pageFactory = $this->objectManager->get(PageFactory::class);
5567
}
5668

5769
/**
@@ -98,6 +110,63 @@ public function testDynamicBundleOptionPrices(): void
98110
$this->processBundlePriceView('bundle_product', $expectedData);
99111
}
100112

113+
/**
114+
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_on_second_website.php
115+
* @magentoDbIsolation disabled
116+
* @magentoAppIsolation enabled
117+
*
118+
* @return void
119+
*/
120+
public function testDynamicBundleOptionPricesOnSecondWebsite(): void
121+
{
122+
$this->executeInStoreContext->execute(
123+
'fixture_second_store',
124+
[$this, 'processBundlePriceView'],
125+
'dynamic_bundle_product_with_special_price',
126+
[
127+
'options_prices' => [
128+
[
129+
'oldPrice' => ['amount' => 20],
130+
'basePrice' => ['amount' => 7.5],
131+
'finalPrice' => ['amount' => 7.5],
132+
],
133+
[
134+
'oldPrice' => ['amount' => 40],
135+
'basePrice' => ['amount' => 22.5],
136+
'finalPrice' => ['amount' => 22.5],
137+
],
138+
],
139+
'bundle_prices' => [
140+
'oldPrice' => ['amount' => 0],
141+
'basePrice' => ['amount' => 0],
142+
'finalPrice' => ['amount' => 0],
143+
]
144+
]
145+
);
146+
$this->processBundlePriceView(
147+
'dynamic_bundle_product_with_special_price',
148+
[
149+
'options_prices' => [
150+
[
151+
'oldPrice' => ['amount' => 10],
152+
'basePrice' => ['amount' => 7.5],
153+
'finalPrice' => ['amount' => 7.5],
154+
],
155+
[
156+
'oldPrice' => ['amount' => 20],
157+
'basePrice' => ['amount' => 15],
158+
'finalPrice' => ['amount' => 15],
159+
],
160+
],
161+
'bundle_prices' => [
162+
'oldPrice' => ['amount' => 0],
163+
'basePrice' => ['amount' => 0],
164+
'finalPrice' => ['amount' => 0],
165+
]
166+
]
167+
);
168+
}
169+
101170
/**
102171
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options_1.php
103172
*
@@ -128,14 +197,93 @@ public function testFixedBundleOptionPrices(): void
128197
}
129198

130199
/**
200+
* @magentoDataFixture Magento/Bundle/_files/fixed_bundle_product_on_second_website.php
201+
* @magentoDbIsolation disabled
202+
* @magentoAppIsolation enabled
203+
*
204+
* @return void
205+
*/
206+
public function testFixedBundleOptionPricesOnSecondWebsite(): void
207+
{
208+
$this->executeInStoreContext->execute(
209+
'fixture_second_store',
210+
[$this, 'processBundlePriceView'],
211+
'fixed_bundle_product_with_special_price',
212+
[
213+
'options_prices' => [
214+
[
215+
'oldPrice' => ['amount' => 10],
216+
'basePrice' => ['amount' => 3],
217+
'finalPrice' => ['amount' => 3],
218+
],
219+
[
220+
'oldPrice' => ['amount' => 10],
221+
'basePrice' => ['amount' => 3],
222+
'finalPrice' => ['amount' => 3],
223+
],
224+
[
225+
'oldPrice' => ['amount' => 25],
226+
'basePrice' => ['amount' => 7.5],
227+
'finalPrice' => ['amount' => 7.5],
228+
],
229+
],
230+
'bundle_prices' => [
231+
'oldPrice' => ['amount' => 50],
232+
'basePrice' => ['amount' => 30],
233+
'finalPrice' => ['amount' => 30],
234+
]
235+
]
236+
);
237+
$this->processBundlePriceView(
238+
'fixed_bundle_product_with_special_price',
239+
[
240+
'options_prices' => [
241+
[
242+
'oldPrice' => ['amount' => 10],
243+
'basePrice' => ['amount' => 8],
244+
'finalPrice' => ['amount' => 8],
245+
],
246+
[
247+
'oldPrice' => ['amount' => 12.5],
248+
'basePrice' => ['amount' => 10],
249+
'finalPrice' => ['amount' => 10],
250+
],
251+
[
252+
'oldPrice' => ['amount' => 25],
253+
'basePrice' => ['amount' => 20],
254+
'finalPrice' => ['amount' => 20],
255+
],
256+
],
257+
'bundle_prices' => [
258+
'oldPrice' => ['amount' => 60],
259+
'basePrice' => ['amount' => 50],
260+
'finalPrice' => ['amount' => 50],
261+
]
262+
]
263+
);
264+
}
265+
266+
/**
267+
* Asserts bundle product prices from price block.
268+
*
131269
* @param string $productSku
132270
* @param array $expectedData
133271
* @return void
134272
*/
135-
private function processBundlePriceView(string $productSku, array $expectedData): void
273+
public function processBundlePriceView(string $productSku, array $expectedData): void
136274
{
275+
$this->objectManager->removeSharedInstance(BundleOptions::class);
137276
$this->registerProduct($productSku);
138-
$jsonConfig = $this->json->unserialize($this->block->getJsonConfig());
277+
/** @var Page $page */
278+
$page = $this->pageFactory->create();
279+
$page->addHandle([
280+
'default',
281+
'catalog_product_view',
282+
'catalog_product_view_type_bundle',
283+
]);
284+
$page->getLayout()->generateXml();
285+
$block = $page->getLayout()->getBlock('product.info.bundle.options');
286+
$jsonConfig = $this->json->unserialize($block->getJsonConfig());
139287
$this->assertEquals($expectedData['bundle_prices'], $jsonConfig['prices']);
140288
$this->assertOptionsConfig($expectedData['options_prices'], $jsonConfig);
141289
}
@@ -165,7 +313,7 @@ private function assertOptionsConfig(array $expectedData, array $actualData): vo
165313
*/
166314
private function registerProduct(string $productSku): void
167315
{
168-
$product = $this->productRepository->get($productSku);
316+
$product = $this->productRepository->get($productSku, false, $this->storeManager->getStore()->getId(), true);
169317
$this->registry->unregister('product');
170318
$this->registry->register('product', $product);
171319
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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\Bundle\Block\Catalog\Product\View\Type;
9+
10+
use Magento\TestFramework\Store\ExecuteInStoreContext;
11+
12+
/**
13+
* Class checks checkbox bundle options appearance on second store view.
14+
*
15+
* @magentoAppArea frontend
16+
* @magentoAppIsolation enabled
17+
* @magentoDbIsolation disabled
18+
*/
19+
class OptionViewOnStoreTest extends AbstractBundleOptionsViewTest
20+
{
21+
/**
22+
* @var ExecuteInStoreContext
23+
*/
24+
private $executeInStoreContext;
25+
26+
/**
27+
* @inheridoc
28+
*/
29+
protected function setUp()
30+
{
31+
parent::setUp();
32+
33+
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
34+
}
35+
36+
/**
37+
* @magentoDataFixture Magento/Bundle/_files/fixed_bundle_product_on_second_website.php
38+
*
39+
* @return void
40+
*/
41+
public function testOptionsViewOnSecondStore(): void
42+
{
43+
$this->executeInStoreContext->execute(
44+
'fixture_second_store',
45+
[$this, 'processMultiSelectionsView'],
46+
'fixed_bundle_product_with_special_price',
47+
'Option 1 on second store',
48+
['Simple Product', 'Simple Product2', 'Simple Product 3'],
49+
true
50+
);
51+
$this->processMultiSelectionsView(
52+
'fixed_bundle_product_with_special_price',
53+
'Option 1',
54+
['Simple Product', 'Simple Product2', 'Simple Product 3'],
55+
true
56+
);
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
protected function getRequiredSelectXpath(): string
63+
{
64+
return "//input[@type='radio' and contains(@data-validate, 'validate-one-required-by-name')"
65+
. "and contains(@class, 'bundle option')]/../label//span[normalize-space(text()) = '%s']";
66+
}
67+
68+
/**
69+
* @inheritdoc
70+
*/
71+
protected function getNotRequiredSelectXpath(): string
72+
{
73+
return '';
74+
}
75+
}

0 commit comments

Comments
 (0)