123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Weee\Test\Unit\App\Action;
- /**
- * Class ContextPluginTest
- *
- * @package Magento\Weee\Test\Unit\App\Action
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class ContextPluginTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Tax\Helper\Data
- */
- protected $taxHelperMock;
- /**
- * @var \Magento\Weee\Helper\Data
- */
- protected $weeeHelperMock;
- /**
- * @var \Magento\Weee\Model\Tax
- */
- protected $weeeTaxMock;
- /**
- * @var \Magento\Framework\App\Http\Context
- */
- protected $httpContextMock;
- /**
- * @var \Magento\Tax\Model\Calculation\Proxy
- */
- protected $taxCalculationMock;
- /**
- * @var \Magento\Framework\Module\Manager
- */
- protected $moduleManagerMock;
- /**
- * @var \Magento\PageCache\Model\Config
- */
- protected $cacheConfigMock;
- /**
- * @var \Magento\Store\Model\StoreManager
- */
- protected $storeManageMock;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfig
- */
- protected $scopeConfigMock;
- /**
- * @var \Magento\Tax\Model\App\Action\ContextPlugin
- */
- protected $contextPlugin;
- protected function setUp()
- {
- $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->taxHelperMock = $this->getMockBuilder(\Magento\Tax\Helper\Data::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->weeeHelperMock = $this->getMockBuilder(\Magento\Weee\Helper\Data::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->weeeTaxMock = $this->getMockBuilder(\Magento\Weee\Model\Tax::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->httpContextMock = $this->getMockBuilder(\Magento\Framework\App\Http\Context::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->customerSessionMock = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
- ->disableOriginalConstructor()
- ->setMethods([
- 'getDefaultTaxBillingAddress', 'getDefaultTaxShippingAddress', 'getCustomerTaxClassId',
- 'getWebsiteId', 'isLoggedIn'
- ])
- ->getMock();
- $this->moduleManagerMock = $this->getMockBuilder(\Magento\Framework\Module\Manager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->cacheConfigMock = $this->getMockBuilder(\Magento\PageCache\Model\Config::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->contextPlugin = $this->objectManager->getObject(
- \Magento\Weee\Model\App\Action\ContextPlugin::class,
- [
- 'customerSession' => $this->customerSessionMock,
- 'httpContext' => $this->httpContextMock,
- 'weeeTax' => $this->weeeTaxMock,
- 'taxHelper' => $this->taxHelperMock,
- 'weeeHelper' => $this->weeeHelperMock,
- 'moduleManager' => $this->moduleManagerMock,
- 'cacheConfig' => $this->cacheConfigMock,
- 'storeManager' => $this->storeManagerMock,
- 'scopeConfig' => $this->scopeConfigMock
- ]
- );
- }
- public function testBeforeDispatchBasedOnDefault()
- {
- $this->customerSessionMock->expects($this->once())
- ->method('isLoggedIn')
- ->willReturn(true);
- $this->moduleManagerMock->expects($this->once())
- ->method('isEnabled')
- ->with('Magento_PageCache')
- ->willReturn(true);
- $this->cacheConfigMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->weeeHelperMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->taxHelperMock->expects($this->once())
- ->method('getTaxBasedOn')
- ->willReturn('billing');
- $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
- ->disableOriginalConstructor()
- ->getMock();
- $storeMock->expects($this->once())
- ->method('getWebsiteId')
- ->willReturn(1);
- $this->storeManagerMock->expects($this->once())
- ->method('getStore')
- ->willReturn($storeMock);
- $this->scopeConfigMock->expects($this->at(0))
- ->method('getValue')
- ->with(
- \Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- null
- )
- ->willReturn('US');
- $this->scopeConfigMock->expects($this->at(1))
- ->method('getValue')
- ->with(
- \Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- null
- )
- ->willReturn(0);
- $this->weeeTaxMock->expects($this->once())
- ->method('isWeeeInLocation')
- ->with('US', 0, 1)
- ->willReturn(true);
- $this->httpContextMock->expects($this->once())
- ->method('setValue')
- ->with('weee_tax_region', ['countryId' => 'US', 'regionId' => 0], 0);
- $action = $this->objectManager->getObject(\Magento\Framework\App\Test\Unit\Action\Stub\ActionStub::class);
- $request = $this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getActionName']);
- $this->contextPlugin->beforeDispatch($action, $request);
- }
- public function testBeforeDispatchBasedOnOrigin()
- {
- $this->customerSessionMock->expects($this->once())
- ->method('isLoggedIn')
- ->willReturn(true);
- $this->moduleManagerMock->expects($this->once())
- ->method('isEnabled')
- ->with('Magento_PageCache')
- ->willReturn(true);
- $this->cacheConfigMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->weeeHelperMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->taxHelperMock->expects($this->once())
- ->method('getTaxBasedOn')
- ->willReturn('origin');
- $action = $this->objectManager->getObject(\Magento\Framework\App\Test\Unit\Action\Stub\ActionStub::class);
- $request = $this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getActionName']);
- $this->contextPlugin->beforeDispatch($action, $request);
- }
- public function testBeforeDispatchBasedOnBilling()
- {
- $this->customerSessionMock->expects($this->once())
- ->method('isLoggedIn')
- ->willReturn(true);
- $this->moduleManagerMock->expects($this->once())
- ->method('isEnabled')
- ->with('Magento_PageCache')
- ->willReturn(true);
- $this->cacheConfigMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->weeeHelperMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->taxHelperMock->expects($this->once())
- ->method('getTaxBasedOn')
- ->willReturn('billing');
- $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
- ->disableOriginalConstructor()
- ->getMock();
- $storeMock->expects($this->once())
- ->method('getWebsiteId')
- ->willReturn(1);
- $this->storeManagerMock->expects($this->once())
- ->method('getStore')
- ->willReturn($storeMock);
- $this->scopeConfigMock->expects($this->at(0))
- ->method('getValue')
- ->with(
- \Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- null
- )
- ->willReturn('US');
- $this->scopeConfigMock->expects($this->at(1))
- ->method('getValue')
- ->with(
- \Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- null
- )
- ->willReturn(0);
- $this->customerSessionMock->expects($this->once())
- ->method('getDefaultTaxBillingAddress')
- ->willReturn(['country_id' => 'US', 'region_id' => 1]);
- $this->weeeTaxMock->expects($this->once())
- ->method('isWeeeInLocation')
- ->with('US', 1, 1)
- ->willReturn(true);
- $this->httpContextMock->expects($this->once())
- ->method('setValue')
- ->with('weee_tax_region', ['countryId' => 'US', 'regionId' => 1], 0);
- $action = $this->objectManager->getObject(\Magento\Framework\App\Test\Unit\Action\Stub\ActionStub::class);
- $request = $this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getActionName']);
- $this->contextPlugin->beforeDispatch($action, $request);
- }
- public function testBeforeDispatchBasedOnShipping()
- {
- $this->customerSessionMock->expects($this->once())
- ->method('isLoggedIn')
- ->willReturn(true);
- $this->moduleManagerMock->expects($this->once())
- ->method('isEnabled')
- ->with('Magento_PageCache')
- ->willReturn(true);
- $this->cacheConfigMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->weeeHelperMock->expects($this->once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->taxHelperMock->expects($this->once())
- ->method('getTaxBasedOn')
- ->willReturn('shipping');
- $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
- ->disableOriginalConstructor()
- ->getMock();
- $storeMock->expects($this->once())
- ->method('getWebsiteId')
- ->willReturn(1);
- $this->storeManagerMock->expects($this->once())
- ->method('getStore')
- ->willReturn($storeMock);
- $this->scopeConfigMock->expects($this->at(0))
- ->method('getValue')
- ->with(
- \Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- null
- )
- ->willReturn('US');
- $this->scopeConfigMock->expects($this->at(1))
- ->method('getValue')
- ->with(
- \Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- null
- )
- ->willReturn(0);
- $this->customerSessionMock->expects($this->once())
- ->method('getDefaultTaxShippingAddress')
- ->willReturn(['country_id' => 'US', 'region_id' => 1]);
- $this->weeeTaxMock->expects($this->once())
- ->method('isWeeeInLocation')
- ->with('US', 1, 1)
- ->willReturn(true);
- $this->httpContextMock->expects($this->once())
- ->method('setValue')
- ->with('weee_tax_region', ['countryId' => 'US', 'regionId' => 1], 0);
- $action = $this->objectManager->getObject(\Magento\Framework\App\Test\Unit\Action\Stub\ActionStub::class);
- $request = $this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getActionName']);
- $this->contextPlugin->beforeDispatch($action, $request);
- }
- }
|