public function testValidateAddressesOneInvalidNoKeys() { $invalidAddress = $this->_addressBuilder->setFirstname('Freddy')->setLastname('Mercury')->create(); try { $this->_service->validateAddresses(array_merge($this->_expectedAddresses, array($invalidAddress))); $this->fail("InputException was expected but not thrown"); } catch (InputException $actualException) { $expectedException = new InputException(); $expectedException->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'street', 'index' => 2]); $expectedException->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'city', 'index' => 2]); $expectedException->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'telephone', 'index' => 2]); $expectedException->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'postcode', 'index' => 2]); $expectedException->addError(InputException::REQUIRED_FIELD, ['fieldName' => 'countryId', 'index' => 2]); $this->assertEquals($expectedException, $actualException); } }
public function testValidateAddressesValid() { // Setup address mock $mockAddress = $this->_createAddress(1, 'John'); $address = $this->_addressBuilder->setFirstname('John')->setLastname(self::LASTNAME)->setRegion($this->objectManagerHelper->getObject('\\Magento\\Customer\\Service\\V1\\Data\\RegionBuilder')->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create())->setStreet(array(self::STREET))->setTelephone(self::TELEPHONE)->setCity(self::CITY)->setCountryId(self::COUNTRY_ID)->setPostcode(self::POSTCODE)->create(); $this->_addressConverterMock->expects($this->once())->method('createAddressModel')->with($address)->will($this->returnValue($mockAddress)); $customerService = $this->_createService(); $this->assertTrue($customerService->validateAddresses(array($address))); }
/** * @param AddressBuilder $addressBuilder */ private function _fillMinimumRequiredFields(AddressBuilder $addressBuilder) { $addressBuilder->setFirstname($this->_expectedValues['firstname']); $addressBuilder->setLastname($this->_expectedValues['lastname']); $addressBuilder->setStreet($this->_expectedValues['street']); $addressBuilder->setCity($this->_expectedValues['city']); $addressBuilder->setCountryId($this->_expectedValues['country_id']); $addressBuilder->setRegion($this->objectManagerHelper->getObject('\\Magento\\Customer\\Service\\V1\\Data\\RegionBuilder')->setRegionId($this->_expectedValues['region']['region_id'])->setRegion($this->_expectedValues['region']['region'])->create()); $addressBuilder->setPostcode($this->_expectedValues['postcode']); $addressBuilder->setTelephone($this->_expectedValues['telephone']); }