12
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
13
13
use Magento \Catalog \Model \Product ;
14
14
use Magento \Catalog \Model \Product \Visibility ;
15
- use Magento \Eav \Model \AttributeSetSearchResults ;
16
- use Magento \Eav \Model \Entity \Attribute \Set ;
17
15
use Magento \Eav \Model \Entity \Type ;
18
16
use Magento \Framework \Api \SearchCriteriaBuilder ;
19
17
use Magento \Framework \Api \SortOrderBuilder ;
20
18
use Magento \Framework \App \Http ;
21
- use Magento \Framework \Data \Collection ;
22
19
use Magento \Framework \Registry ;
23
- use Magento \Store \Api \WebsiteRepositoryInterface ;
24
20
use Magento \Store \Model \StoreManagerInterface ;
21
+ use Magento \TestFramework \Eav \Model \GetAttributeSetByName ;
25
22
use Magento \TestFramework \Request ;
26
23
use PHPUnit \Framework \MockObject \MockObject ;
27
24
use Psr \Log \LoggerInterface ;
@@ -66,15 +63,15 @@ class ViewTest extends AbstractController
66
63
/** @var StoreManagerInterface */
67
64
private $ storeManager ;
68
65
69
- /** @var WebsiteRepositoryInterface */
70
- private $ websiteRepository ;
71
-
72
66
/** @var SortOrderBuilder */
73
67
private $ sortOrderBuilder ;
74
68
75
69
/** @var SearchCriteriaBuilder */
76
70
private $ searchCriteriaBuilder ;
77
71
72
+ /** @var GetAttributeSetByName */
73
+ private $ getAttributeSetByName ;
74
+
78
75
/**
79
76
* @inheritdoc
80
77
*/
@@ -89,9 +86,9 @@ protected function setUp()
89
86
->loadByCode (Product::ENTITY );
90
87
$ this ->registry = $ this ->_objectManager ->get (Registry::class);
91
88
$ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
92
- $ this ->websiteRepository = $ this ->_objectManager ->get (WebsiteRepositoryInterface::class);
93
89
$ this ->sortOrderBuilder = $ this ->_objectManager ->create (SortOrderBuilder::class);
94
90
$ this ->searchCriteriaBuilder = $ this ->_objectManager ->get (SearchCriteriaBuilder::class);
91
+ $ this ->getAttributeSetByName = $ this ->_objectManager ->get (GetAttributeSetByName::class);
95
92
}
96
93
97
94
/**
@@ -128,7 +125,7 @@ public function testViewActionCustomAttributeSetWithoutCountryOfManufacture(): v
128
125
/** @var MockObject|LoggerInterface $logger */
129
126
$ logger = $ this ->setupLoggerMock ();
130
127
$ product = $ this ->productRepository ->get ('simple_with_com ' );
131
- $ attributeSetCustom = $ this ->getProductAttributeSetByName ('custom_attribute_set_wout_com ' );
128
+ $ attributeSetCustom = $ this ->getAttributeSetByName -> execute ('custom_attribute_set_wout_com ' );
132
129
$ product ->setAttributeSetId ($ attributeSetCustom ->getAttributeSetId ());
133
130
$ this ->productRepository ->save ($ product );
134
131
@@ -226,7 +223,7 @@ public function testProductVisibleOnTwoWebsites(): void
226
223
*/
227
224
public function testRemoveProductFromOneWebsiteVisibility (): void
228
225
{
229
- $ websiteId = $ this ->websiteRepository -> get ('test ' )->getId ();
226
+ $ websiteId = $ this ->storeManager -> getWebsite ('test ' )->getId ();
230
227
$ currentStore = $ this ->storeManager ->getStore ();
231
228
$ secondStoreId = $ this ->storeManager ->getStore ('fixture_second_store ' )->getId ();
232
229
$ product = $ this ->updateProduct ('simple-on-two-websites ' , ['website_ids ' => [$ websiteId ]]);
@@ -355,31 +352,6 @@ private function setupLoggerMock(): MockObject
355
352
return $ logger ;
356
353
}
357
354
358
- /**
359
- * Get product attribute set by name.
360
- *
361
- * @param string $attributeSetName
362
- * @return Set|null
363
- */
364
- private function getProductAttributeSetByName (string $ attributeSetName ): ?Set
365
- {
366
- $ this ->searchCriteriaBuilder ->addFilter ('attribute_set_name ' , $ attributeSetName );
367
- $ this ->searchCriteriaBuilder ->addFilter ('entity_type_id ' , $ this ->productEntityType ->getId ());
368
- $ attributeSetIdSortOrder = $ this ->sortOrderBuilder
369
- ->setField ('attribute_set_id ' )
370
- ->setDirection (Collection::SORT_ORDER_DESC )
371
- ->create ();
372
- $ this ->searchCriteriaBuilder ->addSortOrder ($ attributeSetIdSortOrder );
373
- $ this ->searchCriteriaBuilder ->setPageSize (1 );
374
- $ this ->searchCriteriaBuilder ->setCurrentPage (1 );
375
- /** @var AttributeSetSearchResults $searchResult */
376
- $ searchResult = $ this ->attributeSetRepository ->getList ($ this ->searchCriteriaBuilder ->create ());
377
- $ items = $ searchResult ->getItems ();
378
- $ result = count ($ items ) > 0 ? reset ($ items ) : null ;
379
-
380
- return $ result ;
381
- }
382
-
383
355
/**
384
356
* Update product visibility
385
357
*
0 commit comments