public function testGetWeeeAttributesForBundle() { $prodId1 = 1; $prodId2 = 2; $fptCode1 = 'fpt' . $prodId1; $fptCode2 = 'fpt' . $prodId2; $weeeObject1 = new \Magento\Framework\DataObject(['code' => $fptCode1, 'amount' => '15.0000']); $weeeObject2 = new \Magento\Framework\DataObject(['code' => $fptCode2, 'amount' => '15.0000']); $testArray = [$prodId1 => [$fptCode1 => $weeeObject1], $prodId2 => [$fptCode2 => $weeeObject2]]; $this->weeeTax->expects($this->any())->method('getProductWeeeAttributes')->will($this->returnValue([$weeeObject1, $weeeObject2])); $productSimple = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\Simple', ['getId'], [], '', false); $productSimple->expects($this->at(0))->method('getId')->will($this->returnValue($prodId1)); $productSimple->expects($this->at(1))->method('getId')->will($this->returnValue($prodId2)); $productInstance = $this->getMock('\\Magento\\Bundle\\Model\\Product\\Type', [], [], '', false); $productInstance->expects($this->any())->method('getSelectionsCollection')->will($this->returnValue([$productSimple])); $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false); /** @var \Magento\Catalog\Model\Product $product */ $product = $this->getMock('\\Magento\\Bundle\\Model\\Product', ['getTypeInstance', 'getStoreId', 'getStore', 'getTypeId'], [], '', false); $product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($productInstance)); $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); $product->expects($this->any())->method('getStore')->will($this->returnValue($store)); $product->expects($this->any())->method('getTypeId')->will($this->returnValue('bundle')); $registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product)); $this->assertEquals($testArray, $this->helperData->getWeeeAttributesForBundle($product)); }
public function testGetWeeAttributesForBundle() { $weeObject = new \Magento\Framework\Object(['code' => 'fpt', 'amount' => '15.0000']); $testArray = ['fpt' => $weeObject]; $this->weeeTax->expects($this->any())->method('getProductWeeeAttributes')->will($this->returnValue([$weeObject])); $productSimple = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Type\\Simple', [], [], '', false); $productInstance = $this->getMock('\\Magento\\Bundle\\Model\\Product\\Type', [], [], '', false); $productInstance->expects($this->any())->method('getSelectionsCollection')->will($this->returnValue([$productSimple])); $store = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false); $product = $this->getMock('\\Magento\\Bundle\\Model\\Product', ['getTypeInstance', 'getStoreId', 'getStore', 'getTypeId'], [], '', false); $product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($productInstance)); $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); $product->expects($this->any())->method('getStore')->will($this->returnValue($store)); $product->expects($this->any())->method('getTypeId')->will($this->returnValue('bundle')); $registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $registry->expects($this->any())->method('registry')->with('current_product')->will($this->returnValue($product)); $this->assertEquals($testArray, $this->_helperData->getWeeAttributesForBundle($product)); }
public function testAroundDispatchBasedOnShipping() { $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->aroundDispatch($action, $proceed, $request); }