|
33 | 33 | use Magento\Store\Model\Store;
|
34 | 34 | use PHPUnit\Framework\MockObject\MockObject;
|
35 | 35 | use PHPUnit\Framework\TestCase;
|
| 36 | +use Zend_Db_Select_Exception; |
36 | 37 |
|
37 | 38 | /**
|
38 | 39 | * Test sales rule model validator
|
@@ -538,7 +539,7 @@ public function testProcessShippingAmountProcessDisabled()
|
538 | 539 | * @param int $ruleDiscount
|
539 | 540 | * @param int $shippingDiscount
|
540 | 541 | * @dataProvider dataProviderActions
|
541 |
| - * @throws \Zend_Db_Select_Exception |
| 542 | + * @throws Zend_Db_Select_Exception |
542 | 543 | */
|
543 | 544 | public function testProcessShippingAmountActions($action, $ruleDiscount, $shippingDiscount): void
|
544 | 545 | {
|
@@ -595,6 +596,86 @@ public static function dataProviderActions()
|
595 | 596 | ];
|
596 | 597 | }
|
597 | 598 |
|
| 599 | + /** |
| 600 | + * Tests shipping amount with full discount action. |
| 601 | + * |
| 602 | + * @dataProvider dataProviderForFullShippingDiscount |
| 603 | + * @param string $action |
| 604 | + * @param float $ruleDiscount |
| 605 | + * @param float $shippingDiscount |
| 606 | + * @param float $shippingAmount |
| 607 | + * @param float $quoteBaseSubTotal |
| 608 | + * @throws Zend_Db_Select_Exception |
| 609 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 610 | + */ |
| 611 | + public function testProcessShippingAmountWithFullFixedPercentDiscount( |
| 612 | + string $action, |
| 613 | + float $ruleDiscount, |
| 614 | + float $shippingDiscount, |
| 615 | + float $shippingAmount, |
| 616 | + float $quoteBaseSubTotal |
| 617 | + ): void { |
| 618 | + $ruleMock = $this->getMockBuilder(Rule::class) |
| 619 | + ->disableOriginalConstructor() |
| 620 | + ->setMethods(['getApplyToShipping', 'getSimpleAction', 'getDiscountAmount']) |
| 621 | + ->getMock(); |
| 622 | + $ruleMock->method('getApplyToShipping') |
| 623 | + ->willReturn(true); |
| 624 | + $ruleMock->method('getDiscountAmount') |
| 625 | + ->willReturn($ruleDiscount); |
| 626 | + $ruleMock->method('getSimpleAction') |
| 627 | + ->willReturn($action); |
| 628 | + |
| 629 | + $iterator = new \ArrayIterator([$ruleMock]); |
| 630 | + $this->ruleCollection->method('getIterator') |
| 631 | + ->willReturn($iterator); |
| 632 | + |
| 633 | + $this->utility->method('canProcessRule') |
| 634 | + ->willReturn(true); |
| 635 | + |
| 636 | + $this->priceCurrency->method('convert') |
| 637 | + ->willReturn($ruleDiscount); |
| 638 | + |
| 639 | + $this->priceCurrency->method('roundPrice') |
| 640 | + ->willReturn(round($shippingDiscount, 2)); |
| 641 | + |
| 642 | + $this->model->init( |
| 643 | + $this->model->getWebsiteId(), |
| 644 | + $this->model->getCustomerGroupId(), |
| 645 | + $this->model->getCouponCode() |
| 646 | + ); |
| 647 | + |
| 648 | + $addressMock = $this->setupAddressMock($shippingAmount, $quoteBaseSubTotal); |
| 649 | + |
| 650 | + self::assertInstanceOf(Validator::class, $this->model->processShippingAmount($addressMock)); |
| 651 | + self::assertEquals($shippingDiscount, $addressMock->getShippingDiscountAmount()); |
| 652 | + } |
| 653 | + |
| 654 | + /** |
| 655 | + * Get data provider array for full shipping discount action |
| 656 | + * |
| 657 | + * @return array |
| 658 | + */ |
| 659 | + public function dataProviderForFullShippingDiscount(): array |
| 660 | + { |
| 661 | + return [ |
| 662 | + 'verify shipping discount when shipping amount is greater than zero' => [ |
| 663 | + Rule::BY_PERCENT_ACTION, |
| 664 | + 100.00, |
| 665 | + 5.0, |
| 666 | + 5.0, |
| 667 | + 10.0 |
| 668 | + ], |
| 669 | + 'verify shipping discount when shipping amount is zero' => [ |
| 670 | + Rule::BY_PERCENT_ACTION, |
| 671 | + 100.00, |
| 672 | + 5.0, |
| 673 | + 0, |
| 674 | + 10.0 |
| 675 | + ] |
| 676 | + ]; |
| 677 | + } |
| 678 | + |
598 | 679 | /**
|
599 | 680 | * @param float $shippingAmount
|
600 | 681 | * @param float $quoteBaseSubTotal
|
|
0 commit comments