Skip to content

Commit cb29678

Browse files
committed
Merge remote-tracking branch 'tango/MC-33512' into Chaika-PR-2020-05-21
2 parents 90f29d6 + b9ca779 commit cb29678

File tree

1 file changed

+106
-39
lines changed

1 file changed

+106
-39
lines changed

dev/tests/api-functional/testsuite/Magento/Catalog/Api/SpecialPriceStorageTest.php

Lines changed: 106 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@
55
*/
66
namespace Magento\Catalog\Api;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Framework\Exception\CouldNotSaveException;
10+
use Magento\Framework\Exception\InputException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\Exception\StateException;
13+
use Magento\Framework\Webapi\Rest\Request;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\ObjectManager;
816
use Magento\TestFramework\TestCase\WebapiAbstract;
9-
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
1017

1118
/**
12-
* SpecialPriceStorage test.
19+
* SpecialPriceStorage API operations test
1320
*/
1421
class SpecialPriceStorageTest extends WebapiAbstract
1522
{
1623
const SERVICE_NAME = 'catalogSpecialPriceStorageV1';
1724
const SERVICE_VERSION = 'V1';
1825
const SIMPLE_PRODUCT_SKU = 'simple';
26+
const VIRTUAL_PRODUCT_SKU = 'virtual-product';
1927

2028
/**
21-
* @var \Magento\TestFramework\ObjectManager
29+
* @var ObjectManager
2230
*/
2331
private $objectManager;
2432

@@ -27,7 +35,7 @@ class SpecialPriceStorageTest extends WebapiAbstract
2735
*/
2836
protected function setUp()
2937
{
30-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
38+
$this->objectManager = Bootstrap::getObjectManager();
3139
}
3240

3341
/**
@@ -38,14 +46,14 @@ protected function setUp()
3846
public function testGet()
3947
{
4048
$specialPrice = 3057;
41-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
49+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
4250
$product = $productRepository->get(self::SIMPLE_PRODUCT_SKU, true);
4351
$product->setData('special_price', $specialPrice);
4452
$productRepository->save($product);
4553
$serviceInfo = [
4654
'rest' => [
4755
'resourcePath' => '/V1/products/special-price-information',
48-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST
56+
'httpMethod' => Request::HTTP_METHOD_POST
4957
],
5058
'soap' => [
5159
'service' => self::SERVICE_NAME,
@@ -54,7 +62,7 @@ public function testGet()
5462
],
5563
];
5664
$response = $this->_webApiCall($serviceInfo, ['skus' => [self::SIMPLE_PRODUCT_SKU]]);
57-
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */
65+
/** @var ProductInterface $product */
5866
$product = $productRepository->get(self::SIMPLE_PRODUCT_SKU);
5967
$this->assertNotEmpty($response);
6068
$this->assertEquals($product->getSpecialPrice(), $response[0]['price']);
@@ -64,34 +72,27 @@ public function testGet()
6472
* Test update method.
6573
*
6674
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
75+
* @dataProvider updateData
76+
* @param array $data
6777
*/
68-
public function testUpdate()
78+
public function testUpdate(array $data)
6979
{
70-
$sku = 'virtual-product';
7180
$serviceInfo = [
7281
'rest' => [
7382
'resourcePath' => '/V1/products/special-price',
74-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST
83+
'httpMethod' => Request::HTTP_METHOD_POST
7584
],
7685
'soap' => [
7786
'service' => self::SERVICE_NAME,
7887
'serviceVersion' => self::SERVICE_VERSION,
7988
'operation' => self::SERVICE_NAME . 'Update',
8089
],
8190
];
82-
$storeId = 0;
83-
$newPrice = 31337;
8491
$response = $this->_webApiCall(
8592
$serviceInfo,
8693
[
8794
'prices' => [
88-
[
89-
'price' => $newPrice,
90-
'store_id' => $storeId,
91-
'sku' => $sku,
92-
'price_from' => '2037-01-19 03:14:07',
93-
'price_to' => '2038-01-19 03:14:07',
94-
]
95+
$data
9596
]
9697
]
9798
);
@@ -102,23 +103,28 @@ public function testUpdate()
102103
* Test delete method.
103104
*
104105
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
106+
* @dataProvider deleteData
107+
* @param array $data
108+
* @throws CouldNotSaveException
109+
* @throws InputException
110+
* @throws NoSuchEntityException
111+
* @throws StateException
105112
*/
106-
public function testDelete()
113+
public function testDelete(array $data)
107114
{
108-
$specialPrice = 3057;
109-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
110-
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
111-
$fromDate = '1970-01-01 00:00:01';
112-
$toDate = '2038-01-19 03:14:07';
113-
$product = $productRepository->get(self::SIMPLE_PRODUCT_SKU, true);
114-
$product->setData('special_price', $specialPrice)
115-
->setData('special_from_date', $fromDate)
116-
->setData('special_to_date', $toDate);
115+
/** @var ProductRepositoryInterface $productRepository */
116+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
117+
$product = $productRepository->get($data['sku'], true);
118+
$product->setData('special_price', $data['price']);
119+
$product->setData('special_from_date', $data['price_from']);
120+
if ($data['price_to']) {
121+
$product->setData('special_to_date', $data['price_to']);
122+
}
117123
$productRepository->save($product);
118124
$serviceInfo = [
119125
'rest' => [
120126
'resourcePath' => '/V1/products/special-price-delete',
121-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST
127+
'httpMethod' => Request::HTTP_METHOD_POST
122128
],
123129
'soap' => [
124130
'service' => self::SERVICE_NAME,
@@ -130,19 +136,80 @@ public function testDelete()
130136
$serviceInfo,
131137
[
132138
'prices' => [
133-
[
134-
'price' => $specialPrice,
135-
'store_id' => 0,
136-
'sku' => self::SIMPLE_PRODUCT_SKU,
137-
'price_from' => $fromDate,
138-
'price_to' => $toDate,
139-
]
139+
$data
140140
]
141141
]
142142
);
143-
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */
144-
$product = $productRepository->get(self::SIMPLE_PRODUCT_SKU, false, null, true);
143+
$product = $productRepository->get($data['sku'], false, null, true);
145144
$this->assertEmpty($response);
146145
$this->assertNull($product->getSpecialPrice());
147146
}
147+
148+
/**
149+
* Data provider for testUpdate
150+
*
151+
* @return array
152+
*/
153+
public function updateData(): array
154+
{
155+
$fromDate = '2037-01-19 03:14:07';
156+
$toDate = '2038-01-19 03:14:07';
157+
158+
return [
159+
[
160+
// data set with 'price_to' specified
161+
[
162+
'price' => 31337,
163+
'store_id' => 0,
164+
'sku' => self::VIRTUAL_PRODUCT_SKU,
165+
'price_from' => $fromDate,
166+
'price_to' => $toDate
167+
]
168+
],
169+
[
170+
// data set without 'price_to' specified
171+
[
172+
'price' => 31337,
173+
'store_id' => 0,
174+
'sku' => self::VIRTUAL_PRODUCT_SKU,
175+
'price_from' => $fromDate,
176+
'price_to' => false
177+
]
178+
],
179+
];
180+
}
181+
182+
/**
183+
* Data provider for testDelete
184+
*
185+
* @return array
186+
*/
187+
public function deleteData(): array
188+
{
189+
$fromDate = '1970-01-01 00:00:01';
190+
$toDate = '2038-01-19 03:14:07';
191+
192+
return [
193+
[
194+
// data set with 'price_to' specified
195+
[
196+
'price' => 3057,
197+
'store_id' => 0,
198+
'sku' => self::SIMPLE_PRODUCT_SKU,
199+
'price_from' => $fromDate,
200+
'price_to' => $toDate
201+
]
202+
],
203+
[
204+
// data set without 'price_to' specified
205+
[
206+
'price' => 3057,
207+
'store_id' => 0,
208+
'sku' => self::SIMPLE_PRODUCT_SKU,
209+
'price_from' => $fromDate,
210+
'price_to' => false
211+
]
212+
],
213+
];
214+
}
148215
}

0 commit comments

Comments
 (0)