7
7
8
8
use Magento \Catalog \Api \ProductRepositoryInterface ;
9
9
use Magento \Catalog \Model \Product \Attribute \Source \Status ;
10
+ use Magento \Store \Model \Store ;
11
+ use Magento \Store \Model \StoreManagerInterface ;
10
12
use Magento \TestFramework \Helper \Bootstrap ;
11
13
12
- /**
13
- * @magentoAppIsolation enabled
14
- */
15
14
class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase
16
15
{
16
+ /**
17
+ * @var StoreManagerInterface
18
+ */
19
+ private $ storeManager ;
20
+
17
21
/**
18
22
* @var LowestPriceOptionsProviderInterface
19
23
*/
@@ -26,27 +30,37 @@ class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase
26
30
27
31
protected function setUp ()
28
32
{
33
+ $ this ->storeManager = Bootstrap::getObjectManager ()->get (StoreManagerInterface::class);
29
34
$ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
30
35
$ this ->lowestPriceOptionsProvider = Bootstrap::getObjectManager ()->get (
31
36
LowestPriceOptionsProviderInterface::class
32
37
);
33
38
}
34
39
35
40
/**
36
- * @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_simple .php
41
+ * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable .php
37
42
*/
38
43
public function testGetProductsIfOneOfChildIsDisabled ()
39
44
{
40
- $ configurableProduct = $ this ->productRepository ->get ( ' configurable_product_with_two_simple ' );
45
+ $ configurableProduct = $ this ->productRepository ->getById ( 1 , false , null , true );
41
46
$ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
42
47
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
43
48
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
44
49
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
45
50
46
51
// load full aggregation root
47
- $ lowestPriceChildProduct = $ this ->productRepository ->get ($ lowestPriceChildrenProduct ->getSku ());
52
+ $ lowestPriceChildProduct = $ this ->productRepository ->get (
53
+ $ lowestPriceChildrenProduct ->getSku (),
54
+ false ,
55
+ null ,
56
+ true
57
+ );
48
58
$ lowestPriceChildProduct ->setStatus (Status::STATUS_DISABLED );
59
+ // update in global scope
60
+ $ currentStoreId = $ this ->storeManager ->getStore ()->getId ();
61
+ $ this ->storeManager ->setCurrentStore (Store::DEFAULT_STORE_ID );
49
62
$ this ->productRepository ->save ($ lowestPriceChildProduct );
63
+ $ this ->storeManager ->setCurrentStore ($ currentStoreId );
50
64
51
65
$ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
52
66
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
@@ -55,22 +69,25 @@ public function testGetProductsIfOneOfChildIsDisabled()
55
69
}
56
70
57
71
/**
58
- * @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_simple .php
72
+ * @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable .php
59
73
*/
60
74
public function testGetProductsIfOneOfChildIsOutOfStock ()
61
75
{
62
- $ configurableProduct = $ this ->productRepository ->get ( ' configurable_product_with_two_simple ' );
76
+ $ configurableProduct = $ this ->productRepository ->getById ( 1 , false , null , true );
63
77
$ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
64
78
$ this ->assertCount (1 , $ lowestPriceChildrenProducts );
65
79
$ lowestPriceChildrenProduct = reset ($ lowestPriceChildrenProducts );
66
80
$ this ->assertEquals (10 , $ lowestPriceChildrenProduct ->getPrice ());
67
81
68
82
// load full aggregation root
69
- $ lowestPriceChildProduct = $ this ->productRepository ->get ($ lowestPriceChildrenProduct ->getSku ());
83
+ $ lowestPriceChildProduct = $ this ->productRepository ->get (
84
+ $ lowestPriceChildrenProduct ->getSku (),
85
+ false ,
86
+ null ,
87
+ true
88
+ );
70
89
$ stockItem = $ lowestPriceChildProduct ->getExtensionAttributes ()->getStockItem ();
71
- $ stockItem ->setIsInStock (false );
72
- // TODO: Need to delete next string after MAGETWO-59315 fixing
73
- $ lowestPriceChildProduct ->setStockData (['is_in_stock ' => 0 , 'qty ' => 0 ]);
90
+ $ stockItem ->setIsInStock (0 );
74
91
$ this ->productRepository ->save ($ lowestPriceChildProduct );
75
92
76
93
$ lowestPriceChildrenProducts = $ this ->lowestPriceOptionsProvider ->getProducts ($ configurableProduct );
0 commit comments