Skip to content

Commit 0f007c4

Browse files
committed
MC-20684: Admin: Add/remove product from other storeviews and websites
1 parent 42ccbc3 commit 0f007c4

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/UpdateProductWebsiteTest.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
12-
use Magento\Catalog\Model\ResourceModel\Product\WebsiteFactory;
12+
use Magento\Catalog\Model\ResourceModel\Product\Website\Link;
1313
use Magento\Framework\Exception\NoSuchEntityException;
1414
use Magento\Framework\ObjectManagerInterface;
1515
use Magento\Store\Api\WebsiteRepositoryInterface;
@@ -26,8 +26,8 @@ class UpdateProductWebsiteTest extends TestCase
2626
/** @var ObjectManagerInterface */
2727
private $objectManager;
2828

29-
/** @var WebsiteFactory */
30-
private $websiteProductsResourceFactory;
29+
/** @var Link */
30+
private $productWebsiteLink;
3131

3232
/** @var WebsiteRepositoryInterface */
3333
private $websiteRepository;
@@ -43,7 +43,7 @@ protected function setUp()
4343
parent::setUp();
4444

4545
$this->objectManager = Bootstrap::getObjectManager();
46-
$this->websiteProductsResourceFactory = $this->objectManager->get(WebsiteFactory::class);
46+
$this->productWebsiteLink = $this->objectManager->get(Link::class);
4747
$this->websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
4848
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
4949
}
@@ -58,7 +58,10 @@ public function testAssignProductToWebsite(): void
5858
$defaultWebsiteId = $this->websiteRepository->get('base')->getId();
5959
$secondWebsiteId = $this->websiteRepository->get('test')->getId();
6060
$product = $this->updateProductWebsites('simple2', [$defaultWebsiteId, $secondWebsiteId]);
61-
$this->assertProductWebsites((int)$product->getId(), [$defaultWebsiteId, $secondWebsiteId]);
61+
$this->assertEquals(
62+
[$defaultWebsiteId, $secondWebsiteId],
63+
$this->productWebsiteLink->getWebsiteIdsByProductId($product->getId())
64+
);
6265
}
6366

6467
/**
@@ -68,11 +71,9 @@ public function testAssignProductToWebsite(): void
6871
*/
6972
public function testUnassignProductFromWebsite(): void
7073
{
71-
$product = $this->productRepository->get('simple-on-two-websites');
7274
$secondWebsiteId = $this->websiteRepository->get('test')->getId();
73-
$product->setWebsiteIds([$secondWebsiteId]);
74-
$product = $this->productRepository->save($product);
75-
$this->assertProductWebsites((int)$product->getId(), [$secondWebsiteId]);
75+
$product = $this->updateProductWebsites('simple-on-two-websites', [$secondWebsiteId]);
76+
$this->assertEquals([$secondWebsiteId], $this->productWebsiteLink->getWebsiteIdsByProductId($product->getId()));
7677
}
7778

7879
/**
@@ -102,17 +103,4 @@ private function updateProductWebsites(string $productSku, array $websiteIds): P
102103

103104
return $this->productRepository->save($product);
104105
}
105-
106-
/**
107-
* Assert that websites attribute was correctly saved
108-
*
109-
* @param int $productId
110-
* @param array $expectedData
111-
* @return void
112-
*/
113-
private function assertProductWebsites(int $productId, array $expectedData): void
114-
{
115-
$websiteResource = $this->websiteProductsResourceFactory->create();
116-
$this->assertEquals($expectedData, $websiteResource->getWebsites([$productId])[$productId]);
117-
}
118106
}

0 commit comments

Comments
 (0)