protected function setUp() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->scopeConfig = $this->getMock('Magento\\Framework\\App\\Config', [], [], '', false); $this->address = $objectManager->getObject('Magento\\Sales\\Model\\Quote\\Address', ['scopeConfig' => $this->scopeConfig]); $this->quote = $this->getMock('Magento\\Sales\\Model\\Quote', [], [], '', false); $this->address->setQuote($this->quote); }
public function testPopulateBeforeSaveData() { /** Preconditions */ $customerId = 1; $customerAddressId = 1; $this->_address->setQuote($this->_quote); $this->assertNotEquals($customerId, $this->_address->getCustomerId(), "Precondition failed: Customer ID was not set."); $this->assertNotEquals(1, $this->_address->getQuoteId(), "Precondition failed: Quote ID was not set."); $this->assertNotEquals($customerAddressId, $this->_address->getCustomerAddressId(), "Precondition failed: Customer address ID was not set."); /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $addressBuilder */ $addressBuilder = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder'); $customerAddressData = $addressBuilder->setId($customerAddressId)->create(); $this->_address->setCustomerAddressData($customerAddressData); $this->_address->save(); $this->assertEquals($customerId, $this->_address->getCustomerId()); $this->assertEquals($this->_quote->getId(), $this->_address->getQuoteId()); $this->assertEquals($customerAddressId, $this->_address->getCustomerAddressId()); }
/** * @param Address $address * @return $this */ public function addAddress(Address $address) { $address->setQuote($this); if (!$address->getId()) { $this->getAddressesCollection()->addItem($address); } return $this; }