Skip to content

Commit 4b428b6

Browse files
authored
Merge pull request #5893 from magento-tsg/2.3-develop-com-pr22
[TSG-Commerce] Tests for 2.3 (pr22)
2 parents 1bcbcfe + d2c7d9e commit 4b428b6

File tree

47 files changed

+2785
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2785
-307
lines changed

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

Lines changed: 128 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,46 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Block\Product;
79

10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Pricing\Price\FinalPrice;
13+
use Magento\Framework\Pricing\Render;
14+
use Magento\Framework\Serialize\SerializerInterface;
15+
use Magento\Framework\View\DesignInterface;
16+
use Magento\Framework\View\LayoutInterface;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use Magento\TestFramework\ObjectManager;
19+
use PHPUnit\Framework\TestCase;
20+
821
/**
922
* Test class for \Magento\Catalog\Block\Product\Abstract.
1023
*
1124
* @magentoDataFixture Magento/Catalog/_files/product_with_image.php
1225
* @magentoAppArea frontend
1326
*/
14-
class AbstractTest extends \PHPUnit\Framework\TestCase
27+
class AbstractTest extends TestCase
1528
{
1629
/**
1730
* Stub class name for class under test
1831
*/
1932
const STUB_CLASS = 'Magento_Catalog_Block_Product_AbstractProduct_Stub';
2033

2134
/**
22-
* @var \Magento\Catalog\Block\Product\AbstractProduct
35+
* @var AbstractProduct
2336
*/
2437
protected $block;
2538

2639
/**
27-
* @var \Magento\Catalog\Model\Product
40+
* @var ProductInterface
2841
*/
2942
protected $product;
3043

3144
/**
32-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
45+
* @var ProductRepositoryInterface
3346
*/
3447
protected $productRepository;
3548

@@ -40,62 +53,89 @@ class AbstractTest extends \PHPUnit\Framework\TestCase
4053
*/
4154
protected static $isStubClass = false;
4255

56+
/**
57+
* @var ObjectManager
58+
*/
59+
private $objectManager;
60+
61+
/**
62+
* @var LayoutInterface
63+
*/
64+
private $layout;
65+
66+
/**
67+
* @var SerializerInterface
68+
*/
69+
private $json;
70+
71+
/**
72+
* @inheritdoc
73+
*/
4374
protected function setUp()
4475
{
4576
if (!self::$isStubClass) {
4677
$this->getMockForAbstractClass(
47-
\Magento\Catalog\Block\Product\AbstractProduct::class,
78+
AbstractProduct::class,
4879
[],
4980
self::STUB_CLASS,
5081
false
5182
);
5283
self::$isStubClass = true;
5384
}
54-
55-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
56-
57-
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
58-
$objectManager->get(\Magento\Framework\View\DesignInterface::class)->setDefaultDesignTheme();
59-
$this->block = $objectManager->get(
60-
\Magento\Framework\View\LayoutInterface::class
61-
)->createBlock(self::STUB_CLASS);
62-
$this->productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
63-
64-
$this->product = $this->productRepository->get('simple');
65-
$this->product->addData(
66-
[
67-
'image' => '/m/a/magento_image.jpg',
68-
'small_image' => '/m/a/magento_image.jpg',
69-
'thumbnail' => '/m/a/magento_image.jpg',
70-
]
71-
);
72-
$this->block->setProduct($this->product);
85+
$this->objectManager = Bootstrap::getObjectManager();
86+
$this->objectManager->get(DesignInterface::class)->setDefaultDesignTheme();
87+
$this->layout = $this->objectManager->get(LayoutInterface::class);
88+
$this->block = $this->layout->createBlock(self::STUB_CLASS);
89+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
90+
$this->productRepository->cleanCache();
91+
$this->json = $this->objectManager->get(SerializerInterface::class);
7392
}
7493

7594
/**
7695
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_simple.php
7796
* @magentoAppIsolation enabled
97+
* @return void
7898
*/
79-
public function testGetAddToCartUrl()
99+
public function testGetAddToCartUrlWithProductRequiredOptions(): void
80100
{
81101
$product = $this->productRepository->get('simple');
82102
$url = $this->block->getAddToCartUrl($product);
83103
$this->assertStringEndsWith('?options=cart', $url);
84104
$this->assertStringMatchesFormat('%ssimple-product.html%s', $url);
85105
}
86106

87-
public function testGetSubmitUrl()
107+
/**
108+
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
109+
* @return void
110+
*/
111+
public function testGetAddToCartUrlWithSimpleProduct(): void
112+
{
113+
$product = $this->productRepository->get('simple-1');
114+
$url = $this->block->getAddToCartUrl($product);
115+
$this->assertStringEndsWith(sprintf('product/%s/', $product->getId()), $url);
116+
$this->assertContains('checkout/cart/add', $url);
117+
}
118+
119+
/**
120+
* @return void
121+
*/
122+
public function testGetSubmitUrl(): void
88123
{
124+
$this->product = $this->productRepository->get('simple');
89125
/* by default same as add to cart */
90126
$this->assertStringEndsWith('?options=cart', $this->block->getSubmitUrl($this->product));
91127
$this->block->setData('submit_route_data', ['route' => 'catalog/product/view']);
92128
$this->assertStringEndsWith('catalog/product/view/', $this->block->getSubmitUrl($this->product));
93129
}
94130

95-
public function testGetAddToWishlistParams()
131+
/**
132+
* @return void
133+
*/
134+
public function testGetAddToWishlistParams(): void
96135
{
136+
$this->product = $this->productRepository->get('simple');
97137
$json = $this->block->getAddToWishlistParams($this->product);
98-
$params = (array)json_decode($json);
138+
$params = (array)$this->json->unserialize($json);
99139
$data = (array)$params['data'];
100140
$this->assertEquals($this->product->getId(), $data['product']);
101141
$this->assertArrayHasKey('uenc', $data);
@@ -105,53 +145,70 @@ public function testGetAddToWishlistParams()
105145
);
106146
}
107147

