9
9
10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
12
- use Magento \Catalog \Model \ResourceModel \Product \WebsiteFactory ;
12
+ use Magento \Catalog \Model \ResourceModel \Product \Website \ Link ;
13
13
use Magento \Framework \Exception \NoSuchEntityException ;
14
14
use Magento \Framework \ObjectManagerInterface ;
15
15
use Magento \Store \Api \WebsiteRepositoryInterface ;
@@ -26,8 +26,8 @@ class UpdateProductWebsiteTest extends TestCase
26
26
/** @var ObjectManagerInterface */
27
27
private $ objectManager ;
28
28
29
- /** @var WebsiteFactory */
30
- private $ websiteProductsResourceFactory ;
29
+ /** @var Link */
30
+ private $ productWebsiteLink ;
31
31
32
32
/** @var WebsiteRepositoryInterface */
33
33
private $ websiteRepository ;
@@ -43,7 +43,7 @@ protected function setUp()
43
43
parent ::setUp ();
44
44
45
45
$ this ->objectManager = Bootstrap::getObjectManager ();
46
- $ this ->websiteProductsResourceFactory = $ this ->objectManager ->get (WebsiteFactory ::class);
46
+ $ this ->productWebsiteLink = $ this ->objectManager ->get (Link ::class);
47
47
$ this ->websiteRepository = $ this ->objectManager ->get (WebsiteRepositoryInterface::class);
48
48
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
49
49
}
@@ -58,7 +58,10 @@ public function testAssignProductToWebsite(): void
58
58
$ defaultWebsiteId = $ this ->websiteRepository ->get ('base ' )->getId ();
59
59
$ secondWebsiteId = $ this ->websiteRepository ->get ('test ' )->getId ();
60
60
$ 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
+ );
62
65
}
63
66
64
67
/**
@@ -68,11 +71,9 @@ public function testAssignProductToWebsite(): void
68
71
*/
69
72
public function testUnassignProductFromWebsite (): void
70
73
{
71
- $ product = $ this ->productRepository ->get ('simple-on-two-websites ' );
72
74
$ 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 ()));
76
77
}
77
78
78
79
/**
@@ -102,17 +103,4 @@ private function updateProductWebsites(string $productSku, array $websiteIds): P
102
103
103
104
return $ this ->productRepository ->save ($ product );
104
105
}
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
- }
118
106
}
0 commit comments