6
6
namespace Magento \Catalog \Model \Product \Type ;
7
7
8
8
use Magento \Catalog \Model \Product ;
9
+ use Magento \Catalog \Model \ProductRepository ;
10
+ use Magento \Framework \App \ResourceConnection ;
11
+ use Magento \Framework \DataObject ;
12
+ use Magento \Catalog \Model \Indexer \Product \Price \PriceTableResolver ;
13
+ use Magento \Framework \Indexer \DimensionFactory ;
14
+ use Magento \Store \Model \Indexer \WebsiteDimensionProvider ;
15
+ use Magento \Customer \Model \Indexer \CustomerGroupDimensionProvider ;
16
+ use Magento \TestFramework \Helper \Bootstrap ;
9
17
10
18
/**
11
19
* @magentoDbIsolation disabled
@@ -22,20 +30,49 @@ class PriceWithDimensionTest extends \PHPUnit\Framework\TestCase
22
30
23
31
protected function setUp ()
24
32
{
25
- $ this ->_model = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
33
+ $ this ->_model = Bootstrap::getObjectManager ()->create (
26
34
\Magento \Catalog \Model \Product \Type \Price::class
27
35
);
28
36
}
29
37
38
+ public function testGetPriceFromIndexer ()
39
+ {
40
+ /** @var PriceTableResolver $tableResolver */
41
+ $ tableResolver = Bootstrap::getObjectManager ()->create (PriceTableResolver::class);
42
+
43
+ /** @var ResourceConnection $resourceConnection */
44
+ $ resourceConnection = Bootstrap::getObjectManager ()->create (ResourceConnection::class);
45
+
46
+ /** @var DimensionFactory $dimensionFactory */
47
+ $ dimensionFactory = Bootstrap::getObjectManager ()->create (DimensionFactory::class);
48
+ $ dimension = [
49
+ $ dimensionFactory ->create (CustomerGroupDimensionProvider::DIMENSION_NAME , (string )0 ),
50
+ $ dimensionFactory ->create (WebsiteDimensionProvider::DIMENSION_NAME , (string )1 )
51
+ ];
52
+ $ connection = $ resourceConnection ->getConnection ();
53
+ $ priceTable = $ connection ->getTableName (
54
+ $ tableResolver ->resolve ('catalog_product_index_price ' , $ dimension )
55
+ );
56
+
57
+ $ select = $ connection ->select ()->from ($ priceTable )->where ('entity_id = 1 ' );
58
+
59
+ $ return = $ connection ->fetchAll ($ select );
60
+
61
+ $ this ->assertEquals ('10 ' , $ return [0 ]['price ' ]);
62
+ $ this ->assertEquals ('10 ' , $ return [0 ]['final_price ' ]);
63
+ $ this ->assertEquals ('19 ' , $ return [0 ]['min_price ' ]);
64
+ $ this ->assertEquals ('19 ' , $ return [0 ]['max_price ' ]);
65
+ }
66
+
30
67
public function testGetPrice ()
31
68
{
32
- $ this ->assertEquals ('test ' , $ this ->_model ->getPrice (new \ Magento \ Framework \ DataObject (['price ' => 'test ' ])));
69
+ $ this ->assertEquals ('test ' , $ this ->_model ->getPrice (new DataObject (['price ' => 'test ' ])));
33
70
}
34
71
35
72
public function testGetFinalPrice ()
36
73
{
37
- $ repository = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
38
- \ Magento \ Catalog \ Model \ ProductRepository::class
74
+ $ repository = Bootstrap::getObjectManager ()->create (
75
+ ProductRepository::class
39
76
);
40
77
$ product = $ repository ->get ('simple ' );
41
78
// fixture
@@ -58,8 +95,8 @@ public function testGetFinalPrice()
58
95
59
96
public function testGetFormatedPrice ()
60
97
{
61
- $ repository = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()->create (
62
- \ Magento \ Catalog \ Model \ ProductRepository::class
98
+ $ repository = Bootstrap::getObjectManager ()->create (
99
+ ProductRepository::class
63
100
);
64
101
$ product = $ repository ->get ('simple ' );
65
102
// fixture
@@ -93,7 +130,7 @@ public function testIsTierPriceFixed()
93
130
* Build buy request based on product custom options
94
131
*
95
132
* @param Product $product
96
- * @return \Magento\Framework\ DataObject
133
+ * @return DataObject
97
134
*/
98
135
private function prepareBuyRequest (Product $ product )
99
136
{
@@ -114,6 +151,6 @@ private function prepareBuyRequest(Product $product)
114
151
$ options [$ option ->getId ()] = $ value ;
115
152
}
116
153
117
- return new \ Magento \ Framework \ DataObject (['qty ' => 1 , 'options ' => $ options ]);
154
+ return new DataObject (['qty ' => 1 , 'options ' => $ options ]);
118
155
}
119
156
}
0 commit comments