/** * Test getting just tax records for a given address. Only tax records with * a matching quote address id should be returned. */ public function testGetTaxRecordsForAddress() { $this->_taxSession->expects($this->any())->method('getTaxRecords')->will($this->returnValue($this->_taxRecords)); $recordsForAddress = $this->_taxCollector->getTaxRecordsByAddressId($this->_addressId); $this->assertCount(2, $recordsForAddress); // Strict in_array checks necessary to prevent attempting to match recursively // through the mocked objects, allowing these checks to work - loose checks // cause fatal errors due to excessive nesting, possibly recursive structures in mocks. $this->assertTrue(in_array($this->_shipTaxRecord, $recordsForAddress, true)); $this->assertTrue(in_array($this->_merchTaxRecord, $recordsForAddress, true)); $this->assertFalse(in_array($this->_altMerchTaxRecord, $recordsForAddress, true)); }
/** * Update the address totals with tax amounts. * * @param Mage_Sales_Model_Quote_Address * @return self */ public function collect(Mage_Sales_Model_Quote_Address $address) { // Necessary for inherited `self::_setAmount` and `self::_setBaseAmount` to behave. $this->_setAddress($address); $addressId = $address->getId(); $taxTotal = $this->_totalTaxRecordsCalculatedTaxes($this->_taxCollector->getTaxRecordsByAddressId($addressId)); $dutyTotal = $this->_totalDuties($this->_taxCollector->getTaxDutiesByAddressId($addressId)); $feeTotal = $this->_totalFees($this->_taxCollector->getTaxFeesByAddressId($addressId)); $total = $taxTotal + $dutyTotal + $feeTotal; $this->_logger->debug("Collected tax totals of: tax - {$taxTotal}, duty - {$dutyTotal}, fee - {$feeTotal}, total - {$total}.", $this->_logContext->getMetaData(__CLASS__)); // Always overwrite amounts for this total. The total calculated from // the collector's tax records will be the complete tax amount for // the address. $this->_setAmount($total)->_setBaseAmount($total); return $this; }