108-
public function testGetAddToCompareUrl()
148+
/**
149+
* @return void
150+
*/
151+
public function testGetAddToCompareUrl(): void
109152
{
110153
$this->assertStringMatchesFormat('%scatalog/product_compare/add/', $this->block->getAddToCompareUrl());
111154
}
112155

113-
public function testGetMinimalQty()
156+
/**
157+
* @return void
158+
*/
159+
public function testGetMinimalQty(): void
114160
{
161+
$this->product = $this->productRepository->get('simple');
115162
$this->assertGreaterThan(0, $this->block->getMinimalQty($this->product));
116163
}
117164

118-
public function testGetReviewsSummaryHtml()
165+
/**
166+
* @return void
167+
*/
168+
public function testGetReviewsSummaryHtml(): void
119169
{
120-
$this->block->setLayout(
121-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
122-
->get(\Magento\Framework\View\LayoutInterface::class)
123-
);
170+
$this->product = $this->productRepository->get('simple');
124171
$html = $this->block->getReviewsSummaryHtml($this->product, false, true);
125172
$this->assertNotEmpty($html);
126173
$this->assertContains('review', $html);
127174
}
128175

129-
public function testGetProduct()
176+
/**
177+
* @return void
178+
*/
179+
public function testGetProduct(): void
130180
{
181+
$this->product = $this->productRepository->get('simple');
182+
$this->block->setProduct($this->product);
131183
$this->assertSame($this->product, $this->block->getProduct());
132184
}
133185

134186
/**
135187
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_simple.php
136188
* @magentoAppIsolation enabled
189+
* @return void
137190
*/
138-
public function testGetProductUrl()
191+
public function testGetProductUrl(): void
139192
{
140193
$product = $this->productRepository->get('simple');
141194
$this->assertStringEndsWith('simple-product.html', $this->block->getProductUrl($product));
142195
}
143196

