6
6
7
7
namespace Magento \Weee \Test \Unit \Observer ;
8
8
9
- use \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
9
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
+ use Magento \Weee \Model \Tax as WeeeDisplayConfig ;
11
+ use Magento \Tax \Model \Config as TaxConfig ;
10
12
11
13
class UpdateProductOptionsObserverTest extends \PHPUnit_Framework_TestCase
12
14
{
13
15
/**
14
16
* Tests the methods that rely on the ScopeConfigInterface object to provide their return values
15
17
*
16
- * @param array $testArray The initial array that specifies the set of additional options
18
+ * @param array $initialArray The initial array that specifies the set of additional options
17
19
* @param bool $weeeEnabled Whether the Weee module is assumed to be enabled
18
- * @param bool $weeeDisplayExclDescIncl Is this Weee display setting assumed to be set
20
+ * @param int $weeeDisplay Which Weee display is configured
21
+ * @param int $priceDisplay Values are: including tax, excluding tax, or both including and excluding tax
19
22
* @param array $expectedArray The revised array of the additional options
20
23
*
21
24
* @dataProvider updateProductOptionsProvider
22
25
*/
23
- public function testUpdateProductOptions ($ testArray , $ weeeEnabled , $ weeeDisplayExclDescIncl , $ expectedArray )
26
+ public function testUpdateProductOptions ($ initialArray , $ weeeEnabled , $ weeeDisplay , $ priceDisplay , $ expectedArray )
24
27
{
25
28
$ configObj = new \Magento \Framework \DataObject (
26
29
[
27
- 'additional_options ' => $ testArray ,
30
+ 'additional_options ' => $ initialArray ,
28
31
]
29
32
);
30
33
@@ -46,13 +49,27 @@ public function testUpdateProductOptions($testArray, $weeeEnabled, $weeeDisplayE
46
49
$ weeeHelper ->expects ($ this ->any ())
47
50
->method ('isEnabled ' )
48
51
->will ($ this ->returnValue ($ weeeEnabled ));
52
+ $ weeeHelper ->expects ($ this ->any ())
53
+ ->method ('geDisplayIncl ' )
54
+ ->will ($ this ->returnValue ($ weeeDisplay == WeeeDisplayConfig::DISPLAY_INCL ));
49
55
$ weeeHelper ->expects ($ this ->any ())
50
56
->method ('geDisplayExlDescIncl ' )
51
- ->will ($ this ->returnValue ($ weeeDisplayExclDescIncl ));
57
+ ->will ($ this ->returnValue ($ weeeDisplay == WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL ));
58
+ $ weeeHelper ->expects ($ this ->any ())
59
+ ->method ('geDisplayExcl ' )
60
+ ->will ($ this ->returnValue ($ weeeDisplay == WeeeDisplayConfig::DISPLAY_EXCL ));
52
61
$ weeeHelper ->expects ($ this ->any ())
53
62
->method ('getWeeeAttributesForBundle ' )
54
63
->will ($ this ->returnValue ([['fpt1 ' => $ weeeObject1 ], ['fpt1 ' =>$ weeeObject1 , 'fpt2 ' =>$ weeeObject2 ]]));
55
64
65
+ $ taxHelper =$ this ->getMock ('Magento\Tax\Helper\Data ' , [], [], '' , false );
66
+ $ taxHelper ->expects ($ this ->any ())
67
+ ->method ('displayPriceExcludingTax ' )
68
+ ->will ($ this ->returnValue ($ priceDisplay == TaxConfig::DISPLAY_TYPE_EXCLUDING_TAX ));
69
+ $ taxHelper ->expects ($ this ->any ())
70
+ ->method ('priceIncludesTax ' )
71
+ ->will ($ this ->returnValue (true ));
72
+
56
73
$ responseObject =$ this ->getMock ('Magento\Framework\Event\Observer ' , ['getResponseObject ' ], [], '' , false );
57
74
$ responseObject ->expects ($ this ->any ())
58
75
->method ('getResponseObject ' )
@@ -83,6 +100,7 @@ public function testUpdateProductOptions($testArray, $weeeEnabled, $weeeDisplayE
83
100
'Magento\Weee\Observer\UpdateProductOptionsObserver ' ,
84
101
[
85
102
'weeeData ' => $ weeeHelper ,
103
+ 'taxData ' => $ taxHelper ,
86
104
'registry ' => $ registry ,
87
105
]
88
106
);
@@ -99,45 +117,64 @@ public function updateProductOptionsProvider()
99
117
{
100
118
return [
101
119
'weee not enabled ' => [
102
- 'testArray ' => [
120
+ 'initialArray ' => [
121
+ 'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
122
+ 'optionTemplate ' => '<%= data.label %><% if (data.finalPrice.value) '
123
+ . '{ %> +<%- data.finalPrice.formatted %><% } %> ' ,
124
+ ],
125
+ 'weeeEnabled ' => false ,
126
+ 'weeeDisplay ' => WeeeDisplayConfig::DISPLAY_INCL , // has no effect for this scenario
127
+ 'priceDisplay ' => TaxConfig::DISPLAY_TYPE_EXCLUDING_TAX , // has no effect for this scenario
128
+ 'expectedArray ' => [
129
+ 'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
130
+ 'optionTemplate ' => '<%= data.label %><% if (data.finalPrice.value) '
131
+ . '{ %> +<%- data.finalPrice.formatted %><% } %> ' ,
132
+ ],
133
+ ],
134
+
135
+ 'weee enabled, and display with Weee included in the price ' => [
136
+ 'initialArray ' => [
103
137
'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
104
138
'optionTemplate ' => '<%= data.label %><% if (data.basePrice.value) '
105
139
. '{ %> +<%- data.basePrice.formatted %><% } %> ' ,
106
140
],
107
- 'weeeEnabled ' => false ,
108
- 'weeeDisplayExclDescIncl ' => true ,
141
+ 'weeeEnabled ' => true ,
142
+ 'weeeDisplay ' => WeeeDisplayConfig::DISPLAY_INCL ,
143
+ 'priceDisplay ' => TaxConfig::DISPLAY_TYPE_INCLUDING_TAX ,
109
144
'expectedArray ' => [
110
145
'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
111
146
'optionTemplate ' => '<%= data.label %><% if (data.basePrice.value) '
112
147
. '{ %> +<%- data.basePrice.formatted %><% } %> ' ,
113
148
],
114
149
],
115
150
116
- 'weee enabled, but not displaying ExclDescIncl ' => [
117
- 'testArray ' => [
151
+ 'weee enabled, and display with Weee included in the price, and include the Weee descriptions ' => [
152
+ 'initialArray ' => [
118
153
'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
119
154
'optionTemplate ' => '<%= data.label %><% if (data.basePrice.value) '
120
155
. '{ %> +<%- data.basePrice.formatted %><% } %> ' ,
121
156
],
122
157
'weeeEnabled ' => true ,
123
- 'weeeDisplayExclDescIncl ' => false ,
158
+ 'weeeDisplay ' => WeeeDisplayConfig::DISPLAY_INCL_DESCR ,
159
+ 'priceDisplay ' => TaxConfig::DISPLAY_TYPE_INCLUDING_TAX ,
124
160
'expectedArray ' => [
125
161
'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
126
162
'optionTemplate ' => '<%= data.label %><% if (data.basePrice.value) '
127
163
. '{ %> +<%- data.basePrice.formatted %><% } %> <% if (data.weeePricefpt1) '
128
- . '{ %> (: <%- data.weeePricefpt1.formatted %>)<% } %> '
129
- . ' <% if (data.weeePricefpt2) { %> (: <%- data.weeePricefpt2.formatted %>)<% } %> ' ,
164
+ . '{ %> (: <%- data.weeePricefpt1.formatted %>)<% } %> '
165
+ . '<% if (data.weeePricefpt2) { %> (: <%- data.weeePricefpt2.formatted %>)<% } %> ' ,
130
166
],
131
167
],
132
168
133
169
'weee enabled, and display with ExclDescIncl ' => [
134
- 'testArray ' => [
170
+ 'initialArray ' => [
135
171
'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
136
172
'optionTemplate ' => '<%= data.label %><% if (data.basePrice.value) '
137
173
. '{ %> +<%- data.basePrice.formatted %><% } %> ' ,
138
174
],
139
175
'weeeEnabled ' => true ,
140
- 'weeeDisplayExclDescIncl ' => true ,
176
+ 'weeeDisplay ' => WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL ,
177
+ 'priceDisplay ' => TaxConfig::DISPLAY_TYPE_INCLUDING_TAX ,
141
178
'expectedArray ' => [
142
179
'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
143
180
'optionTemplate ' => '<%= data.label %><% if (data.basePrice.value) '
@@ -147,6 +184,34 @@ public function updateProductOptionsProvider()
147
184
. '<% if (data.weeePrice) { %><%- data.weeePrice.formatted %><% } %> ' ,
148
185
],
149
186
],
187
+
188
+ 'weee enabled, and display prices including tax but without Weee ' => [
189
+ 'initialArray ' => [
190
+ 'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
191
+ ],
192
+ 'weeeEnabled ' => true ,
193
+ 'weeeDisplay ' => WeeeDisplayConfig::DISPLAY_EXCL ,
194
+ 'priceDisplay ' => TaxConfig::DISPLAY_TYPE_INCLUDING_TAX ,
195
+ 'expectedArray ' => [
196
+ 'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
197
+ 'optionTemplate ' => '<%- data.label %><% if (data.finalPrice.value) '
198
+ . '{ %> +<%- data.finalPrice.formatted %><% } %> ' ,
199
+ ],
200
+ ],
201
+
202
+ 'weee enabled, and display prices excluding tax but without Weee ' => [
203
+ 'initialArray ' => [
204
+ 'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
205
+ ],
206
+ 'weeeEnabled ' => true ,
207
+ 'weeeDisplay ' => WeeeDisplayConfig::DISPLAY_EXCL ,
208
+ 'priceDisplay ' => TaxConfig::DISPLAY_TYPE_EXCLUDING_TAX ,
209
+ 'expectedArray ' => [
210
+ 'TOTAL_BASE_CALCULATION ' => 'TOTAL_BASE_CALCULATION ' ,
211
+ 'optionTemplate ' => '<%- data.label %><% if (data.basePrice.value) '
212
+ . '{ %> +<%- data.basePrice.formatted %><% } %> ' ,
213
+ ],
214
+ ],
150
215
];
151
216
}
152
217
}
0 commit comments