|
30 | 30 | use Magento\Framework\DataObject\Copy;
|
31 | 31 | use Magento\Framework\DataObject\Factory;
|
32 | 32 | use Magento\Framework\Event\Manager;
|
| 33 | +use Magento\Framework\Exception\NoSuchEntityException; |
33 | 34 | use Magento\Framework\Model\Context;
|
| 35 | +use Magento\Framework\Phrase; |
34 | 36 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
35 | 37 | use Magento\Quote\Api\Data\CartInterface;
|
36 | 38 | use Magento\Quote\Model\Quote;
|
@@ -640,6 +642,48 @@ public function testGetCustomerTaxClassId()
|
640 | 642 | $this->assertEquals($taxClassId, $result);
|
641 | 643 | }
|
642 | 644 |
|
| 645 | + /** |
| 646 | + * Test case when non-existent customer group is stored into the quote. |
| 647 | + * In such a case we should get a NoSuchEntityException exception and try |
| 648 | + * to get a valid customer group from the current customer object. |
| 649 | + */ |
| 650 | + public function testGetCustomerTaxClassIdForNonExistentCustomerGroup() |
| 651 | + { |
| 652 | + $customerId = 1; |
| 653 | + $nonExistentGroupId = 100; |
| 654 | + $groupId = 1; |
| 655 | + $taxClassId = 1; |
| 656 | + $groupMock = $this->getMockForAbstractClass(GroupInterface::class, [], '', false); |
| 657 | + $this->groupRepositoryMock->expects($this->at(0)) |
| 658 | + ->method('getById') |
| 659 | + ->with($nonExistentGroupId) |
| 660 | + ->willThrowException(new NoSuchEntityException(new Phrase('Entity Id does not exist'))); |
| 661 | + $customerMock = $this->getMockForAbstractClass( |
| 662 | + CustomerInterface::class, |
| 663 | + [], |
| 664 | + '', |
| 665 | + false |
| 666 | + ); |
| 667 | + $customerMock->expects($this->once()) |
| 668 | + ->method('getGroupId') |
| 669 | + ->willReturn($groupId); |
| 670 | + $this->customerRepositoryMock->expects($this->once()) |
| 671 | + ->method('getById') |
| 672 | + ->with($customerId) |
| 673 | + ->willReturn($customerMock); |
| 674 | + $this->groupRepositoryMock->expects($this->at(1)) |
| 675 | + ->method('getById') |
| 676 | + ->with($groupId) |
| 677 | + ->willReturn($groupMock); |
| 678 | + $groupMock->expects($this->once()) |
| 679 | + ->method('getTaxClassId') |
| 680 | + ->willReturn($taxClassId); |
| 681 | + $this->quote->setData('customer_id', $customerId); |
| 682 | + $this->quote->setData('customer_group_id', $nonExistentGroupId); |
| 683 | + $result = $this->quote->getCustomerTaxClassId(); |
| 684 | + $this->assertEquals($taxClassId, $result); |
| 685 | + } |
| 686 | + |
643 | 687 | public function testGetAllAddresses()
|
644 | 688 | {
|
645 | 689 | $id = 1;
|
|
0 commit comments