144-
public function testHasProductUrl()
197+
/**
198+
* @return void
199+
*/
200+
public function testHasProductUrl(): void
145201
{
202+
$this->product = $this->productRepository->get('simple');
146203
$this->assertTrue($this->block->hasProductUrl($this->product));
147204
}
148205

149-
public function testLayoutDependColumnCount()
206+
/**
207+
* @return void
208+
*/
209+
public function testLayoutDependColumnCount(): void
150210
{
151-
$this->block->setLayout(
152-
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
153-
->get(\Magento\Framework\View\LayoutInterface::class)
154-
);
211+
$this->block->setLayout($this->layout);
155212
$this->assertEquals(3, $this->block->getColumnCount());
156213
/* default column count */
157214

@@ -161,8 +218,35 @@ public function testLayoutDependColumnCount()
161218
$this->assertFalse($this->block->getColumnCountLayoutDepend('test'));
162219
}
163220

164-
public function testGetCanShowProductPrice()
221+
/**
222+
* @return void
223+
*/
224+
public function testGetCanShowProductPrice(): void
165225
{
226+
$this->product = $this->productRepository->get('simple');
166227
$this->assertTrue($this->block->getCanShowProductPrice($this->product));
167228
}
229+
230+
/**
231+
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
232+
* @return void
233+
*/
234+
public function testGetProductPriceHtml(): void
235+
{
236+
$product = $this->productRepository->get('simple-1');
237+
$this->assertEmpty($this->block->getProductPriceHtml($product, FinalPrice::PRICE_CODE));
238+
$this->layout->createBlock(
239+
Render::class,
240+
'product.price.render.default',
241+
[
242+
'data' => [
243+
'price_render_handle' => 'catalog_product_prices',
244+
'use_link_for_as_low_as' => true,
245+
],
246+
]
247+
);
248+
$finalPriceHtml = $this->block->getProductPriceHtml($product, FinalPrice::PRICE_CODE);
249+
$this->assertContains('price-' . FinalPrice::PRICE_CODE, $finalPriceHtml);
250+
$this->assertContains('product-price-' . $product->getId(), $finalPriceHtml);
251+
}
168252
}

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ProductList/AbstractLinksTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ abstract class AbstractLinksTest extends TestCase
6666
/** @var string */
6767
protected $linkType;
6868

69+
/** @var string */
70+
protected $titleName;
71+
72+
/** @var string */
73+
protected $titleXpath = "//strong[@id = 'block-%s-heading'][contains(text(), '%s')]";
74+
6975
/**
7076
* @inheritdoc
7177
*/
@@ -297,7 +303,7 @@ protected function linkProducts(string $sku, array $productLinks): void
297303
*
298304
* @return array
299305
*/
300-
protected function prepareWebsiteIdsProducts(): array
306+
protected function prepareProductsWebsiteIds(): array
301307
{
302308
$websiteId = $this->storeManager->getWebsite('test')->getId();
303309
$defaultWebsiteId = $this->storeManager->getWebsite('base')->getId();

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ProductList/RelatedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testPositionRelatedProducts(): void
132132
*/
133133
public function testMultipleWebsitesRelatedProducts(array $data): void
134134
{
135-
$this->updateProducts($this->prepareWebsiteIdsProducts());
135+
$this->updateProducts($this->prepareProductsWebsiteIds());
136136
$productLinks = array_replace_recursive($this->existingProducts, $data['productLinks']);
137137
$this->linkProducts('simple-1', $productLinks);
138138
$this->product = $this->productRepository->get(

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ProductList/UpsellTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testPositionUpsellProducts(): void
120120
*/
121121
public function testMultipleWebsitesUpsellProducts(array $data): void
122122
{
123-
$this->updateProducts($this->prepareWebsiteIdsProducts());
123+
$this->updateProducts($this->prepareProductsWebsiteIds());
124124
$productLinks = array_replace_recursive($this->existingProducts, $data['productLinks']);
125125
$this->linkProducts('simple-1', $productLinks);
126126
$this->product = $this->productRepository->get(

0 commit comments

Comments
 (0)