Skip to content

Commit

Permalink
OXAP-292 Mapped the pseudo code in the unit tests and fixxed the wron…
Browse files Browse the repository at this point in the history
…g handling for the street number of amazon

Signed-off-by: Bjoern Lange <bjoern.lange@bestit-online.de>
  • Loading branch information
Bjoern Lange committed Oct 10, 2019
1 parent b68a986 commit fe8b8dd
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 0 deletions.
35 changes: 35 additions & 0 deletions application/models/bestitamazonpay4oxidaddressutil.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ private function _cleanPatternSearchResult(array $matches)
return $requiredValues;
}

/**
* Saves the street + house number in the street field and remove the company field, if number is saved in company.
*
* Amazon had a short period, in which their address form was wrong so the street number must be handled specially.
*
* @param array $possibleStreetLines
*
* @return array Return the changed to original street lines.
*/
private function _fixBrokenHouseNumberDataIfNeeded(array $possibleStreetLines)
{
if ($this->_lineContainsJustAHouseNumber($possibleStreetLines['usual company'])) {
$possibleStreetLines['usual street'] = $possibleStreetLines['usual street'] . ' ' .
$possibleStreetLines['usual company'];

$possibleStreetLines['usual company'] = '';
}

return $possibleStreetLines;
}

/**
* Checks the address lines and returns the matching steet and company information.
*
Expand Down Expand Up @@ -72,6 +93,8 @@ private function _getPossibleStreetLinesInTheConfiguredOrder(stdClass $amazonDat
if (isset($aMap[$amazonData->CountryCode])) {
// Usually line 2 is the street but if line 2 empty, line 1 becomes the street, so move line 2 to the top.
$possibleStreetLines = array_reverse($possibleStreetLines);

$possibleStreetLines = $this->_fixBrokenHouseNumberDataIfNeeded($possibleStreetLines);
}

// Line 3 is the company or additional company infos, everytime! But if the other lines are empty, it can be
Expand Down Expand Up @@ -151,6 +174,18 @@ protected function _isStreetParsingLongerThanNumber(array $followingNumberMatche
return strlen((string) @$followingNumberMatches['Name']) > strlen((string) @$followingNumberMatches['Number']);
}

/**
* Does it seem that the given address line just contains a house number?
*
* @param string $addressLine
*
* @return bool
*/
private function _lineContainsJustAHouseNumber($addressLine)
{
return (bool) preg_match('/^\s*(?P<StreetNr>\d+[\s\w]{0,9})\s*$/', $addressLine);
}

/**
* Returns parsed Street name and Street number in array
*
Expand Down
204 changes: 204 additions & 0 deletions tests/unit/application/models/bestitAmazonPay4OxidAdressUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,210 @@ public function getFullAddressParseAsserts()
),
true,
false
),
// Amazon had a short period, in which their address form was wrong
// so the street number must be handled specially.
'map pseudo code with all filled fields, company on top like in germany, but broken street nr' => array(
array(
'AddressLine1' => 'Street Line 1a additional',
'AddressLine2' => ' 50N',
'AddressLine3' => 'Company Line 3',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Company Line 3',
'Street' => 'Street Line',
'StreetNr' => '1a',
'AddInfo' => 'additional 50N',
),
true
),
'map pseudo code with company and street, company on top like in germany, but broken street nr' => array(
array(
'AddressLine1' => 'Street Line',
'AddressLine2' => ' 50N',
'AddressLine3' => 'Company Line 3',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Company Line 3',
'Street' => 'Street Line',
'StreetNr' => '50N',
'AddInfo' => '',
),
true
),
'map pseudo code with just street, company on top like in germany, but broken street nr' => array(
array(
'AddressLine1' => 'Street Line',
'AddressLine2' => ' 50N',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => '',
'Street' => 'Street Line',
'StreetNr' => '50N',
'AddInfo' => '',
),
true
),
'map pseudo code with all filled fields, company on top like in germany' => array(
array(
'AddressLine1' => 'Company Line 1',
'AddressLine2' => 'Street Line 2a additional',
'AddressLine3' => 'Info Line 3',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Company Line 1, Info Line 3',
'Street' => 'Street Line',
'StreetNr' => '2a',
'AddInfo' => 'additional',
),
true
),
'map pseudo code without line 2, company on top like in germany' => array(
array(
'AddressLine1' => 'Street Line 1a additional',
'AddressLine3' => 'Info Line 3',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Info Line 3',
'Street' => 'Street Line',
'StreetNr' => '1a',
'AddInfo' => 'additional',
),
true
),
'map pseudo code without line 2 and 3, company on top like in germany' => array(
array(
'AddressLine1' => 'Street Line 1a',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => '',
'Street' => 'Street Line',
'StreetNr' => '1a',
'AddInfo' => '',
),
true
),
'map pseudo code with all filled fields, normal order' => array(
array(
'AddressLine1' => 'Street Line 1a additional',
'AddressLine2' => 'Company Line 2',
'AddressLine3' => 'Info Line 3',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Company Line 2, Info Line 3',
'Street' => 'Street Line',
'StreetNr' => '1a',
'AddInfo' => 'additional',
)
),
'map pseudo code with all filled fields but no info line, normal order' => array(
array(
'AddressLine1' => 'Street Line 1a additional',
'AddressLine2' => 'Company Line 2',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Company Line 2',
'Street' => 'Street Line',
'StreetNr' => '1a',
'AddInfo' => 'additional',
)
),
'map pseudo code with line 1 but no company line, normal order' => array(
array(
'AddressLine1' => 'Street Line 1a additional',
'AddressLine2' => '',
'AddressLine3' => 'Info Line 3',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Info Line 3',
'Street' => 'Street Line',
'StreetNr' => '1a',
'AddInfo' => 'additional',
)
),
'map pseudo code with line 1 but nothing else, normal order' => array(
array(
'AddressLine1' => 'Street Line 1a additional',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => '',
'Street' => 'Street Line',
'StreetNr' => '1a',
'AddInfo' => 'additional',
)
),
'map pseudo code with all filled fields but line 1, normal order' => array(
array(
'AddressLine2' => 'Street Line 2b additional',
'AddressLine3' => 'Company Line 3',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => 'Company Line 3',
'Street' => 'Street Line',
'StreetNr' => '2b',
'AddInfo' => 'additional',
)
),
'map pseudo code with just line 2, normal order' => array(
array(
'AddressLine2' => 'Street Line 2b',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => '',
'Street' => 'Street Line',
'StreetNr' => '2b',
'AddInfo' => '',
)
),
'map pseudo code with just line 3, normal order' => array(
array(
'AddressLine2' => 'StreetLine 3c',
'Name' => 'FName MName LName'
),
array(
'LastName' => 'LName',
'FirstName' => 'FName MName',
'CompanyName' => '',
'Street' => 'StreetLine',
'StreetNr' => '3c',
'AddInfo' => '',
)
)
);
}
Expand Down

0 comments on commit fe8b8dd

Please sign in to comment.