/** * @param bool $cache * @param bool $taxEnabled * @param bool $loggedIn * @dataProvider dataProviderAroundExecute */ public function testAroundExecute($cache, $taxEnabled, $loggedIn) { $this->customerSessionMock->expects($this->any()) ->method('isLoggedIn') ->willReturn($loggedIn); $this->moduleManagerMock->expects($this->any()) ->method('isEnabled') ->with('Magento_PageCache') ->willReturn($cache); $this->cacheConfigMock->expects($this->any()) ->method('isEnabled') ->willReturn($cache); if ($cache && $loggedIn) { $this->taxHelperMock->expects($this->any()) ->method('isCatalogPriceDisplayAffectedByTax') ->willReturn($taxEnabled); if ($taxEnabled) { $this->customerSessionMock->expects($this->once()) ->method('getDefaultTaxBillingAddress') ->willReturn(['country_id' => 1, 'region_id' => 1, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once()) ->method('getDefaultTaxShippingAddress') ->willReturn(['country_id' => 1, 'region_id' => 1, 'postcode' => 11111]); $this->customerSessionMock->expects($this->once()) ->method('getCustomerTaxClassId') ->willReturn(1); $this->taxCalculationMock->expects($this->once()) ->method('getTaxRates') ->with( ['country_id' => 1, 'region_id' => 1, 'postcode' => 11111], ['country_id' => 1, 'region_id' => 1, 'postcode' => 11111], 1 ) ->willReturn([]); $this->httpContextMock->expects($this->any()) ->method('setValue') ->with('tax_rates', [], 0); } $action = $this->objectManager->getObject('Magento\Framework\App\Test\Unit\Action\Stub\ActionStub'); $request = $this->getMock('\Magento\Framework\App\Request\Http', ['getActionName'], [], '', false); $expectedResult = 'expectedResult'; $proceed = function ($request) use ($expectedResult) { return $expectedResult; }; $this->contextPlugin->aroundExecute($action, $proceed, $request); } }
public function testAroundExecuteBasedOnShipping() { $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') ->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'); $request = $this->getMock('\Magento\Framework\App\Request\Http', ['getActionName'], [], '', false); $expectedResult = 'expectedResult'; $proceed = function ($request) use ($expectedResult) { return $expectedResult; }; $this->contextPlugin->aroundExecute($action, $proceed, $request); }