CalculationTest.php 2.74 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Tax\Model;

use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;

/**
 * Class CalculationTest
 *
 * @magentoDataFixture Magento/Customer/_files/customer.php
 * @magentoDataFixture Magento/Customer/_files/customer_address.php
 */
class CalculationTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \Magento\TestFramework\ObjectManager
     */
    protected $_objectManager;

    /**
     * @var CustomerRepositoryInterface
     */
    protected $customerRepository;

    /**
     * @var AddressRepositoryInterface
     */
    protected $addressRepository;

    /**
     * @var GroupRepositoryInterface
     */
    protected $groupRepository;

    const FIXTURE_CUSTOMER_ID = 1;

    const FIXTURE_ADDRESS_ID = 1;

    /**
     * @var \Magento\Tax\Model\Calculation
     */
    protected $_model;

    protected function setUp()
    {
        /** @var $objectManager \Magento\TestFramework\ObjectManager */
        $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
        $this->_model = $this->_objectManager->create(\Magento\Tax\Model\Calculation::class);
        $this->customerRepository = $this->_objectManager->create(
            \Magento\Customer\Api\CustomerRepositoryInterface::class
        );
        $this->addressRepository = $this->_objectManager->create(
            \Magento\Customer\Api\AddressRepositoryInterface::class
        );
        $this->groupRepository = $this->_objectManager->create(\Magento\Customer\Api\GroupRepositoryInterface::class);
    }

    public function testDefaultCustomerTaxClass()
    {
        $defaultCustomerTaxClass = 3;
        $this->assertEquals($defaultCustomerTaxClass, $this->_model->getDefaultCustomerTaxClass(null));
    }

    public function testGetDefaultRateRequest()
    {
        $customerDataSet = $this->customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
        $address = $this->addressRepository->getById(self::FIXTURE_ADDRESS_ID);

        $rateRequest = $this->_model->getRateRequest(null, null, null, null, $customerDataSet->getId());

        $this->assertNotNull($rateRequest);
        $this->assertEquals($address->getCountryId(), $rateRequest->getCountryId());
        $this->assertEquals($address->getRegion()->getRegionId(), $rateRequest->getRegionId());
        $this->assertEquals($address->getPostcode(), $rateRequest->getPostcode());

        $customerTaxClassId = $this->groupRepository->getById($customerDataSet->getGroupId())->getTaxClassId();
        $this->assertEquals($customerTaxClassId, $rateRequest->getCustomerClassId());
    }
}