Skip to content

Commit 04fd1ac

Browse files
committed
MC-39598: Create automated test for: "Assign/Unassign product to websites via API"
1 parent 0e81b05 commit 04fd1ac

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,19 @@ protected function setUp(): void
4646
$this->websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
4747
}
4848

49-
/**
50-
* @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php
51-
*
52-
* @return void
53-
*/
54-
public function testSaveWebsiteLinkWithoutWebsiteId(): void
55-
{
56-
$serviceInfo = $this->fillServiceInfo('/V1/products/:sku/websites', Request::HTTP_METHOD_POST, 'Save');
57-
$requestData = ['productWebsiteLink' => ['sku' => 'simple2']];
58-
$this->expectException(\Exception::class);
59-
$this->expectErrorMessage((string)__('There are not websites for assign to product'));
60-
$this->_webApiCall($serviceInfo, $requestData);
61-
}
62-
6349
/**
6450
* @magentoApiDataFixture Magento/Catalog/_files/second_product_simple.php
6551
*
6652
* @return void
6753
*/
6854
public function testSaveWebsiteLinkWithUnexistingWebsiteId(): void
6955
{
56+
$pattern = '/(Could\\snot\\sassign\\sproduct)+([\\s\\S]*)(to\\swebsites)+([\\s\\S]*)/';
7057
$unexistingWebsiteId = 8932568989;
7158
$serviceInfo = $this->fillServiceInfo('/V1/products/:sku/websites', Request::HTTP_METHOD_POST, 'Save');
7259
$requestData = ['productWebsiteLink' => ['sku' => 'simple2', 'websiteId' => $unexistingWebsiteId]];
7360
$this->expectException(\Exception::class);
74-
$this->expectExceptionMessageMatches('/Could not assign product \\\"%1\\\" to websites \\\"%2\\\"/');
61+
$this->expectExceptionMessageMatches($pattern);
7562
$this->_webApiCall($serviceInfo, $requestData);
7663
}
7764

@@ -85,8 +72,8 @@ public function testDeleteWebsiteLink(): void
8572
$productSku = 'unique-simple-azaza';
8673
$websiteId = (int)$this->websiteRepository->get('second_website')->getId();
8774
$resourcePath = sprintf('/V1/products/%s/websites/%u', $productSku, $websiteId);
88-
$serviceInfo = $this->fillServiceInfo($resourcePath, Request::HTTP_METHOD_DELETE, 'Delete');
89-
$this->_webApiCall($serviceInfo);
75+
$serviceInfo = $this->fillServiceInfo($resourcePath, Request::HTTP_METHOD_DELETE, 'DeleteById');
76+
$this->_webApiCall($serviceInfo, ['sku' => $productSku, 'websiteId' => $websiteId]);
9077
$product = $this->productRepository->get($productSku, false, null, true);
9178
$this->assertNotContains($websiteId, $product->getWebsiteIds());
9279
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductWebsiteLinkRepositoryTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Api\Data\ProductWebsiteLinkInterfaceFactory;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Api\ProductWebsiteLinkRepositoryInterface;
13+
use Magento\Framework\Exception\InputException;
1314
use Magento\Framework\ObjectManagerInterface;
1415
use Magento\Store\Api\WebsiteRepositoryInterface;
1516
use Magento\TestFramework\Helper\Bootstrap;
@@ -55,7 +56,21 @@ protected function setUp(): void
5556
}
5657

5758
/**
58-
* @magentoApiDataFixture Magento/Catalog/_files/product_with_two_websites.php
59+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
60+
*
61+
* @return void
62+
*/
63+
public function testSaveWithoutWebsiteId(): void
64+
{
65+
$productWebsiteLink = $this->productWebsiteLinkFactory->create();
66+
$productWebsiteLink->setSku('unique-simple-azaza');
67+
$this->expectException(InputException::class);
68+
$this->expectErrorMessage((string)__('There are not websites for assign to product'));
69+
$this->productWebsiteLinkRepository->save($productWebsiteLink);
70+
}
71+
72+
/**
73+
* @magentoDataFixture Magento/Catalog/_files/product_with_two_websites.php
5974
*
6075
* @return void
6176
*/

0 commit comments

Comments
 (0)