@@ -58,194 +58,93 @@ protected function setUp()
58
58
);
59
59
}
60
60
61
- // public function testValidate()
62
- // {
63
- // $product = new \Magento\Framework\DataObject();
64
- // $product->setTierPrice(
65
- // [
66
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
67
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
68
- // ]
69
- // );
70
- // $this->assertTrue($this->_model->validate($product));
71
- // }
72
- //
73
- // /**
74
- // * @expectedException \Magento\Framework\Exception\LocalizedException
75
- // */
76
- // public function testValidateDuplicate()
77
- // {
78
- // $product = new \Magento\Framework\DataObject();
79
- // $product->setTierPrice(
80
- // [
81
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
82
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
83
- // ]
84
- // );
85
- //
86
- // $this->_model->validate($product);
87
- // }
88
- //
89
- // /**
90
- // * @expectedException \Magento\Framework\Exception\LocalizedException
91
- // */
92
- // public function testValidateDuplicateWebsite()
93
- // {
94
- // $product = new \Magento\Framework\DataObject();
95
- // $product->setTierPrice(
96
- // [
97
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
98
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
99
- // ['website_id' => 1, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
100
- // ]
101
- // );
102
- //
103
- // $this->_model->validate($product);
104
- // }
105
- //
106
- // /**
107
- // * @expectedException \Magento\Framework\Exception\LocalizedException
108
- // */
109
- // public function testValidatePercentage()
110
- // {
111
- // $product = new \Magento\Framework\DataObject();
112
- // $product->setTierPrice(
113
- // [
114
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'percentage_value' => 101],
115
- // ]
116
- // );
117
- //
118
- // $this->_model->validate($product);
119
- // }
120
- //
121
- // public function testPreparePriceData()
122
- // {
123
- // $data = [
124
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 2, 'price' => 8],
125
- // ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
126
- // ['website_id' => 1, 'cust_group' => 1, 'price_qty' => 5, 'price' => 5],
127
- // ];
128
- //
129
- // $newData = $this->_model->preparePriceData($data, \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, 1);
130
- // $this->assertEquals(2, count($newData));
131
- // $this->assertArrayHasKey('1-2', $newData);
132
- // $this->assertArrayHasKey('1-5', $newData);
133
- // }
134
- //
135
- // public function testAfterLoad()
136
- // {
137
- // /** @var $product \Magento\Catalog\Model\Product */
138
- // $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
139
- // \Magento\Catalog\Model\Product::class
140
- // );
141
- // $fixtureProduct = $this->productRepository->get('simple');
142
- // $product->setId($fixtureProduct->getId());
143
- // $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
144
- // $product->setData($linkField, $fixtureProduct->getData($linkField));
145
- // $this->_model->afterLoad($product);
146
- // $price = $product->getTierPrice();
147
- // $this->assertNotEmpty($price);
148
- // $this->assertEquals(4, count($price));
149
- // }
61
+ public function testValidate ()
62
+ {
63
+ $ product = new \Magento \Framework \DataObject ();
64
+ $ product ->setTierPrice (
65
+ [
66
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
67
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 ],
68
+ ]
69
+ );
70
+ $ this ->assertTrue ($ this ->_model ->validate ($ product ));
71
+ }
150
72
151
73
/**
152
- * @magentoAppArea adminhtml
153
- * @param array $tierPricesData
154
- * @param bool $isChanged
155
- * @param int $tierPriceCtr
156
- * @dataProvider afterSaveDataProvider
74
+ * @expectedException \Magento\Framework\Exception\LocalizedException
157
75
*/
158
- public function testAfterSave ( array $ tierPricesData , $ isChanged , $ tierPriceCtr )
76
+ public function testValidateDuplicate ( )
159
77
{
160
- /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
161
- $ productRepository = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
162
- ->get (\Magento \Catalog \Api \ProductRepositoryInterface::class);
78
+ $ product = new \Magento \Framework \DataObject ();
79
+ $ product ->setTierPrice (
80
+ [
81
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
82
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
83
+ ]
84
+ );
163
85
164
- /** @var $product \Magento\Catalog\Model\Product */
165
- $ product = $ productRepository ->get ('simple ' , true );
166
- $ tierPrices = [];
167
- foreach ($ tierPricesData as $ tierPrice ) {
168
- $ tierPrices [] = $ this ->tierPriceFactory ->create ([
169
- 'data ' => $ tierPrice
170
- ]);
171
- }
86
+ $ this ->_model ->validate ($ product );
87
+ }
172
88
173
- // Added tier price
174
- $ product ->setTierPrices ($ tierPrices );
175
- $ product ->save ();
89
+ /**
90
+ * @expectedException \Magento\Framework\Exception\LocalizedException
91
+ */
92
+ public function testValidateDuplicateWebsite ()
93
+ {
94
+ $ product = new \Magento \Framework \DataObject ();
95
+ $ product ->setTierPrice (
96
+ [
97
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
98
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 ],
99
+ ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 ],
100
+ ]
101
+ );
176
102
177
- $ this ->assertEquals ($ isChanged , $ product ->getData ('tier_price_changed ' ));
103
+ $ this ->_model ->validate ($ product );
104
+ }
178
105
179
- /** @var $product \Magento\Catalog\Model\Product */
180
- $ product = $ productRepository ->get ('simple ' , true , null , true );
181
- $ this ->assertEquals ($ tierPriceCtr , count ($ product ->getTierPrice ()));
182
- $ this ->assertEquals (0 , $ product ->getData ('tier_price_changed ' ));
106
+ /**
107
+ * @expectedException \Magento\Framework\Exception\LocalizedException
108
+ */
109
+ public function testValidatePercentage ()
110
+ {
111
+ $ product = new \Magento \Framework \DataObject ();
112
+ $ product ->setTierPrice (
113
+ [
114
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'percentage_value ' => 101 ],
115
+ ]
116
+ );
117
+
118
+ $ this ->_model ->validate ($ product );
183
119
}
184
120
185
- public function afterSaveDataProvider ()
121
+ public function testPreparePriceData ()
186
122
{
187
- return [
188
- 'same ' => [
189
- [
190
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 2 , 'value ' => 8 ],
191
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 5 , 'value ' => 5 ],
192
- ['website_id ' => 0 , 'customer_group_id ' => 0 , 'qty ' => 3 , 'value ' => 5 ],
193
- [
194
- 'website_id ' => 0 ,
195
- 'customer_group_id ' => 0 ,
196
- 'qty ' => 10 ,
197
- 'extension_attributes ' => new \Magento \Framework \DataObject (['percentage_value ' => 50 ])
198
- ],
199
- ],
200
- 0 ,
201
- 4 ,
202
- ],
203
- 'update one ' => [
204
- [
205
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 2 , 'value ' => 8 ],
206
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 5 , 'value ' => 5 ],
207
- ['website_id ' => 0 , 'customer_group_id ' => 0 , 'qty ' => 3 , 'value ' => 5 ],
208
- [
209
- 'website_id ' => 0 ,
210
- 'customer_group_id ' => 0 ,
211
- 'qty ' => 10 ,
212
- 'extension_attributes ' => new \Magento \Framework \DataObject (['percentage_value ' => 10 ])
213
- ],
214
- ],
215
- 1 ,
216
- 4 ,
217
- ],
218
- 'delete one ' => [
219
- [
220
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 5 , 'value ' => 5 ],
221
- ['website_id ' => 0 , 'customer_group_id ' => 0 , 'qty ' => 3 , 'value ' => 5 ],
222
- [
223
- 'website_id ' => 0 ,
224
- 'customer_group_id ' => 0 ,
225
- 'qty ' => 10 ,
226
- 'extension_attributes ' => new \Magento \Framework \DataObject (['percentage_value ' => 50 ])
227
- ],
228
- ],
229
- 1 ,
230
- 3 ,
231
- ],
232
- 'add one ' => [
233
- [
234
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 2 , 'value ' => 8 ],
235
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 5 , 'value ' => 5 ],
236
- ['website_id ' => 0 , 'customer_group_id ' => 32000 , 'qty ' => 20 , 'percentage_value ' => 90 ],
237
- ['website_id ' => 0 , 'customer_group_id ' => 0 , 'qty ' => 3 , 'value ' => 5 ],
238
- [
239
- 'website_id ' => 0 ,
240
- 'customer_group_id ' => 0 ,
241
- 'qty ' => 10 ,
242
- 'extension_attributes ' => new \Magento \Framework \DataObject (['percentage_value ' => 50 ])
243
- ],
244
- ],
245
- 1 ,
246
- 5 ,
247
- ],
248
- 'delete all ' => [[], 1 , 0 ,],
123
+ $ data = [
124
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 2 , 'price ' => 8 ],
125
+ ['website_id ' => 0 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 ],
126
+ ['website_id ' => 1 , 'cust_group ' => 1 , 'price_qty ' => 5 , 'price ' => 5 ],
249
127
];
128
+
129
+ $ newData = $ this ->_model ->preparePriceData ($ data , \Magento \Catalog \Model \Product \Type::TYPE_SIMPLE , 1 );
130
+ $ this ->assertEquals (2 , count ($ newData ));
131
+ $ this ->assertArrayHasKey ('1-2 ' , $ newData );
132
+ $ this ->assertArrayHasKey ('1-5 ' , $ newData );
133
+ }
134
+
135
+ public function testAfterLoad ()
136
+ {
137
+ /** @var $product \Magento\Catalog\Model\Product */
138
+ $ product = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
139
+ \Magento \Catalog \Model \Product::class
140
+ );
141
+ $ fixtureProduct = $ this ->productRepository ->get ('simple ' );
142
+ $ product ->setId ($ fixtureProduct ->getId ());
143
+ $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
144
+ $ product ->setData ($ linkField , $ fixtureProduct ->getData ($ linkField ));
145
+ $ this ->_model ->afterLoad ($ product );
146
+ $ price = $ product ->getTierPrice ();
147
+ $ this ->assertNotEmpty ($ price );
148
+ $ this ->assertEquals (4 , count ($ price ));
250
149
}
251
150
}
0 commit comments