7
7
8
8
use Oro \Bundle \EntityBundle \ORM \DoctrineHelper ;
9
9
10
+ use OroB2B \Bundle \PricingBundle \Entity \CombinedProductPrice ;
10
11
use OroB2B \Bundle \PricingBundle \Layout \DataProvider \FrontendProductPricesProvider ;
11
12
use OroB2B \Bundle \PricingBundle \Model \PriceListRequestHandler ;
12
13
use OroB2B \Bundle \PricingBundle \Manager \UserCurrencyManager ;
14
+ use OroB2B \Bundle \ProductBundle \Entity \Product ;
15
+ use OroB2B \Bundle \ProductBundle \Entity \ProductUnit ;
16
+ use OroB2B \Bundle \ProductBundle \Entity \ProductUnitPrecision ;
13
17
14
18
class FrontendProductPricesProviderTest extends \PHPUnit_Framework_TestCase
15
19
{
@@ -68,13 +72,13 @@ public function testGetDataWithEmptyContext()
68
72
69
73
public function testGetData ()
70
74
{
71
- $ prices = [1 => 'test ' , 2 => 'test2 ' ];
72
75
$ priceListId = 23 ;
73
76
$ priceList = $ this ->getEntity ('OroB2B\Bundle\PricingBundle\Entity\PriceList ' , ['id ' => $ priceListId ]);
74
77
$ productId = 24 ;
75
- $ product = $ this ->getMockBuilder ('OroB2B\Bundle\ProductBundle\Entity\Product ' )
76
- ->disableOriginalConstructor ()
77
- ->getMock ();
78
+ /** @var Product|\PHPUnit_Framework_MockObject_MockObject $product */
79
+ $ product = $ this ->getMockBuilder ('OroB2B\Bundle\ProductBundle\Entity\Product ' )
80
+ ->disableOriginalConstructor ()
81
+ ->getMock ();
78
82
79
83
$ product ->expects ($ this ->once ())
80
84
->method ('getId ' )
@@ -84,13 +88,13 @@ public function testGetData()
84
88
$ unitPrecisions [] = $ this ->createUnitPrecision ('set ' , false );
85
89
86
90
$ product ->expects ($ this ->once ())
87
- ->method ('getUnitPrecisions ' )
88
- ->willReturn ($ unitPrecisions );
91
+ ->method ('getUnitPrecisions ' )
92
+ ->willReturn ($ unitPrecisions );
89
93
90
94
$ productPrice1 = $ this ->createProductPrice ('each ' , $ product );
91
95
$ productPrice2 = $ this ->createProductPrice ('set ' , $ product );
92
96
$ prices = [$ productPrice1 , $ productPrice2 ];
93
-
97
+
94
98
$ priceSorting = ['unit ' => 'ASC ' , 'currency ' => 'DESC ' , 'quantity ' => 'ASC ' ];
95
99
$ context = new LayoutContext ();
96
100
$ context ->data ()->set ('product ' , null , $ product );
@@ -117,29 +121,20 @@ public function testGetData()
117
121
->willReturn ('EUR ' );
118
122
119
123
$ actual = $ this ->provider ->getData ($ context );
120
- $ this ->assertEquals (1 , count ( $ actual) );
124
+ $ this ->assertCount (1 , $ actual );
121
125
$ this ->assertEquals ('each ' , current ($ actual )->getUnit ());
122
126
}
123
127
124
128
/**
125
129
* @param string $unitCode
126
- * @param boolen $sell
127
- * @return productUnitPresion
130
+ * @param boolean $sell
131
+ * @return ProductUnitPrecision
128
132
*/
129
133
private function createUnitPrecision ($ unitCode , $ sell )
130
134
{
131
- $ p = $ this ->getMockBuilder ('OroB2B\Bundle\ProductBundle\Entity\ProductUnionPrecision ' )
132
- ->setMethods (array ('isSell ' , 'getUnit ' ))
133
- ->disableOriginalConstructor ()
134
- ->getMock ();
135
-
136
- $ p ->expects ($ this ->once ())
137
- ->method ('isSell ' )
138
- ->willReturn ($ sell );
139
-
140
- $ p ->expects ($ this ->any ())
141
- ->method ('getUnit ' )
142
- ->willReturn ($ unitCode );
135
+ $ p = new ProductUnitPrecision ();
136
+ $ p ->setSell ($ sell );
137
+ $ p ->setUnit ($ this ->getUnit ($ unitCode ));
143
138
144
139
return $ p ;
145
140
}
@@ -151,21 +146,22 @@ private function createUnitPrecision($unitCode, $sell)
151
146
*/
152
147
private function createProductPrice ($ unit , $ product )
153
148
{
154
- $ p = $ this ->getMockBuilder (
155
- 'OroB2B\Bundle\PricingBundle\Entity\CombinedProductPrice ' ,
156
- array ('getUnit ' , 'getProduct ' )
157
- )
158
- ->disableOriginalConstructor ()
159
- ->getMock ();
149
+ $ p = new CombinedProductPrice ();
150
+ $ p ->setProduct ($ product );
151
+ $ p ->setUnit ($ this ->getUnit ($ unit ));
160
152
161
- $ p ->expects ($ this ->any ())
162
- ->method ('getProduct ' )
163
- ->willReturn ($ product );
153
+ return $ p ;
154
+ }
164
155
165
- $ p ->expects ($ this ->any ())
166
- ->method ('getUnit ' )
167
- ->willReturn ($ unit );
156
+ /**
157
+ * @param string $unitCode
158
+ * @return ProductUnit
159
+ */
160
+ private function getUnit ($ unitCode )
161
+ {
162
+ $ unit = new ProductUnit ();
163
+ $ unit ->setCode ($ unitCode );
168
164
169
- return $ p ;
165
+ return $ unit ;
170
166
}
171
167
}
0 commit comments