5
5
*/
6
6
namespace Magento \Bundle \Test \Unit \Pricing \Render ;
7
7
8
- use \Magento \Bundle \Pricing \Render \FinalPriceBox ;
9
-
8
+ use Magento \Bundle \Pricing \Render \FinalPriceBox ;
10
9
use Magento \Bundle \Pricing \Price ;
10
+ use Magento \Catalog \Pricing \Price \CustomOptionPrice ;
11
11
12
12
class FinalPriceBoxTest extends \PHPUnit_Framework_TestCase
13
13
{
@@ -34,31 +34,50 @@ public function setUp()
34
34
/**
35
35
* @dataProvider showRangePriceDataProvider
36
36
*/
37
- public function testShowRangePrice ($ value , $ maxValue , $ result )
37
+ public function testShowRangePrice ($ optMinValue , $ optMaxValue , $ custMinValue , $ custMaxValue , $ expectedShowRange )
38
38
{
39
+ $ enableCustomOptionMocks = ($ optMinValue == $ optMaxValue );
40
+
39
41
$ priceInfo = $ this ->getMock ('Magento\Framework\Pricing\PriceInfo\Base ' , [], [], '' , false );
40
- $ optionPrice = $ this ->getMockBuilder ('Magento\Bundle\Pricing\Price\BundleOptionPrice ' )
42
+ $ bundleOptionPrice = $ this ->getMockBuilder ('Magento\Bundle\Pricing\Price\BundleOptionPrice ' )
43
+ ->disableOriginalConstructor ()
44
+ ->getMock ();
45
+ $ customOptionPrice = $ this ->getMockBuilder ('Magento\Catalog\Pricing\Price\CustomOptionPrice ' )
41
46
->disableOriginalConstructor ()
42
47
->getMock ();
43
48
44
49
$ this ->saleableItem ->expects ($ this ->atLeastOnce ())
45
50
->method ('getPriceInfo ' )
46
51
->will ($ this ->returnValue ($ priceInfo ));
47
52
48
- $ priceInfo ->expects ($ this ->atLeastOnce ( ))
53
+ $ priceInfo ->expects ($ this ->at ( 0 ))
49
54
->method ('getPrice ' )
50
55
->with (Price \BundleOptionPrice::PRICE_CODE )
51
- ->will ($ this ->returnValue ($ optionPrice ));
56
+ ->will ($ this ->returnValue ($ bundleOptionPrice ));
57
+ if ($ enableCustomOptionMocks ) {
58
+ $ priceInfo ->expects ($ this ->at (1 ))
59
+ ->method ('getPrice ' )
60
+ ->with (CustomOptionPrice::PRICE_CODE )
61
+ ->will ($ this ->returnValue ($ customOptionPrice ));
62
+ }
52
63
53
- $ optionPrice ->expects ($ this ->once ())
64
+ $ bundleOptionPrice ->expects ($ this ->once ())
54
65
->method ('getValue ' )
55
- ->will ($ this ->returnValue ($ value ));
56
-
57
- $ optionPrice ->expects ($ this ->once ())
66
+ ->will ($ this ->returnValue ($ optMinValue ));
67
+ $ bundleOptionPrice ->expects ($ this ->once ())
58
68
->method ('getMaxValue ' )
59
- ->will ($ this ->returnValue ($ maxValue ));
69
+ ->will ($ this ->returnValue ($ optMaxValue ));
60
70
61
- $ this ->assertEquals ($ result , $ this ->model ->showRangePrice ());
71
+ if ($ enableCustomOptionMocks ) {
72
+ $ customOptionPrice ->expects ($ this ->at (0 ))
73
+ ->method ('getCustomOptionRange ' )
74
+ ->will ($ this ->returnValue ($ custMinValue ));
75
+ $ customOptionPrice ->expects ($ this ->at (1 ))
76
+ ->method ('getCustomOptionRange ' )
77
+ ->will ($ this ->returnValue ($ custMaxValue ));
78
+ }
79
+
80
+ $ this ->assertEquals ($ expectedShowRange , $ this ->model ->showRangePrice ());
62
81
}
63
82
64
83
/**
@@ -67,9 +86,37 @@ public function testShowRangePrice($value, $maxValue, $result)
67
86
public function showRangePriceDataProvider ()
68
87
{
69
88
return [
70
- ['value ' => 40.2 , 'maxValue ' => 45. , 'result ' => true ],
71
- ['value ' => false , 'maxValue ' => false , 'result ' => false ],
72
- ['value ' => 45.0 , 'maxValue ' => 45. , 'result ' => false ],
89
+ 'bundle options different, custom options noop ' => [
90
+ 'optMinValue ' => 40.2 ,
91
+ 'optMaxValue ' => 45. ,
92
+ 'custMinValue ' => 0 ,
93
+ 'custMaxValue ' => 0 ,
94
+ 'expectedShowRange ' => true
95
+ ],
96
+
97
+ 'bundle options same boolean, custom options same boolean ' => [
98
+ 'optMinValue ' => false ,
99
+ 'optMaxValue ' => false ,
100
+ 'custMinValue ' => false ,
101
+ 'custMaxValue ' => false ,
102
+ 'expectedShowRange ' => false
103
+ ],
104
+
105
+ 'bundle options same numeric, custom options same ' => [
106
+ 'optMinValue ' => 45.0 ,
107
+ 'optMaxValue ' => 45 ,
108
+ 'custMinValue ' => 1.0 ,
109
+ 'custMaxValue ' => 1 ,
110
+ 'expectedShowRange ' => false
111
+ ],
112
+
113
+ 'bundle options same numeric, custom options different ' => [
114
+ 'optMinValue ' => 45.0 ,
115
+ 'optMaxValue ' => 45. ,
116
+ 'custMinValue ' => 0 ,
117
+ 'custMaxValue ' => 1 ,
118
+ 'expectedShowRange ' => true
119
+ ],
73
120
];
74
121
}
75
122
}
0 commit comments