/** * @covers Auspost\Postage\DeliveryChoiceClient::factory * @dataProvider provider */ public function testFactoryInitalisesClientInDeveloperMode($userEmail, $userPwd, $developerMode = true, $reqUrl = 'https://api.auspost.com.au', $reqEmail = '*****@*****.**', $reqPwd = 'password') { $client = DeliveryChoiceClient::factory(array('developer_mode' => $developerMode, 'email_address' => $userEmail, 'password' => $userPwd)); $this->assertEquals($developerMode, $client->getConfig('developer_mode')); $this->assertEquals($reqUrl, $client->getBaseUrl()); $this->assertEquals($reqEmail, $client->getConfig('email_address')); $this->assertEquals($reqPwd, $client->getConfig('password')); }
/** * @dataProvider validateAddressProvider */ public function testValidateAddress($mock, $args, $valid, $description = null) { $this->setMockResponse($this->client, $mock); $response = $this->client->validateAddress($args); $result = $response['ValidateAustralianAddressResponse']; $this->assertEquals($valid, $result['ValidAustralianAddress']); if (!$valid) { $this->assertEquals($description, $result['BusinessException']['Description']); } }
/** * Converts the customer provided address data into an Australia * Post-supported format. * * @param array $street Address lines * @param string $state Address state * @param string $suburb Address city / suburb * @param string $postcode Address postcode * @param string $country Address country * * @return array */ public function validateAddress(array $street, $state, $suburb, $postcode, $country) { $address = array('address_line_1' => $street[0], 'state' => $state, 'suburb' => $suburb, 'postcode' => $postcode, 'country' => $country); if (count($street) > 1) { $address['address_line_2'] = $street[1]; } $result = array(); try { $result = $this->client->validateAddress($address); $result = $result['ValidateAustralianAddressResponse']; if (is_array($result['Address']['AddressLine'])) { $result['Address']['AddressLine'] = $result['Address']['AddressLine'][0]; } unset($result['Address']['DeliveryPointIdentifier']); } catch (Exception $e) { $result['ValidAustralianAddress'] = false; Mage::logException($e); } return $result; }