|
5 | 5 | */
|
6 | 6 | namespace Magento\Paypal\Test\Unit\Model\Hostedpro;
|
7 | 7 |
|
| 8 | +use Magento\Sales\Model\Order; |
| 9 | +use Magento\Sales\Model\Order\Payment; |
| 10 | + |
8 | 11 | class RequestTest extends \PHPUnit_Framework_TestCase
|
9 | 12 | {
|
10 | 13 | /**
|
@@ -181,48 +184,65 @@ public function testSetOrder()
|
181 | 184 | }
|
182 | 185 |
|
183 | 186 | /**
|
184 |
| - * @covers \Magento\Paypal\Model\Hostedpro\Request::setAmount |
| 187 | + * @covers \Magento\Paypal\Model\Hostedpro\Request::setAmount() |
| 188 | + * @param $subtotal |
| 189 | + * @param $total |
| 190 | + * @param $tax |
| 191 | + * @param $shipping |
| 192 | + * @param $discount |
| 193 | + * @dataProvider amountWithoutTaxDataProvider |
185 | 194 | */
|
186 |
| - public function testSetAmountWithoutTax() |
| 195 | + public function testSetAmountWithoutTax($total, $subtotal, $tax, $shipping, $discount) |
187 | 196 | {
|
188 | 197 | $expectation = [
|
189 |
| - 'subtotal' => 12.04, |
190 |
| - 'tax' => 2.03, |
191 |
| - 'shipping' => 5.05 |
| 198 | + 'subtotal' => $subtotal, |
| 199 | + 'total' => $total, |
| 200 | + 'tax' => $tax, |
| 201 | + 'shipping' => $shipping, |
| 202 | + 'discount' => abs($discount) |
192 | 203 | ];
|
193 |
| - $amount = array_sum($expectation); |
194 | 204 |
|
195 | 205 | static::assertFalse($this->taxData->priceIncludesTax());
|
196 | 206 |
|
197 |
| - $payment = $this->getMockBuilder('Magento\Sales\Model\Order\Payment') |
| 207 | + $payment = $this->getMockBuilder(Payment::class) |
198 | 208 | ->disableOriginalConstructor()
|
199 | 209 | ->getMock();
|
200 | 210 |
|
201 |
| - $order = $this->getMockBuilder('Magento\Sales\Model\Order') |
| 211 | + $order = $this->getMockBuilder(Order::class) |
202 | 212 | ->disableOriginalConstructor()
|
203 | 213 | ->getMock();
|
204 | 214 |
|
205 | 215 | $payment->expects(static::once())
|
206 | 216 | ->method('getBaseAmountAuthorized')
|
207 |
| - ->willReturn($amount); |
| 217 | + ->willReturn($total); |
208 | 218 |
|
209 | 219 | $order->expects(static::once())
|
210 | 220 | ->method('getPayment')
|
211 | 221 | ->willReturn($payment);
|
212 | 222 |
|
213 |
| - $order->expects(static::atLeastOnce()) |
| 223 | + $order->expects(static::once()) |
| 224 | + ->method('getBaseDiscountAmount') |
| 225 | + ->willReturn($discount); |
| 226 | + |
| 227 | + $order->expects(static::once()) |
214 | 228 | ->method('getBaseTaxAmount')
|
215 |
| - ->willReturn($expectation['tax']); |
| 229 | + ->willReturn($tax); |
216 | 230 |
|
217 |
| - $order->expects(static::atLeastOnce()) |
| 231 | + $order->expects(static::once()) |
218 | 232 | ->method('getBaseShippingAmount')
|
219 |
| - ->willReturn($expectation['shipping']); |
| 233 | + ->willReturn($shipping); |
220 | 234 |
|
| 235 | + $order->expects(static::once()) |
| 236 | + ->method('getBaseSubtotal') |
| 237 | + ->willReturn($subtotal); |
221 | 238 | $this->_model->setAmount($order);
|
222 | 239 |
|
223 | 240 | static::assertEquals($expectation, $this->_model->getData());
|
224 | 241 | }
|
225 | 242 |
|
| 243 | + /** |
| 244 | + * @covers \Magento\Paypal\Model\Hostedpro\Request::setAmount() |
| 245 | + */ |
226 | 246 | public function testSetAmountWithIncludedTax()
|
227 | 247 | {
|
228 | 248 | /** @var \Magento\Tax\Model\Config $config */
|
@@ -273,4 +293,16 @@ public function testSetAmountWithIncludedTax()
|
273 | 293 |
|
274 | 294 | static::assertEquals($expectation, $this->_model->getData());
|
275 | 295 | }
|
| 296 | + |
| 297 | + /** |
| 298 | + * Get data for amount with tax tests |
| 299 | + * @return array |
| 300 | + */ |
| 301 | + public function amountWithoutTaxDataProvider() |
| 302 | + { |
| 303 | + return [ |
| 304 | + ['total' => 31.00, 'subtotal' => 10.00, 'tax' => 1.00, 'shipping' => 20.00, 'discount' => 0.00], |
| 305 | + ['total' => 5.00, 'subtotal' => 10.00, 'tax' => 0.00, 'shipping' => 20.00, 'discount' => -25.00], |
| 306 | + ]; |
| 307 | + } |
276 | 308 | }
|
0 commit comments